VIM-related commands are documented separately

Source: Internet
Author: User
Tags set background

1. Unbeatable scalability

1.1 Scalability gives software a powerful life

Once upon a while, Windows users had no concept of software extensibility, and they could only make very limited customizations to the software they used. The right to extend the software remains in the hands of the software developer. Users of software who want new features and features can only wait for the software to be upgraded. The ability of the user can not wait, in order to add the features they want, starting from 0 to write a new software. In this way, new features mean new software, software wave upon wave under Windows, and rapidly updating. As a result, software under Windows is very short-lived.

Emacs and Vim have not been eliminated by the times, but are becoming more powerful because they have unmatched scalability in countless editors.

1.2 Emacs is an operating system disguised as an editor

1.3 Vim is not just VI

2. The charm of Maverick

2.1 Extensibility gives you the soul

2.2 Unique modes of operation that you're poisoned.

3. Hacker's editor

4. Holy war caused by artifact

Vim Users and Emacs users have a comparable taste, they should appreciate each other. The reality is that users who are loyal to vim are incompatible with users loyal to Emacs, and often fight with endless battles. Emacs users say that Vim operates in a single and eccentric way, and vim users say that Emacs is bulky and slow to start.

Press Esc Enter normal mode, use the arrow keys in this mode or,,, the h j k l Key can move the cursor.

Key Description
h Left
l Right (lowercase L)
j Under
k On
w Move to the next word
b Move to the previous word

Command Description
i Edit at current cursor
I Insert at beginning of line
A Inserting at the end of a row
a Insert an edit after the cursor
o Insert a new row after the current row
O Insert a new row before the current line
cw Replace the character from the position of the cursor to the end of a word

Try different ways to get into the insert mode from normal mode, add in front of the last line Shiyanlou www. , Notice that each time you go back to normal mode to switch to insert mode in different ways

According to the first week of experiments in the game, Vim adventure, slightly adapted to the HJKL movement, or very interesting.

Command Description
:q! Force quit, do not save
:q Exit
:wq! Force Save and exit
:w <文件路径> Save As
:saveas 文件路径 Save As
:x Save and exit
:wq Save and exit

Go to normal mode and use the following commands to quickly delete text:

Command Description
x Delete the character that the cursor contains
X Delete the previous character of a cursor
Delete Withx
dd Delete entire row
dw Delete a word (not in Chinese)
d$OrD Delete to end of line
d^ Delete to beginning of line
dG Delete to end of document
d1G Delete to document header

In addition, you can add a number to the command before it, indicating that multiple rows are deleted at once, such as:

2ddRepresents deleting 2 rows at a time

One, vim repeat command 1. Repeat the last command

In normal mode . (decimal point) means the last command operation is repeated

Copy test files to a local directory

$ cp /etc/protocols .

Open a file for editing

$ vim protocols

Normal mode input x , delete the first character, the input . (decimal point) will be deleted again a character, in addition to also can be repeated dd delete operation

Inline jump
Command Description
nG(n shift+g) Cursor moves to nth row (if no line number is displayed by default, enter command mode first :set nu to display line numbers)
gg Cursor moves to the first row
G(SHIFT+G) To the last line

tip: After you have completed the jump, you can use the Ctrl+o quick to go back to the previous (before the jump) cursor position , this technique is very practical, such as when you write code, suddenly think of a bug, need to change, this time you jump over to change, just need to press Ctrl+o You can go back to where you were before.

In-line jump

In normal mode, use the following command to jump within a line in a word

Command Description
w To the beginning of the next word
e To the end of the next word
b To the beginning of the first word
ge To the end of the previous word
0Or^ to the wardrobe.
$ To end of line
f<字母> Search backwards < letters > and jump to the first matching position (very useful)
F<字母> Search forward < letters > and jump to the first matching position
t<字母> Search backwards < letters > and jump to a letter before the first matching position (not used)
T<字母> Search forward < letter > and jump to a letter after the first matching position (not used)

Copy paste and cut 1. Copy and paste text
    • Use replication in normal mode y

      • In normal mode, yy the entire line where the cursor is copied ( 3yy representing the replication of 3 rows)
      • In normal mode, y^ copy to the beginning of the line, or y0 . Does not contain the character at which the cursor is located.
      • In normal mode, y$ copy to end of line. The character where the light is contained.
      • In normal mode, yw copy a word.
      • In normal mode, y2w copy two words.
      • In normal mode, yG copy to the end of the text.
      • In normal mode, y1G copy to the beginning of the text.
    • Use paste in normal mode p

      • In normal mode, p (lowercase) represents pasting to the cursor (bottom)
      • In normal mode, P (uppercase) means pasting to the front of the cursor (top)
