ITPub博客

首页 > IT职业 > IT职场 > Senior DBA 之必备vim技能

Senior DBA 之必备vim技能

原创 IT职场 作者:fjzcau 时间:2012-04-30 18:07:58 0 删除 编辑

secooler

http://space.itpub.net/519536/viewspace-608647

[@more@]

Search

/wordSearch “word” from top to bottom
?wordSearch “word” from bottom to top
/jo[ha]nSearch “john” or “joan”
/Search “the”, “theatre” or “then”
/the>Search “the” or “breathe”
/Search “the”
/<….>Search all words of 4 letters
//Search “Andy” but not “HouAndy” or “AndyHou”
/Andy|AnnaSearch “Andy” or “Anna”
/Search exactly 4 digits
/^n{3}Find 3 empty lines
:bufdo /searchstr/Search in all open files

Replace

:%s/old/new/gReplace all occurences of “old” by “new” in file
:%s/old/new/gwReplace all occurences with confirmation
:2,35s/old/new/gReplace all occurences between lines 2 and 35
:5,$s/old/new/gReplace all occurences from line 5 to EOF
:%s/^/hello/gReplace the begining of each line by “hello”
:%s/$/Harry/gReplace the end of each line by “Harry”
:%s/onward/forward/giReplace “onward” by “forward” , case unsensitive
:%s/ *$//gDelete all white spaces
:g/string/dDelete all lines containing “string”
:v/string/dDelete all lines containing which didn't contain “string”
:s/Bill/Steve/Replace the first occurence of “Bill” by “Steve” in current line
:s/Bill/Steve/gReplace “Bill” by “Steve” in current line
:%s/Bill/Steve/gReplace “Bill” by “Steve” in all the file
:%s/r//gDelete DOS carriage returns (^M)
:%s/r/r/gTransform. DOS carriage returns in returns
:%s#<[^>]+>##gDelete HTML tags but keeps text
:%s/^(.*)n1$/1/Delete lines which appears twice
Ctrl+aIncrement number under the cursor
Ctrl+xDecrement number under cursor
ggVGg?Change text to Rot13

Case

VuLowercase line
VUUppercase line
g~~Invert case
vEUSwitch word to uppercase
vE~Modify word case
ggguGSet all text to lowercase
:set ignorecaseIgnore case in searches
:set smartcaseIgnore case in searches excepted if an uppercase letter is used
:%s/<./u&/gSets first letter of each word to uppercase
:%s/<./l&/gSets first letter of each word to lowercase
:%s/.*/u&Sets first letter of each line to uppercase
:%s/.*/l&Sets first letter of each line to lowercase

Read/Write files

:1,10 w outfileSaves lines 1 to 10 inoutfile
:1,10 w >> outfileAppends lines 1 to 10 tooutfile
:r infileInsert the content ofinfile
:23r infileInsert the content ofinfileunder line 23

File explorer

:e .Open integrated file explorer
:SexSplit window and open integrated file explorer
:browse eGraphical file explorer
:lsList buffers
:cd ..Move to parent directory
:argsList files
:args *.phpOpen file list
:grep expression *.phpReturns a list of .php files conteningexpression
gfOpen file name under cursor

Interact with Unix

:!pwdExecute the “pwd” unix command, then returns to Vi
!!pwdExecute the “pwd” unix command and insert output in file
:shTemporary returns to Unix
$exitRetourns to Vi

Alignment

:%!fmtAlign all lines
!}fmtAlign all lines at the current position
5!!fmtAlign the next 5 lines

Tabs

:tabnewCreates a new tab
gtShow next tab
:tabfirstShow first tab
:tablastShow last tab
:tabm n(position)Rearrange tabs
:tabdo %s/foo/bar/gExecute a command in all tabs
:tab ballPuts all open files in tabs

Window spliting

:e filenameEditfilenamein current window
:split filenameSplit the window and openfilename
ctrl-w up arrowPuts cursor in top window
ctrl-w ctrl-wPuts cursor in next window
ctrl-w_Maximise current window
ctrl-w=Gives the same size to all windows
10 ctrl-w+Add 10 lines to current window
:vsplit fileSplit window vertically
:sview fileSame as:splitin readonly mode
:hideClose current window
:onlyClose all windows, excepted current
:b 2Open #2 in this window

Auto-completion

Ctrl+n Ctrl+p (in insert mode)Complete word
Ctrl+x Ctrl+lComplete line
:set dictionary=dictDefinedictas a dictionnary
Ctrl+x Ctrl+kComplete with dictionnary

Marks

mkMarks current position ask
‘kMoves cursor to markk
d’kDelete all until markk

Abbreviations

:ab mail mail@provider.orgDefinemailas abbreviation ofmail@provider.org

Text indent

:set autoindentTurn on auto-indent
:set smartindentTurn on intelligent auto-indent
:set shiftwidth=4Defines 4 spaces as indent size
ctrl-t, ctrl-dIndent/un-indent in insert mode
>>Indent
<<Un-indent

Syntax highlighting

:syntax onTurn on syntax highlighting
:syntax offTurn off syntax highlighting
:set syntax=perlForce syntax highlighting

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22661144/viewspace-1058082/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-04-03

  • 博文量
    208
  • 访问量
    547191