I have noted my most used commands and operations down her for me to remember. If there is something, you are missing. I can highly recommend devhints.io/vim, they also have a guide to other tools/technologies, outline is very beautifully.
Delete a line
- Move the cursor to the line you want to delete
Delete x consecutive lines
- Move to the first line.
dwhere x = the number of lines you wish to remove
Delete NEXT word
- Move the cursor to just before the word you wish to remove
Copy-paste a line
- Place the cursor to the line you want to cut.
Vto select the entire line, or
vto select from where your cursor is.
- Place the cursor to the end of what you want to cut, using
h,j,k, or l.
yto copy it, or
dto cut it.
- Move the cursor to the line where you would like to paste stuff.
Pto paste it before your cursor, or
pto paste it after the cursor.
Insert Comments (or other symbols)
ifor entering insert mode
Replace a string
You enter command mode and start typing a regular expression, but for all of us that knows regex, but tries to forget ;) here are some examples.
Find each occurrence of ‘foo’ (in all lines), and replace it with ‘bar’.
Find each occurrence of ‘foo’ (in the current line only), and replace it with ‘bar’.
Change each ‘foo’ to ‘bar’, but ask for confirmation first.
Change only whole words exactly matching ‘foo’ to ‘bar’; ask for confirmation.
Change each ‘foo’ (case insensitive due to the i flag) to ‘bar’; ask for confirmation.
:%s/foo\c/bar/gc is the same because \c makes the search case insensitive. :%s/foo/bar/gcI
Change each ‘foo’ (case sensitive due to the I flag) to ‘bar’; ask for confirmation.
:%s/foo\C/bar/gc is the same because \C makes the search case sensitive.