"Go" vi/vim common commands

Source: Internet
Author: User
Tags first string

Original URL: http://www.blogjava.net/woxingwosu/archive/2007/09/06/125193.html


VI is the abbreviation of "Visual interface", its status on Linux as if the edit program on DOS. It can perform many text operations, such as output, delete, find, replace, block operations, and so on, and users can customize them according to their own needs, which is not available in other editing programs.

VI is not a typesetting program, it is not like word or WPS can be the font, format, paragraph and other properties of the orchestration, it is just a text editing program.

VI There are no menus, only commands, and commands are numerous. VI has three basic modes of operation: command line mode, text input mode, and last line mode.

Command-line mode (commands mode/general mode)
At any time, no matter what mode the user is in, just press the key to make VI into the command line mode; We enter the Launch VI command under the shell environment (prompt $), and it is in that mode when you enter the editor.
In this mode, users can enter a variety of legal VI commands for managing their own documents. Any character entered from the keyboard is interpreted as an edit command, and if the input character is a valid VI command, VI completes the corresponding action after accepting the user command. Note, however, that the commands you enter are not displayed on the screen. If the input character is not a legal command of VI, VI will ring the alarm.

Text input mode (input mode/edit mode)
Enter the input command in command mode i, attach command A, open command O, modify command C, replace command R or Replace command s can enter the text input mode. In this mode, any characters entered by the user are saved by VI as the contents of the file and displayed on the screen. In the process of text input, if you want to return to the command mode, press the button.

Final line mode (last lines mode/command mode)
The last line mode is also known as ex escape mode.
The functions of the VI and ex editors are the same, the main difference being the user interface. In VI, commands are usually a single key, such as I, A, O, etc., whereas in ex, the command is the body line that ends with a hit return. VI has a dedicated "escape" command to access many of the line-oriented ex commands. In command mode, the user presses the ":" Key to enter the last row mode, at which time VI displays a ":" As a prompt in the final row of the display window (usually the last line of the screen), waiting for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the edit buffer to a file medium). After the last command is executed, VI automatically returns to the command mode.


I. Commands that go from general mode to input mode
1〉 Cursor Move command

0 move to the front of the column where the cursor is located [Home]
$ move to the last face of the column where the cursor is located [End]
[CTRL] [d] Half PAGE Down
[CTRL] [f] Page down [PageDown]
[CTRL] [u] up half page
[CTRL] [b] up one page [PageUp]
H moves to the first column of the window
M moves to the middle column of the window
L move to the last column of the window
G Move to the last column of the file
Ng is moved directly to Nth row (equivalent to command ": N") with the number n plus the uppercase G
FX moves right to the X character
TX moves to the right before the X character
Shift +g jumps to the end of the file (equivalent to G)
GG Jump to file header
XP Exchange two character positions
DDP up and down two lines swap
[Move to file start location
] to move to the end of the file
NK moves up n rows
n↑ N rows up
N-N-line, cursor at the beginning of the line
NI moves down n rows
n+ N-line, cursor at the beginning of the line
N↓ Moving down n rows
W move forward one word
NW Move N Word forward
→ Move one character "L" to the right
← Move left one character "H"
↑ Move up one line "K"
↓ Move Down one line "J"


2〉 Delete Operation command

X Delete the character "delete" where the cursor is located
DW Delete the word where the cursor is located
D $ removes all characters from the cursor to the end of the line
/d with/d $
DD Delete When moving forward
DND Delete current n rows
DG deletes the current line to the last row
You can add a number before the delete command, such as <5x to delete 5 rows.


3〉 Change and replace operation commands

R replaces the character that the cursor contains
/RR replacing character sequences
C $ replaces all characters from the cursor position to the end of the line
CL modifies the current character
CC changes when moving forward
C $ Changes to end of line content
:%s#abc#123#g replaces all ABC in the text with 123
DDP up and down two lines of exchange (actually first DD, then execute p)


4〉 Query command

/string forward search string "support regular"
N Find Next
? string searches backwards for string
/+ up and down arrows search history
: + Up/down arrows: History of commands
* Look ahead to the current word, provided the cursor moves to the word you are looking for
# Look back at the current word, provided the cursor moves to the word you are looking for
/\<word\> matches only word, does not match wordstr, and so on
% looks for matching parentheses, provided the cursor is on one side of the parenthesis
FX moves to the next character X in the current line


5〉 Copy and Paste commands

YW copy the word from the cursor into the Clipboard
y$ Copy the character of the cursor to the end of the line into the Clipboard
Y with
YY Copy the current line into the Clipboard
Yny Copy the current n rows into the Clipboard
P Pastes the contents of the Clipboard after the cursor
P Pastes the contents of the Clipboard in front of the cursor


6〉 file Edit, save and Exit VI command

: Q Do not save exit
: q! Do not save mandatory exits
: W Save Edit
: w filename is saved in file filename
: w! FileName Mandatory deposit file in filename
: Wq/: X/zz Save exit
: wq! Force Save and exit


7〉 Other Commands

: args Displays the current file name
U undo, equivalent to Ctrl + Z
U undo all operations on one line at a time
Ctrl+r Redo
: Help View all assistance
: Help 0 View about 0
ZZ exit Help, back to edit mode
Ctrl+g know if the file name modifies the percentage of rows before the current first row
Ctrl + V Select a block
: Set number Displays line numbers
: Set Nonumber does not display line numbers
: Set rule shows cursor position
: Set ignorecase search is case insensitive
: Set Noignorecase search case sensitive
: AB string hint (for example: AB ABC abcdefg, when input ABC and then enter a space, ABC automatically becomes ABCDEFG)
: New filename Opens or creates a new file, or creates a new file if you do not specify a file name or the file name does not exist.
: Set ruler to open the cursor's row and column position display function
: Set shiftwidth=4 Sets the number of automatically indented cells
: Set Autoindent to turn on auto Indent function
: Set paste to close auto indent when pasting
: Set Nopaste to open Auto indent when pasting


Iii. order to enter VI

VI FileName: Opens or creates a new file and places the cursor at the beginning of the first
VI +n FileName: Opens the file and places the cursor at the beginning of nth
VI + FileName: Opens the file and places the cursor at the beginning of the last line
VI +/pattern FileName: Opens the file and places the cursor at the first string that matches the pattern
Vi-r FileName: The last time you were editing with VI, a system crash occurred, restoring filename
VI filename.filename: Open multiple files, edit them sequentially
VI +/word filename: Enter VI and start with Word of the file


Note: Ctrl+s in Linux is to stop the display terminal output, this time the screen is like fixed, the terminal will not continue to output, will not respond to your input, you need to click Ctrl-q to restore input.

The command is mostly, or read the document.

"Go" vi/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.