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
- press
dd
Delete x consecutive lines
- Move to the first line.
- press
dxdwhere x = the number of lines you wish to remove
Delete NEXT word
- Move the cursor to just before the word you wish to remove
- Press
dw
Copy-paste a line
- Place the cursor to the line you want to cut.
- Press
Vto select the entire line, orvto select from where your cursor is. - Place the cursor to the end of what you want to cut, using
h,j,k, or l. - Press
yto copy it, ordto cut it. - Move the cursor to the line where you would like to paste stuff.
- Press
Pto paste it before your cursor, orpto paste it after the cursor.
Insert Comments (or other symbols)
- Press
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.
:%s/foo/bar/g
Find each occurrence of ‘foo’ (in all lines), and replace it with ‘bar’.
:s/foo/bar/g
Find each occurrence of ‘foo’ (in the current line only), and replace it with ‘bar’.
:%s/foo/bar/gc
Change each ‘foo’ to ‘bar’, but ask for confirmation first.
:%s/\<foo\>/bar/gc
Change only whole words exactly matching ‘foo’ to ‘bar’; ask for confirmation.
:%s/foo/bar/gci
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.
Tagged: #tools
