VIM for productivity

Published by barishaxxer on 2025-01-12
This article has been written using nano
Press esc type :wq! is answer to how to quit vim

First of all

Ensure your tabsize is 4.

esc + set ts=4

Quick operations on lines

yy -> copy line
pp -> paste
dd -> delete line
M -> moves to middle of lines
H -> moves to the top
L -> moves to the bottom
0 -> moves to beginning of the line
$ -> moves to the end of the line
123gg or press esc then :123 -> move to line 123
u -> undo
gg -> to beginning of the file
G -> to the end

Insert mode

fn + delete -> forward delete

Search and Replace

%s/regex/new/g -> replace every match of regex with new

- % indicates to scan all file
- 1,5 indicates to scan 1 to 5
- s indicates substitute mode
- g indicates change all existence
- i indicates ignore case

/regex -> search for regex
n -> moves to next hit
N -> moves to preceding hit

Important to consider

Vim follows POSIX Basıc Regular Expression (BRE) which slightly differs from Extended Regular Expression (ERE). BRE tends to treat characters as literals so involves more backslashes to give them special meaning.

ERE | BRE
    |      
{5} | \{5} 
()  | \(\) 
\b  | \<\>

Further information can be found here