Page content

as i’m using vim almost every day, why not make some notes to improve the skillz ?

Source: and others …


my vim config file. do backup of the old file first!

test -f ~/.vimrc && cp ~/.vimrc ~/.vimrc.bak-$(date "+%s")
cat << 'EOF' > ~/.vimrc
" sample .vimrc from

" Use 2 spaces for tabs
set shiftwidth=2
set tabstop=2
set expandtab
set softtabstop=0
set ruler
set mouse=r

" Disable backup and swap files because they cause more problems than they solve
set nobackup
set noswapfile

" Display line numbers
set number

" Color
syntax on
" colorscheme delek

show whitespaces

:set list

show numbers

:set numbers

ignore case

:set ignorecase

Convert File to xxd (hex editor)


Revert to VIM

:%!xxd -r

Search & Replace

search for ‘box’ from line 1 to the End of the File and replace it with ‘BOX’


: command
1 start line 1
$ until end of file
s search
box search string
BOX replace string
g globally (if multiple matches on the same line …)

Shift Line 1-10 Lines two Spaces to the Right

:1,10s/^/  /

Open File, Position Line 100

vim +100 myfile

Open File, Position on ‘box’

vim +/box myfile

Open Two Files im Diff Mode

vim -d file1 file2

Open ReadOnly

vim -R myfile

Inserting Chars

i at cursor
I at the Beginning of the Line
a after the Cursor
A at the End of the Line

Inserting Lines

o insert line after the current line O insert line before the current line

Deleting Chars

x under cursor
X before cursor

Deletinge line

dd delete current line
2dd delete current and next line
J deleting linebreak (merge two lines)

Undo / Redo

u undo
CTRL-R redo


:q quit without save
:q! quit without save, lose changes
:w quit and save changes
ZZ quit and save changes

moving around

w one word foward
9w nine words foward
b one word backward
9b nine word backward
:1 move to first line
:100 move to line 100
gg move to first line
G move to last line
50% move to middle of the File
75% move 3/4 to the File
H move top of visible screen
M move middle of visible screen
L move end of visible screen

/hi search hi forward
?hi search hi backward


qa (start macro 'a')
asf asdf asdf (do things ...)
j (jump next line)
q (quit macro)

@a apply macro
3@a 3 x apply macro

Any Comments ?

sha256: 5f659d2c1f7e9f0cc329b48b99af26c08e76aa16a431a03ad7e4d7a09d56fe32