Linux file editing commands commonly used commands of vim

 

vi command

vi command is the UNIX operating system and UNIX-like operating system, the most common full-screen plain text editor. Linux in the vi editor called vim, which is an enhanced version of vi (vi Improved), fully compatible with the vi editor, but also achieved a lot of enhancements.

vi editor supports editing mode and command mode, you can complete editing text edit mode, you can complete the operation command file command mode, use the vi editor to correct you must be familiar with the switch between the two modes. By default, automatically enter the command mode after opening the vi editor. Switching from the command mode to the edit mode using the "esc" key to switch from the command mode to the edit mode using the "A", "a", "O", "o", "I", "i" key.

vi editor provides a wealth of built-in commands, and some built-in commands using keyboard combinations to complete, and some built-in commands you need a colon ":" at the beginning input. Common built-in command as follows:

Ctrl + u: first turned to the document half screen; 
ctrl + D: Total half screen to the end of the file; 
ctrl + F: turning a screen to the end of the file; 
ctrl + B: the beginning of the file down one screen; 
the Esc: switching from the edit mode to command mode; 
ZZ: command mode to save the current exit vi after modification made to the file; 
: line number: the cursor jumps to the beginning of the specified row; 
: $: the cursor jumps to the beginning of the last line; 
the X-X or : after deleting a character, x deleted cursor, and X is deleted before the cursor; 
D: remove all the entries from the cursor end of the line the cursor to; dd : delete the cursor line is the line content; 
NDD: delete the current row and the n -1 line; 
NYY: save the contents of the current line and the next n rows to the register? , Where? A letter, a n-digit; 
P: Pasting text, for pasting the contents of the cache to below the current cursor position; 
P: Pasting text, for pasting the contents of the buffer to the current cursor location above; 
/ string: text search operation for starting from the current cursor position to find the contents of the specified string end of the file, the search string will be highlighted; 
? name: text search operation, for starting to find the contents of the specified file from the head of the string at the current cursor position, the search string will be highlighted; 
A, BS / F. / T: Text replacement operation, for a second line between the second line b, the string will be replaced by F T string. Wherein, "s /" represents a replacement operation; 
A: add text after the current character; 
A: Add the end of the text line; 
I: Insert text before the current character; 
the I: The first line of text is inserted;

o: Insert after the current line by a blank line; 
O: inserted in front of the current line by a blank line; 
: WQ: in command mode, perform save and exit operation; 
: W : in command mode, perform save operation; 
: W! : In the command mode, the forced save operation; 
: Q: In the command mode, perform operations from the vi; 
: Q! : In the command mode, the forced exit vi operation; 
: E filename: in command mode, open and edit the file with the specified name; 
: n-: in command mode, if the open multiple files simultaneously, continue editing the next file; 
: F: in the command mode, displays the current file name, line number and the line where the cursor display scale; 
: SET number: in command mode for displaying the line number at the left end; 
: SET nonumber: in the command mode, for the leftmost line numbers are not displayed;

grammar

vi (options) (parameters)

Options

+ <Line number>: Start from the first line of text contents of the specified line number; 
-b: binary mode document for editing binary files and executable files; 
-C <command>: Upon completion of the editing of a document after the task execution instruction is given; 
-d: in diff open the schema file, when a plurality of file editing, file differential display portion; 
-l: use lisp mode, open "lisp" and "showmatch when"; 
-m: cancel write file function, Reset " write " option; 
-M: Close editing; 
-n: not practical cache function; 
-o <file number>: Specifies the number of open files simultaneously specified; 
-R & lt: Read-only files ; 
-s: silent mode, unrealistic instructions any error messages.

parameter

File list: Specifies a list of files to be edited. Use spaces between multiple files separated.

Knowledge extension

vi editor has three operating modes: command mode, input and ex escape mode. Or by a corresponding operation command, between these three operating modes can be switched.

Command mode

After the command prompt, type vi Shell, placed in vi, vi and in the command mode. At this time, any input from the keyboard characters are interpreted as edit command, for example, a (append) indicates additional command, i (insert) indicates insertion command, x represents a command to delete characters and the like. If a character is not a legal vi command, the machine issued a "sound the alarm", the cursor does not move. Further, the characters (i.e., command vi) entered in the command mode is not displayed on the screen, for example, input i, no change on the screen, by executing the command i, editor works has changed: the command mode becomes the input mode.

Input

By inserting the command input vi (i), additional commands (a), a command to open (o), the Replace command (s), to modify the command (c) or instead of the command (r) may enter command mode from input mode. In the input mode, all characters entered from the keyboard are being inserted into the edit buffer, it is treated as the body of the document. After entering the input mode, enter the visible characters are displayed on the screen while editing commands no longer function, it appears only as an ordinary letter. For example, enter the command mode in the letters i, into the input mode, then the input i, a letter i is added corresponding cursor on the screen.

By the way back to command mode input way is to press the Esc key. If the command mode, then press the Esc key will issue a "beep". In order to ensure vi command you want to execute is entered in command mode, it may be more than a few Esc key, enter the command to hear the beep again.

ex escape mode

vi and ex editor function is the same, the main difference between the two user interface. In vi, usually command a single letter, such as a, x, r the like. In the ex, the command is Enter; key to the end of the command line. vi has a special "escape" command, can access a lot of ex command line-oriented. Using ex escape mode, enter a colon (:). As ex command prompt, a colon appears in the status line (generally the lowest row of the screen). Press the interrupt key (usually Del key), to terminate the command is doing. Most file management commands are executed in ex escape mode (for example, to read the file, the contents of the edit buffer is written to the medium-file). After the escape command, automatically return to command mode. E.g:

: 1, $ s / I / i / g Press Enter

File from the first row to the end of file ($) I replace all uppercase to lowercase i. Conversion between the three modes vi editor shown in FIG.

we

 

 

 

 

 

 

 

 

 

 

 

 

skills:

 

 

Guess you like

Origin www.cnblogs.com/wuwuyong/p/11839421.html