Vim is a powerful text editor tool which can be loved or hated. Usually the love comes with practical knowledge on ho to effectively use this tool.

Why is Vim such popular software and why is it even consider a competition to software such as VS Code or Sublime Text? Vim is very extendable such as his competitors. However there is something special about Vim… it have its own super powers one of them are MACROS. This powerful feature allows you to record your input and commands to a key shortcuts and execute them at later point. This is a monster of a feature and this is one of the reason that it is so popular. MACROS combined with light weight and speed and possibilities to extend is what make it so famous that is wildly used even in 2021. Vim can be run in terminal so it also score extra points for being easy accessible on server machines.

It also very specific. Unlike other text editor we mention in this article in Vim you don’t use mouse to navigate with in document. This specific workflow might seems little bit odd at the start but once you get to know how to efficiently move around with keys it will not be an issue any more.

So if you happen to work with Vim occasionally and you want to make this time little bit more of a pleasure rather then hard time stick with this article to the end.

  1. Vim uses two mode normal (search/edit) and “insert” (insert) mode. Switch between them by pressing “Esc” and “i” on your keyboard. Note that you can modify content of a file while being in normal mode.
  2. Navigate one step at a time in document while in normal mode with arrow keys or use “h”, “j”, “k”, “l” keys. Note that to navigate in “insert” mode you can only use arrow keys.
  3. Move to the next word start/end previous word start with keys:
    • “w” – next word start,
    • “e” – next word end,
    • “b” – previous word start.
      * Note – you can use numbers to multiply key press like 2w or 5e instead of pressing ww / eeeee
  4. You can use multiple insert using notation in normal mode like:
    • [being in normal mode] “5i-” (press Esc) will produce —–
  5. Basic search line using f/F
    • Use “fo” to find next occurrence of “o” char in current line
    • Use “Fo” to find previous occurrence of “o” char in current line
      * Note – you can combine this with number to find x occurrence using for example “3fo”
  6. Use % to jump to starting / ending parentheses/brackets: { [ ( and ) ] }
  7. Jump to start / end of the file using:
    • “0” – start of the line
    • “$” – end of the line
  8. Find word under cursor:
    • “*” – next
    • “#” – previous
      * Note – you can combine this with number to find x occurrence using for example “2*”
  9. Navigate to first, last or specific line of a file:
    • “gg” – first line of a file
    • “G” – last line of a file
    • “4gg” – 4 line of a file
    • :4 – will also go to line 4
  10. Advance search with “/” – use word search or regular expression search.
    • “/” (type text) (press Enter) (navigate with “n” and “N”)

Find and replace word globally:
:%s/foo/bar/g

Clean up

Remove all vim support files with:
ls -a | grep yourfilename.ext.sw.$ | xargs rm -f

Context-Aware Actions

i, I change to insert mode

h, j, k, l move left, down, up, right

w, b, e, ge move word at a time

[n][action/movement] do n times, e.g. 3w

x, X remove a character

a, A append

f[char] move to next given char in line

F[char] move to previous char in line

; and , repeat last f or F

/yourtext and then: n, N Search text

d[movement] delete by giving movement

r[char] replaces character below cursor

0, $ move to start/end of line

o, O add new line

% Goto corresponding parentheses

ci[movement] change inside of given movement

D delete to end of line

S clear current line; to insert mode

gg / G move to start / end of buffer

yy copy current line

p Paste copied text after cursor.


Learn VIM

Configure VIM like VS Code

src:

https://openvim.com/

Common issues:

https://stackoverflow.com/questions/41308915/vim-recording-a-macro-with-an-escape-key-press-does-not-work-correctly

https://vim.fandom.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell

/c/users/name/.vimrc

0
Would love your thoughts, please comment.x
()
x