Sie sind auf Seite 1von 2

Sheet1

VIM Cheat Sheet


COMMAND What is it ?
vi filename start editing filename, create it if necessary
:wq write the file to disk and quit
:q! quit without saving any changes
:sav newfilename save as ...
write all lines from the entire current file into the file 'newfile',
:w! newfile overwriting any existing newfile
:e c:\temp\filestopen.txt open file on the specified directory.
write the lines from n to m, inclusive, into the file newfile,
:n,m w! newfile overwriting any existing newfile
:help Display help
ESC quit from editing / cancel the command.
very helpful command. for displaying table of content. you
:help reference_toc can search the manual very fast

Editing Command
^wc Close window
^ww Move between active window
^w= Equal size for active window
^w_ Maximize the window
:tabnew Blank tab
:tab newtabfile Openfile in new tab
:tabe help Open help in new tab
:tabn x Move to tab number x
CTRL-PGUP/PGDOWN cycling to other tab
:!cmd Run cmd in console
:!xxx Run xxx (as window command) in console

Control Command
gg Scroll to top
G Scroll to bottom
xG Scroll to line X
% matching parenthesis (ex: ( will match with )
:ls list all buffers
:buffers same as above (list all buffers)
:sbuffer x open buffer in new window
:bnext go to next buffer
:bprevious go to previous buffer
:bfirst go to the first buffer
:blast go to the last buffe
:bdelete x delete buffer no x
:bwipe delete all unlisted buffer
:buffers! display all unlisted (closed buffer)
type gf after you select a specific file, vi will search the file for
gf you. (for example gf.php)
:find filename search filename

Regular Expression (Search and Replace)


/string /search for string

Page 1
Sheet1

/[a-zA-Z]*\.exe/ will match everything that has .exe

:%s/pattern/string/flags Replace pattern with string according to flags.


Notes % = for all file. while 8,10 means range line 8-10 only
g flag: replace all
c flag: confirm replace
i flag: ignore case
I flag: dont ignore case – case sensitive
\1 = (\w\+) , \2 = (\s\+\) \3=(\w\+\) thus this will reorder the
s:\(\w\+\)\(\s\+\)\(\w\+\):\3\2\1: string
Regex Operator Precedence
\(\) grouping
\=,\+,*,\{n} etc. quantifiers
sequence of characters/ metacharacters, not containing
abc\t\.\w quantifiers or grouping operators
\| alternation

^x^p code completion when you type only part of the word
omnifunc code completion (on version 7.0) – must have
^x^o omnixxx installed
:vimgrep texttosearch ../*.php search text in all file and directory
Misc Stuff
:pwd where are you now ? this will display your current directory
:cd c:\test\blablbla\ go to directory specified
:!dir dir command
:find filename search the file in current directory
:helptags c:\vim\_vimfiles\doc add local help on help

Vi Resources
http://rayninfo.co.uk/vimtips.html Tips and tricks about Vi
http://www.geocities.com/volontir/ Tips and tricks
http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/
VIM Color scheme
http://www.vim.org/scripts/index.php VIM Script collection
http://www.vim.org/tips/index.php tips frim vim

Page 2

Das könnte Ihnen auch gefallen