A minimal cheat-sheet to get by in vim (vi /gvim)
There’s no doubt that vim/vi or gvim is an incredibly powerful editor. it’s also very lightweight and fast, making it an ideal editor on the Raspberry Pi. It does however have a learning curve. This in a minimal cheat-sheet of commands. The ones in bold are I think the ones you need to learn to be able to use it at a basic level. Also try running vimtutor
from the command line for a tutorial.
Esc key – Normal mode
Inserting text
a -append
i – insert
o – open (inserts line below current line, O open above current line)
r – replace (replaces the character under the cursor with the next one entered,
R – replace mode (overwrite text until Esc pressed)
ce – change (deletes to end of word and then switches to insert mode) c$ deletes the rest of the line
Deleting text
x -delete character
dw – delete word (d2w delete two words)
de – delete from cursor to end of word
d$ – delete from cursor to end of line
dd – delete the line (2dd delete two lines)
Undo
u – undo
U – undo all changes on a line
Put, Past and Cut
p – put the contents of the buffer (paste) (this is the last thing deleted or yanked)
v – visual selections mode (highlights text for eg deletions or write to file with :w FILENAME)
y – yank (copies highlighted text), yw – yanks word
Moving about
gg – go to start of the file
GG – go to end of the file
504G – goto line 504
/ – search, n find next, N find previous
% – find matching bracket (,[,{
0 – move to start of the line, ^ move to first non space character.
$ – move to end of the line
Status
^G – file and position status
! – execute external command e.g. !ls
Writing and Reading
:w – save the file
:w FILENAME – save as FILENAME
:r FILENAME – inserts content of file here, you can also insert output of commands eg :r !ls
:q! -quit discarding changes
: x – quit saving changes (if there are any as opposed to :wq which always saves)