Starting Vim
vim [file1] [file2] ...
vim has 3 main modes:
- Normal mode: For navigation and manipulation of text. This is the mode that vim will usually start in
- Insert (edit) mode: For inserting new text, where you type into your file like other editors.
- Command mode: For executing extra commands like the help, shell, ...
move around the text (file) by:
gg
<ctrl b>
<ctrl u>
-
k
^
0 / ^ / B / b / h < > l / e / E / w / W / $
v
j
<ctrl d>
<ctrl f>
G
h
: leftj
: downk
: upl
: right
w
: next wordW
: next WORDb
: previous wordB
: previous WORDe
: end of wordE
: end of WORD
0
: begin of line (column 0)^
: begin of line (non-blank)$
: end of line-
=k^
: start of previous linej^
: start of next line
H
: top of windowM
: middle of windowL
: low (bottom) of windowzt
: scroll to topzz
: scroll to middlezb
: scroll to bottom<ctrl b>
/<ctrl f>
: previous / next page<ctrl u>
/<ctrl d>
: previous / next half page(<ctrl w>t) <ctrl w>H
: change 2 Windows from horizontal to split(<ctrl w>t) <ctrl w>K
: change 2 Windows from split to horizontal
searching in Normal Mode:
f[char]
/F[char]
: find forward / backward to next / previous char (exactly on char)t[chat]
/T[char]
: up to forward / backward to next / previous char (next to the char),
/;
: previous / next repeat forf
/t
/F
/T
action*
/#
: find current word backward / forward/[pattern]
/?[pattern]
: search forward / backward by matching patternn
/N
: next / previous result[I
: show lines with matching word under cursor
<ctrl o>
: jump back<ctrl i>
: jump forward<ctrl 6>
: jump to the buffer you just left<ctrl ]>
: jump to tag under cursor (if./tags
is available)''
: jump back to last jump'.
: jump to last edited line{
/}
: previous / next paragraph%
: matching (), {}, []m[char]
/'[char]
: mark by / jump to[char]
m[CHAR]
/'[CHAR]
: mark by / jump to[CHAR]
across the files.
gg
/G
: go to begin / end of file[num]gg
/[num]G
/:num<CR>
: go to line numgd
: go to definition of current wordgf
: go to the file (under the cursor)gi
: go to last insertedgv
: go to last selected and select
these commands take you in Insert Mode
:
i
: insert at left of cursorI
-> insert at the line beginning (non-blank)a
: insert at right of cursorA
: insert at end of lineo
: insert by adding new line below the cursorO
: insert by insert new line above the cursors
: substitute at cursor and enter insert modeS
=^DA
=ddO
: delete current line and enter insert modeC
=c$
: change line from cursor to EOL<c-i>
: right indent(>>)(In Insert-mode)<c-d>
: left indent(<<)(In Insert-mode)
editing the text without transition to Insert Mode
:
.
: repeat last command~
: swap casex
: delete char current charr
: replace char under the cursordd
: delete current lineJ
: merge with the next lineD
: delete line from cursor to the EOLyy
: yank/copy current lineu
: undo<ctrl r>
: redo
paste:
p
: paste to the next lineP
: paste above current line
visual mode:
v
: into visual/select modeV
: into visual/select mode by line<ctrl v>
: into visual/select mode by block
alignment:
=<CR>
,==
: auto indent><CR>
,>>
: shift right, increase indent<<CR>
,<<
: shift left, decrease indent
operator are generally constructed as:
[operator][count][motion]
[operator]i[motion]
- operators:
c
: change command ...d
: delete ...y
: yank (copy) ...g~
: swap case ...gu
: to lower case ...gU
: to upper case ...
- motion:
w
/W
: word / WORD[
,]
: block(
,)
: block<
,>
: block"
,'
: in double quote or quotet
: XML/HTML tags
: sentence
examples:
di)
: delete the text inside current paranthesisci"
: change the text inside ""gUiw
: make the word under the cursor to upper case
"[char][y|d]
: yank/delete into register"[char][p|P]
: paste from register:echo @[char]
: shows register content:reg[isters]
: shows all registers
q[char]
: start recording into registerchar
q
: stop recording macro@[char]
: play macro in registerchar
@@
: repeat last playback
zi
: toggles folding on or offza
: toggles current fold open or closezc
: close current foldzC
: close current fold recursivelyzo
: open current foldzO
: open current fold recursivelyzR
: open all foldszM
: close all foldszv
: expand folds to reveal the cursorzk
/zj
: move to previous / next fold
<ctrl w> s
=:sp[lit]
: split current window horizontally<ctrl w> v
=:vs[plit]
: split current window vertically<ctrl w> c
=:cl[ose]
: close current window<ctrl w> o
=:on[ly]
: close all windows except current one<ctrl w> <ctrl w>
: switch to next split window<ctrl w> <ctrl p>
: switch to previous split window<ctrl w> hjkl
: switch (move cursor) to left, below, above or right split<ctrl w> HJKL
: move current window to left, below, above or right<ctrl w> r
: rotate window clockwise<ctrl w> =
: make all windows equal in size[num]<ctrl w> -
: increase/decrease current window height[num]<ctrl w> <>
: increase/decrease current window width<ctrl w> _
: maximize current window<ctrl w> T
: move current window to new tab
]s
/[s
: jump to next / previous spelling errorz=
: suggest corrections for current wordzg
: add current word to the dictionaryzw
: remove current word from dictionary
Esc
=<ctrl c>
=<ctrl [>
: exit insert mode
<ctrl p>
: auto-complete / previous item<ctrl n>
: auto-complete / next item<ctrl x><ctrl l>
: auto complete line mode<ctrl x><ctrl f>
: auto complete file
<ctrl w>
: delete word before cursor<ctrl u>
: delete line before cursor<ctrl r>[char]
: insert content of register[char]
<ctrl t>
: increase line indent<ctrl u>
: decrease line indent<ctrl a>
: insert last inserted text(wie "." im Normal-Mode)
CTRL-Left
: jump left for 1 wordCTRL-E
: jump to the end of the commandCTRL-B
: jump to the beginning of the commandCTRL-R
: lets you get access to the registersCTRL-R CTRL-W
: adds the word under the cursor to the commandlineCTRL-P
: Previous commandCTRL-N
: Next command
:%s/four/4/g
: substitiutes all "four" with "4" in the whole bufferflag g
: substitutes all occurence in the lineflag c
: ask before substitutionflag e
: when no substitiution occurs, it won't end in an error\<
: signalises the beginning of a word\>
: signalises the end of a word\1
: is a backreference, refers to the "( )"
:jumps
: shows the jump list:changes
: shows the change list:reg[isters]
: shows the registers:marks
: shows the marks:delm[arks] {marks}
: delete specified mark(s)delm a b 1 \"
: deletesa
,b
,1
and"
delm a-h
: deletes all marks froma
toh
:delm[marks]!
: deletes all lowercase marks
:w[rite]
: write current file:q
: close/quit current file, split or tab:wq
=ZZ
: write current file and quit:q!
=ZQ
: quit without writing the changes:qa
: quit all splits:ls
: list all open files/buffers:f[ile]
=<ctrl g>
: shows current file path:e[dit]
: open a file for editing:ene[w]
: open a blank new file for editing:b<n>
: jump to buffern
returned from:ls
:b <file>
: jump to bufferfile
, Tab to scroll through available options:bn[ext]
: jump to next buffer:bp[rev]
: jump to previous buffer:bd[elete]
: remove file from buffer list:vert sb 1
: vertically splits buffer 1
:mak[e]
: run make in current directory:cw
: toggle mini window for errors:!
: executes external shell command:r[ead]
: read external program output into current file(mostly used as :r! "some terminal command")
:sp[lit]
=<ctrl w> s
: split current window horizontally:vs[plit]
=<ctrl w> v
: split current window vertically:cl[ose]
=<ctrl w> c
: close current window:on[ly]
=<ctrl w> o
: close all windows except current one:sp | terminal
= opens in split-screen the terminal
<ctrl w> gf
: open file under the cursor into new tab:tabs
: list current tabs and windows:tabn
=<ctrl PageDown>
: next tab:tabn <n>
: goto tabn
:tabp
=tabN
=<ctrl PageUp>
: previous tab:tabe [file]
: create a new blank tab or opensfile
in that tab
:h cmd
: normal mode command help:h :cmd
: command line help for cmd:h i_cmd
: insert mode command help:h v_cmd
: visual mode command help:h c_cmd
: command line editing cmd help:h 'option'
: help of option:helpg[rep]
: search through help docs!
:h motions
:h word-motions
:h jump-motions
:h mark-motions
:h operators
:h buffres
:h windows
:h tabs
:h registers
:h pattern-searches
:set <opt>?
: shows current option value:set no<opt>
: turn off flagopt
:set opt
: turn on flagopt
:set opt=val
: override value ofopt
:set opt =val
: appendval
toopt
:echo &opt
: shows value ofopt
hidden
orhid
: when off, a buffer is unloaded when it's abandoned.laststatus
orls
: shows status line: 0 (never), 1 (only if at least two windows), 3 (always)hisearch
orhis
: highlight search matchesnumber
ornu
: shows line numbershowcmd
orsc
: shows command as you type them (may not be available on your compilation)ruler
orru
: shows line and column number of the cursorwrap
: controls line wrappingignorecase
oric
: ignores case for search patternssmartindent
orsi
: flag for smart indentingfoldmethod
orfdm
: fold methodspell
/nospell
: turn spell checking enable or disable.
:s/search/replace/
: basic substitution on a line:%s/search/replace/
: run substitution on every line:%s/search/replace/g
:g
flag means apply to every match:%s/search/replace/c
:c
flag means ask for confirmation
by executing $> ctags -r
under project tree:
:tag <name>TAB
: goes to tag name<ctrl ]>
: goes to the tag under cursor
:mksession <Session Name>.vim
: Creates a session with the actual opened filesvim -S <Session Name>.vim
: Opens the session
gi
: open file in horizonal split, but stay in Nerdtreegs
: open file in vertical split, but stay in Nerdtree
do
: get all changes from other window into the current windowdp
: put all the changes from current window into the other window]c
: jump to the next change[c
: jump to the previous changezo
: open foldzc
: close foldzr
: reducing folding levelzm
: one more folding level, please:diffupdate
,:diffu
: recalculate the diff*:.diffg LOCAL
: get this line from LOCAL file (Beachte den "." vor diffg!!)V :diffget
: get this visually selectedV :diffput
: put this visually selected:diffg RE
: get from REMOTE:diffg BA
: get from BASE:diffg LO
: get from LOCAL:diffoff
: to turn diff off:diffthis
: to turn diff on
gU{motion}
: uppercase everything in {motion}(gu for lowercase)gc{motion}
: Comment line(commentary Plugin)cgn
: must have highlighted a word. Will be very useful for '.'
ctrl-h
: backspacectrl-w
: delete backwards a wordctrl-u
: delete from cursor to start of linectrl-o
: goes for ONE command to normal mode and automatic back to insert mode
o
: Go to other end of highlighted text
:(vert) term
: opens terminal
http://vimcasts.org/ http://viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html