130 VIM commands that programmers should know

Source: Internet
Author: User
Tags exit html tags lowercase parent directory php open file save file split uppercase letter

Since 1970, VI and Vim have become one of the programmer's favorite text editors. 5 years ago, I wrote a question to ask myself "every programmer should know the 100 vim command" This is the previous article of the improved version, I hope you will like.
Basis

: E filename openfilenamefor edition:w Save file:q Exit vim:q! Quit without saving:x Write file (if changes has been made) and Exit:sav filename saves file asfilename. Repeats the last change made in normal mode 5. Repeats 5 made in normal mode

Move through files

K or up ARROW move the "cursor up one line J" or "Arrow move" cursor down one line e move the cursor to the "end of TH" E word B Move the "cursor to" begining of the word 0 move the cursor to the begining of the "line G-move" cursor to th E End of the "line GG" move "cursor to" begining of the "the" the cursor to the "end of" the file:59 move cursor To line59. Replace59by the desired line number. 20| Move cursor to Column20. % move cursor to matching parenthesis [[Jump to function start] [{Jump to block start

Cut, copy, and paste

Y Copy the selected text to clipboard P Paste Clipboard contents dd Cut Current line yy Copy current y$ copy to end O F line D cut to end of line

Search

/word Searchwordfrom bottom? Word searchwordfrom bottom to top * Search the word under cursor/cstring orstring, Case insensitive/jo[ha]n Searchjohnorjoan/< the Search theatre orthen/the> searchtheorbreathe ; The> searchthe/<¦.> Search All words of 4 letters//Searchfredbut Notalfredorfrederick/fred|joe Searchfredorj OE/<dddd> Search exactly 4 digits/^{3} Find 3 empty lines:bufdo/searchstr/search in all open files Bufdo%s/som Ething/somethingelse/g Searchsomethingin all the open buffers and replace it withsomethingelse

Replace

:%s/old/new/g Replace all occurences Ofoldbynewin file:%s/onward/forward/gi replace onward by forward, case unsensitive: %S/OLD/NEW/GC Replace all occurences with confirmation:2,35s/old/new/g replace all occurences between lines 2 and 35:5,$ s/old/new/g Replace all occurences from line 5 to EOF:%s/^/hello/g replace the begining of each line Byhello:%s/$/harry/ G Replace the "End of" Byharry:%s/onward/forward/gi Replaceonwardbyforward, Case unsensitive:%s/*$//g Delete al L White spaces:g/string/d Delete all lines containingstring:v/string/d delete all lines containing which didn ' t contains Tring:s/bill/steve/replace the occurence ofbillbystevein current line:s/bill/steve/g Replacebillbystevein Curren T line:%s/bill/steve/g Replacebillbystevein all the file:%s/^m//g Delete dos carriage Returns (^m):%s///g Transform dos Carriage returns in returns:%s#<[^>]+># #g Delete HTML tags but keeps text:%s/^ (. *) 1$/1/delete lines App Ears twice Ctrl + a IncremeNT number under the cursor ctrl+x decrement number under cursor Ggvgg? Change Text to Rot13

casing

Vu lowercase line vu uppercase line g~~ Invert case VEU Switch Word to uppercase ve~ Modify word CAs e Gggug set all text to lowercase gggug set all text to Uppercase:set ignorecase Ignore case in Searches:set I Gnore case in searches excepted if a uppercase letter is used:%s/<./u&/g Sets ASE:%s/<./l&/g Sets A of each of lowercase:%s/.*/u& Sets Se:%s/.*/l& Sets-lowercase

Read-write file

: 1,10 w outfile saves lines 1 to ten inoutfile:1, Ten W >> outfile appends lines 1 to ten tooutfile:r infile insert the content ofinfile:23r infile insert the content Ofinfileunder Line

File browser

E. Open Integrated File Explorer:sex Split window and open integrated file explorer:sex! Same as:sexbut Split window vertically:browse e graphical file Explorer:ls List buffers:cd. Move to Parent Directory:args List Files:args *.php Open file list:grep expression *.php Returns a list of. php files C Onteningexpression GF Open file name under cursor

Interacting with Unix systems

:!pwd Execute Thepwdunix Command, then returns to Vi!! PWD Execute thepwdunix command and insert output in File:sh temporary returns to Unix $exit Retourns to Vi

Snap To

:%!fmt Align all lines!} FMT Align All lines in the current position 5!! FMT Align the next 5 lines

Tabs/windows

: Tabnew Creates a new tab GT show next Tab:tabfirst show I tab:tablast show last tab:tabm n (position) Rearrange tab S:tabdo%s/foo/bar/g Execute a command in all Tabs:tab ball Puts all open files in tabs:new abc.txt editabc.txtin new W Indow

Split-screen display

: E filename editfilenamein current window:split filename split the windows and OpenFileName ctrl-w up arrow Puts cursor in Top window ctrl-w ctrl-w Puts cursor at next window ctrl-w_ maximize Current window vertically ctrl-w| Maximize current window horizontally ctrl-w= gives the same size to all Windows ctrl-w+ Add lines to current window : Vsplit file Split window Vertically:sview file Same as:splitin readonly mode:hide close Current window:nly Windows, excepted current:b 2 Open #2 in this window

Automatic completion

CTRL + N ctrl+p (in insert mode) Complete Word ctrl+x ctrl+l Complete line:set dictionary=dict definedictas a dictionnary C Trl+x ctrl+k Complete with Dictionnary

Marks

m {A-Z} Marks current position as{a-z} ' {A-Z} move to Position{a-z} ' move to previous position

Abbreviation

: AB Mail mail@provider.org definemailas abbreviation ofmail@provider.org

Text indent

: Set autoindent Turn on Auto-indent:set smartindent Turn on Intelligent auto-indent:set shiftwidth=4 defines 4 spaces as Indent size ctrl-t, ctrl-d indent/un-indent in insert mode >> indent << un-indent =% indent the code between Parenthesis 1gvg= Indent the whole file

Syntax highlighting

: Syntax on Turn on syntax highlighting:syntax out Turn off syntax highlighting:set syntax=perl Force syntax highlighting

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.