vi/vim
The only text editor that is always available is vi
. An important concept when working with vi/vim
is that it uses different modes. These modes often cause confusion because in command mode you can just enter a command and you cannot change the contents of a text file. To change the contents of a text file, you need to get to input mode.
vi/vim command | Explanation |
---|---|
Esc |
Switches from input mode to command mode. |
i, a |
Switches from command mode to input mode at i or after a the curent cursor position |
o |
Opens a new line below the current cursor position and goes to input mode. |
:wq |
Writes the current file and quits. |
:q! |
Quits the file without applying any changes. |
:w filename |
Writes the current file with a new filename |
dd |
Deletes the current line. |
yy |
Copies the current line. |
P |
Pastes the current selection. |
v |
Enters visual mode, allowing you to select a block of text using the arrow keys. Use d to cut, or y to copy the selection. |
u |
Undoes the last command, repeat as needed. |
Ctrl+r |
Redoes the last undo. |
gg |
Goes to the first line in the document. |
G |
Goes to the last line in the document. |
/string |
Searches for string from the current cursor position forward. |
?string |
Searches for string from the current cursor position backward. |
^ |
Goes to the first position in the current line. |
$ |
Goes to the last position in the current line. |
!ls |
Adds the output of ls (or any other command) in the current file. |
:%s/old/new/g |
Replaces ALL occurrences of old with new. |
:9 |
Goes to line number 9. |