VIM cheats.

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

  1. Move the cursor to the line you want to delete
  2. press dd

Delete x consecutive lines

  1. Move to the first line.
  2. press dxd where x = the number of lines you wish to remove

Delete NEXT word

  1. Move the cursor to just before the word you wish to remove
  2. Press dw

Copy-paste a line

  1. Place the cursor to the line you want to cut.
  2. Press V to select the entire line, or v to select from where your cursor is.
  3. Place the cursor to the end of what you want to cut, using h,j,k, or l.
  4. Press y to copy it, or d to cut it.
  5. Move the cursor to the line where you would like to paste stuff.
  6. Press P to paste it before your cursor, or p to paste it after the cursor.

Insert Comments (or other symbols)

  1. Press i for 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.

vim

326 Words

2020-09-13 21:00 +0000

comments powered by Disqus