Vim Common commands

Source: Internet
Author: User
Tags html tags parent directory save file uppercase letter

Basic commands
: E filename Open filename for 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 as filename
. Repeats the last change made in normal mode
5. Repeats 5 times The last change made in normal mode
Move around in a file
K or Up Arrow Move the cursor up one line
J or down Arrow Move the cursor down one line
E Move the cursor to the end of the word
B Move the cursor to the begining of the word
0 Move the cursor to the begining of the line
G Move the cursor to the end of the file
Gg Move the cursor to the begining of the file
L Move the cursor to the bottom of the
: 59 Move cursor to line . Replace the desired line number.
20| Move cursor to column .
% 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 Line
y$ Copy to end of line
D Cut to end of line
X Delete Current Cursor Char
Search
/word Search word from top to bottom
? word Search word from bottom to top
* Search the word under cursor
/\cstring Search string or string, case insensitive
/jo[ha]n Search John or Joan
/\< the Search the, theatre or then
/the\> Search The or breathe
/\< the\> Search the
/\<¦.\> Search all words of 4 letters
/\/ Search Fred but not Alfred or Frederick
/fred\|joe Search Fred or Joe
/\<\d\d\d\d\> Search exactly 4 digits
/^\N\{3} Find 3 Empty lines
: bufdo/searchstr/ Search in all open files
Bufdo%s/something/somethingelse/g Search something in all the open buffers and replace it with SomethingElse
Replace
:%s/old/new/g Replace all occurences of the old by new in 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 by Hello
:%s/$/harry/g Replace the end of each line by Harry
:%s/onward/forward/gi Replace onward by forward, Case unsensitive
:%s/*$//g Delete All white spaces
: g/string/d Delete all lines containing string
: v/string/d Delete all lines containing which didn ' t contain string
: s/bill/steve/ Replace the first occurence of Bill by Steve
: s/bill/steve/g Replace Bill by Steve
:%s/bill/steve/g Replace Bill by Steve in all the file
:%s/^m//g Delete DOS Carriage Returns (^M)
:%s/\r/\r/g Transform DOS Carriage returns in returns
:%s#<[^>]\+># #g Delete HTML tags but keeps text
:%s/^\ (. *\) \n\1$/\1/ Delete lines which appears twice
CTRL + A Increment number under the cursor
Ctrl+x Decrement number under cursor
Ggvgg? Change Text to Rot13
Uppercase and lowercase
Vu Lowercase line
Vu Uppercase Line
g~~ Invert case
VEU Switch Word to uppercase
ve~ Modify Word case
Gggug Set all text to lowercase
Gggug Set all text to uppercase
: Set ignorecase Ignore Case in searches
: Set Smartcase Ignore case in searches excepted if a uppercase letter is used
:%s/\<./\u&/g Sets first letter of each word to uppercase
:%s/\<./\l&/g Sets first letter of each word to lowercase
:%s/.*/\u& Sets first letter of all line to uppercase
:%s/.*/\l& Sets first letter of all line to lowercase
Read and write files
: 1,10 w outfile Saves lines 1 to ten in outfile
: 1,10 W >> outfile Appends lines 1 to outfile
: R infile Insert the content of infile
: 23r infile Insert the content of infile under line 23
File browser
E. Open Integrated File explorer
: Sex Split window and open integrated File explorer
: sex! Same as : Sex but 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 contening expression
Gf Open file name under cursor
Interacting with Unix systems
:!pwd Execute the pwd Unix command, then returns to Vi
!! Pwd Execute the pwd Unix 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 on the current position
5!! Fmt Align the next 5 lines
Tabs/Windows
: tabnew Creates a new tab
Gt Show next Tab
: Tabfirst Show first Tab
: Tablast Show last Tab
: tabm N (position) Rearrange tabs
: Tabdo%s/foo/bar/g Execute a command in all tabs
: Tab Ball Puts all open files in tabs
: New Abc.txt Edit abc.txt in New window
Split screen Display
: E filename Edit filename in current window
: Split filename Split the window and open filename
Ctrl-w Up ARROW Puts cursor in top window
Ctrl-w ctrl-w Puts cursor in next window
Ctrl-w_ Maximize Current Window vertically
ctrl-w| Maximize Current Window horizontally
ctrl-w= Gives the same size to all windows
Ten ctrl-w+ ADD ten lines to the current window
: Vsplit File Split window vertically
: Sview File Same as : Split in readonly mode
: Hide Close Current Window
: nly Close all windows, excepted current
: B 2 Open #2 in this window
Auto-complete
CTRL + N ctrl+p (in insert mode) Complete Word
Ctrl+x ctrl+l Complete line
: Set Dictionary=dict Define dict as a dictionnary
Ctrl+x ctrl+k Complete with Dictionnary
Mark
m {A-Z} Marks Current position as {A-Z}
' {A-Z} Move to position {A-Z}
‘‘ Move to previous position
Abbreviation
: AB Mail [email protected] Define Mail as abbreviation of [email protected]
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
Code highlighting
: Syntax on Turn on syntax highlighting
: Syntax off Turn off syntax highlighting
: Set Syntax=perl Force syntax highlighting

Http://www.cnblogs.com/lhb25/p/130-essential-vim-commands.html

Vim Common commands

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.