Editors¶
Learning objectives
Questions
- Which editors are good to use on the command line?
- Which editors are good for using in a GUI (graphical user interface) environment?
Objectives
- Learn about some command line editors
- Try and use
nano
- Learn about some GUI editors
- Try use
gedit
Some editors are more suited for a GUI environment and some are more suited for a command line environment.
less, more, cat¶
If you just need to see the content of a file, one of the commands less
, more
, or cat
are probably the best, since there is no risk of you making changes to the file if you are just looking in it.
less, more, cat - if you just need to see the content
If you just need to see the content of a file, these commands are probably the best, since there is no risk of you making changes to the file if you are just looking in it.
- more: forward navigation and limited backward navigation in a file named FILE.
- Usage:
more FILE
- Exit with:
q
- Usage:
- less: forward and backward navigation and also has search options.
- Usage
less FILE
- Exit with:
q
- Usage
- cat: a tool for file-related operations (view, concatenate, create, copy, merge, and manipulate file contents). Usage:
cat [option] FILE
where option is various optional options (hint:man cat
for more info).
Reminder
If you are just looking in a file, do not use an editor (nano, vim, emacs, …) as you risk making changes if, for instance, your cat runs across the keyboard! Use something like cat or less instead.
Try out less
and cat
!
- Go to the
exercises
directory (that you got from the tarball at the beginning of the course) and change directory to one of the subdirectories. - Use
less
on one of the files. Usecat
on one of the files.
Question: Why is cat
good for short files, but not for long files?
Command line editors¶
These are all good editors for using on the command line:
Of these, vi/vim
as well as emacs
are probably the most powerful, though the latter is better in a GUI environment. The easiest editor to use if you are not familiar with any of them is nano
.
Nano
HINT: code-along!
- Starting “nano”: Type
nano
FILENAME on the command line and pressEnter
. FILENAME is whatever you want to call your file. - If FILENAME is a file that already exists,
nano
will open the file. If it dows not exist, it will be created. - You now get an editor that looks like this:
- First thing to notice is that many of the commands are listed at the bottom.
- The ^ before the letter-commands means you should press CTRL and then the letter (while keeping CTRL down).
- Your prompt is in the editor window itself, and you can just type (or copy and paste) the content you want in your file.
- When you want to exit (and possibly save), you press CTRL and then x while holding CTRL down (this is written CTRL-x or ^x).
nano
will ask you if you want to save the content of the buffer to the file. After that it will exit.
There is a manual for nano
here.
GUI editors¶
If you are connecting with ThinLinc, you will be presented with a graphical user interface (GUI). (For Tetralith, the server is tetralith.nsc.liu.se
). From within Thinlinc you can either open a terminal window/shell or you can choose editors from the menu.
It differs a bit how Thinlinc looks depending on the centre, and it also differs which desktop environment they are running. For instance, NSC’s Tetralith has the Xfce environment while HPC2N’s Kebnekaise has MATE.
Examples to open terminal:
- HPC2N: “Applications” -> “System Tools” -> “MATE Terminal”
- NSC: “Applications” -> “System” -> “Xfce Terminal”
To choose editors from the menu:
- HPC2N: “Applications -> Accessories”.
- NSC: “Applications” -> Accessories” and “Applications” -> “Development”.
Regardless, this gives several editor options, of which these have a graphical interface:
- HPC2N/NSC: Text Editor (gedit)
- HPC2N: Pluma - the default editor on the MATE desktop environments (that Thinlinc runs)
- HPC2N: Atom - no t just an editor, but an IDE
- HPC2N/NSC: Emacs (GUI)
- HPC2N/NSC (under “Applications” -> “Development”): NEdit “Nirvana Text Editor”
If you are not familiar with any of these, a good recommendation would be to use Text Editor/gedit
.
Text Editor/gedit
- Starting “gedit”: From the menu, choose Applications -> Accessories -> Text Editor.
- You then get a window that looks similar to this:
- You can open files by clicking “Open” in the top menu.
- Clicking the small file icon with a plus (located beside the “Open” button”) will create a new document.
- Save by clicking “Save” in the menu.
- The menu on the top right (the three horizontal lines) gives you several other options, including “Find” and “Find and Replace”.
Keypoints
- If you just want to look in a file, it is better to use
less
,more
, orcat
- Some editors are best for the command line and some are best for a GUI environment
nano
is a good first editor for the command line- other editors for the command line are:
vi
/vim
,emacs
, etc. gedit
(Text editor) is a good first editor for the GUI- other editors for a GUI environment are:
Pluma
,Atom
,emacs (GUI)
,NEdit
, etc.