Substitution and revocation of characters (undo action) 1. Replace and revoke (undo) command

Both the Replace and undo commands are for normal mode operations

Command Description
r+< to replace letters > Replace the letter that contains the cursor with the specified letter
R Continuous replacement until you press theEsc
cc Replace the entire row, which deletes the row of the cursor and enters insert mode
cw Replace a word, delete a word, and enter insert mode
CUppercase Replace cursor later to end of line
~ Reverses the case of a cursor in the same letter
uN Undo One or N operations
UUppercase Undo all changes to the current line
Ctrl+r Redo, that is, undo undo operation

Use commands to quickly adjust indent operations

This section learns how to indent quickly in vim and indent operations are effective in normal mode

Open a file for editing

$ vim protocols
    • Normal mode input 15G , jump to 15 lines
    • Input entire line in normal mode >> indent right (used to format code super cool)
    • Enter the entire line in normal mode to the << left fallback
    • Normal mode enter : command line mode to shiftwidth set values to control the number of characters for indentation and fallback
2.shiftwidth command

shiftwidthThe command refers >> to the indentation generated by the previous command (which can be abbreviated sw ). Enter : command line mode to set values in normal mode to control the number of characters in shiftwidth indentation and fallback get current setpoint

:set shiftwidth?

Set indent to 10 characters

:set shiftwidth=10

Enter ESC back into normal mode and try again to >> see if the indent changes

3. Adjust the text position

Command line mode enter :ce (center) command to center the contents of the bank

:ce

Command line mode enter :ri (right) command to make our text

:ri

Command line Mode enter: le (left) command to leave the contents of the bank

:le




Find 1. Quick Find

Enter Normal mode / and then type the string you want to find and press ENTER to find it. is the same as the / function, but looks up and / down. After entering the lookup, the input n and N can continue to find n the expression to continue the lookup, N reverse Lookup

2. Quick Find Exercises

Use VIM to open a file for editing

$ vim protocols
    • Normal mode input /icmp find string ICMP
    • Normal mode Enter to n find the next ICMP
    • Normal mode input ?tcp up lookup string TCP
    • Normal mode input N to find the last occurrence of TCP
3. Advanced Search
    • Enter \* a word in normal mode to find where the cursor is located
    • Normal mode input \# Ibid, but \* forward (up) to find, #则是向后 (bottom) find
    • Normal mode g\* \* , but partially matches the word
    • Normal mode g\# \# , but partially matches the word

Search for n The above, N continue to find command can still be used

One, multi-file editing 1. Use Vim to edit multiple files

There are two forms of editing multiple files, one being a parameter that is used before entering Vim is multiple files. Another is to enter vim and then edit the other files. Create two new files and edit them simultaneously

$ vim 1.txt 2.txt

Default Access 1.txt to file editing interface

    • Command line mode input :n edit 2.txt file, you can ! :n! Force switch, the input of a file is not saved, just switch to another file
    • Command line mode input :N edit 1.txt file, can be ! forced to :N! switch, the input in the previous file is not saved, just switch to another file
2. Open a new file after entering vim
    • Command line mode enter :e 3.txt open new file 3.txt
    • Command line mode input :e# back to the previous file
    • command-line mode input :ls to list previously edited documents
    • Command line mode input :b 2.txt (or number) can be directly into the file 2.txt edit
    • Enter :bd 2.txt (or number) in command-line mode to delete a file item from a previously edited list
    • Command line mode input :e! 4.txt , new open file 4.txt, discard the file being edited
    • Enter :f The file name you are editing in command line mode
    • Input in command line mode :f new.txt , change the file being edited name to New.txt
3. Recover files

If the document is not saved due to a power outage, you can use the recovery method, enter the vim -r document, input :ewcover 1.txt to restore

$ vim -r 1.txt
Second, Visual Mode 1. Introduction to Visual Mode commands
    • Enter in normal mode v (lowercase), enter the character selection mode, you can move the cursor, where the cursor will be selected. The selection is deselected when the V-meeting is pressed again.
    • In normal mode input Shift+v (lowercase), enter the line selection mode, press V will be the entire row selection, you can move up and down the cursor select more rows, again, press once Shift+v can be deselected.
    • In normal mode Ctrl+v (lowercase), this is the area selection mode, you can select the rectangular region, and then cancel the selection by one time Ctrl+v .
    • Enter d Delete selection area in normal mode
    • Enter y Copy selection area contents in normal mode
