Difference between revisions of "Using a Text Editor"
Line 37: | Line 37: | ||
you can edit the testfile.txt |
you can edit the testfile.txt |
||
vi has 3 modes: |
vi has 3 modes: |
||
− | # moving cursor around. Type e.g. i for insert to go to editing mode. or type : to go to mode 3 |
+ | # moving cursor around. Type e.g. '''i''' for insert to go to editing mode. or type ''':''' to go to mode 3 |
− | # editing. Type your text. Leave with ESC. This puts you back into mode 1. |
+ | # editing. Type your text. Leave with '''ESC'''. This puts you back into mode 1. |
− | # entering commands. Type your commands and then press enter to go back to mode 1. |
+ | # entering commands. Type your commands and then press '''enter''' to go back to mode 1. |
+ | |||
+ | So in order to edit something: |
||
+ | |||
+ | * move with cursor key or press '''j''','''k''','''l''','''h''' instead to move to the place where you want to edit |
||
+ | * press '''i''' for insert and enter your text |
||
+ | * press '''ESC''' to go back to the initial mode. |
||
+ | * press ''':wq''' ENTER (which enters the commands write (save) and q (quit). |
||
+ | * in case you want to leave without saving: ''':q!''' |
Revision as of 10:26, 22 March 2020
Motivation
In order to be able to do everything on the command line you also need to learn a text editor. Most programs have their configuration in text files and you need to learn to use a text editor. If you have not done so you should learn vi. vi (or the improved version: vim) is a good text editor that is installed per default on all unix systems. It is a bit more complicated then other editors because it has 3 modes of input.
Here is a list of text editors and their relative advantages and disadvantages
editor | advantages/disadvantages |
---|---|
vi or vim | available on every system, powerful but harder to learn |
emacs | powerful but also complicated, same keyboard shortcuts as bash |
joe | joes own edito - simple, syntax coloring, wordstar like keyboard shortcuts |
pico, nano, jpico | extremely simple editors for casual editing |
gedit | gnome text editor - disadvantage: only works in GUI |
Quick intro to vim
When you start vim
$ vim testfile.txt
you can edit the testfile.txt vi has 3 modes:
- moving cursor around. Type e.g. i for insert to go to editing mode. or type : to go to mode 3
- editing. Type your text. Leave with ESC. This puts you back into mode 1.
- entering commands. Type your commands and then press enter to go back to mode 1.
So in order to edit something:
- move with cursor key or press j,k,l,h instead to move to the place where you want to edit
- press i for insert and enter your text
- press ESC to go back to the initial mode.
- press :wq ENTER (which enters the commands write (save) and q (quit).
- in case you want to leave without saving: :q!