2. Visual Mode Command Practice

Copy the practice file to the current directory

$ cp /etc/protocols .

Open the practice file

$ vim protocols
    • In normal mode 9G , jump to line 9th, enter Shift+v (lowercase v), enter the visual mode for row selection, select 5 rows, press >> indent, indent 5 rows into oneshiftwidth
    • Enter in normal mode Ctrl+v (lowercase v), enter visual mode for rectangular area selection, select the first column character and then x delete the whole column
1. Introduction to Windows operation

Vim can open multiple windows in one interface for editing, which are called Vim windows. There are many ways to open a method, for example, you can use the command-line mode to enter : New   Open a new Vim window, and enter the window to edit a new file (normal mode input ctrl+w can also, but Ctrl+w the shortcut key for Chrome to turn off the tab in Chrome, so you can practice it in IE or other browsers, except for the : New command, The various methods listed below can also open a new window in command mode or Normal mode:

    • Command-line mode enter :sp 1.txt open new Landscape window to edit 1.txt
    • Command-line mode :vsp 2.txt to open a new vertical window to edit 1.txt
    • Ctrl-w ssplit the current window into two horizontal windows in normal mode
    • Ctrl-w vsplit the current window into two vertical windows in normal mode
    • In normal mode Ctrl-w q , it is: Q ends the split window. If you have input in a new window, you need to use the mandatory character! namely: q!
    • Ctrl-w oOpen a window in normal mode and hide all previous windows
    • Ctrl-w jmove to the following window in normal mode
    • Ctrl-w kmove to the upper window in normal mode
    • Ctrl-w hmove to the left window in normal mode
    • Ctrl-w lmove to the right window in normal mode
    • Ctrl-w Jmove the current window below in normal mode
    • Ctrl-w Kmove the current window to the top in normal mode
    • Ctrl-w Hmove the current window to the left in normal mode
    • Ctrl-w Lmove the current window to the right in normal mode
    • Ctrl-w -reduce the height of the window in normal mode
    • Ctrl-w +increase the height of the window in normal mode
2. Windows Operation exercises

Open the practice file

$ vim 1.txt
    • command-line mode input :new open a new vim window
    • Command-line mode enter :sp 2.txt open new Landscape window to edit 2.txt
    • Command-line mode enter :vsp 3.txt open new Landscape window to edit 3.txt
    • If you use a non-Chrome browser, you can use Ctrl+w the jump between windows
    • Enter :q! exit multi-window editing in command-line mode of different windows

Iv. document Encryption 1. Create an encrypted document
$ vim -x file1

Enter your password to confirm the password so that the next time you open, VIM will ask you to enter the password

V. Executing external commands in vim

Enter command-line mode ! to execute external shell commands

    • :!lsUsed to display the contents of the current directory
    • :!rm FILENAMEUsed to delete a file named filename
    • :w FILENAMESave the file you are editing in the current VIM as a filename file
Vi. viewing Help in the Help system 1.vim
    • Press F1 vim to open your own preset help document in normal mode
    • Enter :h shiftwidth shiftwidth The open Help file in command line mode
    • Input :ver display version and parameters in command line mode
Seven, function set 1.vim function setting

Can be set when editing the file function settings, such as the command line mode input :set nu (display number of lines), set value exit Vim will not be saved. To permanently save the configuration, you need to modify the Vim configuration file. Vim configuration file ~/.vimrc , you can open the file for modification, but be careful not to affect the normal use of vim

2. Get the current settings
    • Enter :set or :se display all modified configurations in command line mode
    • command-line mode input :set all displays all the SetPoint values
    • Command-line mode :set option? to enter a setting value that displays option
    • Command line mode to enter the :set nooption cancel current set value
Description of the 3.set function
    • :set autoindent(ai)automatic indentation of input settings in command line mode
    • Command line mode input :set autowrite(aw) set AutoArchive, default not open
    • Enter or in command line :set background=dark mode light , set the background style
    • Command line mode input :set backup(bk) set automatic backup, default not open
    • Command line mode input : set cindent(cin) set C language style indent

"Summary" through the four chapters of the simple learning, I probably understand the basic operation and use of VIM, vim powerful can abandon the mouse to do all the operation, proficiency in a variety of commands can greatly improve work efficiency.

However, the corresponding, Vim is more difficult to get started, need a lot of practice to adapt.

VIM-related commands are documented separately

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.