linux basic commands to use vi Details

using the method described in detail vi

vi editor is a standard editor for Unix and Linux systems all, it is not inferior to any of the powerful new text editor, here is a brief introduction about its use and a small part of the instruction. Since any version of Unix and Linux systems, the vi editor is exactly the same, so you can learn more about it in any other place of introduction vi. Vi is the most basic Linux text editor, after learning it, you will be unimpeded in the Linux world. 

1, the basic concept of vi 
  substantially vi can be divided into three states, namely, command mode (command mode), insert mode (Insert mode) and line mode (last line mode), to distinguish between functions of each mode is as follows: 
    1) command line mode command mode) 
  move the screen cursor control, to delete a character, word, or row, and move into the lower section of a copying Insert mode, or to the last line mode. 
    2) insert mode (Insert mode) 
  only in Insert mode, it can be done entering text, press the "ESC" key to return to the command line mode. 
    3) line mode (last line mode) 
  to save the file or exit vi, you can also set the editing environment, such as finding strings, lists the line number and so on ....... 

But generally we use the simplified two modes vi, is the bottom line mode (last line mode) can be considered the command line mode command mode). 
2, vi basic operation 
a) enter vi 
    after the system prompt type vi and the file name, then enter the vi full-screen editing screen:
   $ vi myfile 
  But one thing is important to note that after you have entered vi, it is in the "Command Line mode (command mode), "you want to switch to" insert mode (insert mode) "to be able to enter text. Vi initial use of people will want to use the cursor keys to move around, the result has been the computer beep call, put their gas half to death, so after entering vi, the first not to tamper with, converted to "insert mode (Insert mode)" then we'll talk ! 

b) switch to insert mode (Insert mode) to edit the file 
  in the "command line mode (command mode)" click on the letter "i" can enter "insert mode (Insert mode)", this time you can start typing the . 

c) Insert the switch 
  You are now in "insert mode (Insert mode)", you'll only have to enter text, if you find the wrong word! Want to move back with the cursor keys, delete the word, you must first click the "ESC" key to go to "command-line mode (command mode)" and then delete the text. 


d) exit vi and save the file 
  under "command line mode (command mode)," click ":" colon to enter the "Last line mode", for example: 
: w filename (enter "w filename" the article to the specified file save name filename) 
: wq (enter "wq", save and exit vi) 
:! q (input q !, force quit without saving vi) 

3, command line mode (command mode) function keys 
. 1) insert mode 
       press the "i "switch into insert mode" insert mode ", press" i "into the insert mode is the beginning of the input file from the current cursor position; 
  press" a "to enter the insert mode, is from a position of the current cursor position start typing; 
  press "o" into insert mode, inserting a new line, enter the text from the beginning of the line. 
2). Insert mode is switched from the command line mode 
      press "ESC" key. 
3) Move the cursor 
  vi can be directly with the cursor on the keyboard to move around, but the formal vi is the "h" in lower case letters, "j", "k", "l", respectively, to control the cursor left, down, on the right a grid. 
  Press "ctrl" + "b": "After" screen to the mobile page. 
  Press "ctrl" + "f": the screen to move "forward" page. 
  Press "ctrl" + "u": screen to move "backward" half a page. 
  Press "ctrl" + "d": the screen to move "forward" half page. 
  Press the number "0": move to the beginning of the article. 
  Press the "G": Move to the end of the article. 
  Press the "$": Move to the "end of line" cursor line. 
  Press the "^": "first line" to move the cursor line 
  by "w": the cursor jumps to the beginning of the next word 
  by "e": the cursor jumps to the next word suffix 
  by "b": the cursor returns at the beginning of the word 
  by "#l": # cursor to the first position of the line, such as: 5l, 56l. 
4) delete the word 
  "x": every time you press Delete "behind" a character at the cursor position. 
  "#X": for example, "6x" means to delete the cursor position "behind" the six characters. 
  "X": uppercase X, every time you press Delete "in front of" a character at the cursor position. 
  "#X": for example, "20X" indicates the position of the cursor to delete the "front" of 20 characters. 
  "Dd": Delete cursor line. 
  "#Dd": # delete rows from the beginning of the line where the cursor 
5) copy. 
  "Yw": the suffix characters to copy into the buffer at the cursor. 
  "#Yw": # copy words to the buffer 
  "yy": Copy the line where the cursor into the buffer. 
  "#Yy": for example, "6yy" said the bank copy from the cursor "down the number" 6 lines of text. 
  "P": the characters in the buffer attached to the cursor position. Note: All the "y" copy command must be related to the "p" to complete with copy and paste functions. 
6). 

  "R": Replace character cursor wherever he went, and until you press the "ESC" key so far. 
7) return the last operation 
  "u": If you mistakenly execute a command, you can immediately press the "u", return to the previous operation. Press repeatedly "u" can perform multiple responses. 

8) Change the 
  "cw": Change the word at the cursor to the suffix of the 
  "c # w": for example, "c3w" means to change the three words 
9) to jump to the specified line. 
  "Ctrl" + "g" row the line number where the cursor line. 
  "#G": for example, "15G" indicates to move the cursor to the article 15 of the first trekking. 


4, Last line mode command Introduction 
  Before using the "last line mode", please remember to press the "ESC" key to confirm you are already in the next "command mode", press ":" colon can enter the "last line mode . " 

A) lists the line number 
 "set nu": Enter "set nu", will be in front of each line in the file lists the line number. 
B) jump to a line in the file 
 "#": "#" sign indicates a number, enter a number after the colon, press the Enter key will jump to the line, such as digital input 15, then Enter, it will jump to the article line 15. 
C) Find the character 
 "/ Keyword": press "/" key, then enter the characters you want to find, if not the first to find the keywords you want, you can always press the "n" will be looking to future Until the keywords you want. 
 "? Keywords": "?" Press the button, and then enter the characters you want to find, if not the first to find the keywords you want, you can always press the "n" will be looking forward to the key you want Until word. 
D) Save the file 
 "w": enter the letter "w" in the colon can be saved file. 
E) vi leave 
 "q": Press the "q" is to quit, if you can not leave vi, may be in a "q" followed forced to leave vi "!." 
 "Qw": generally recommended to leave, with the "w" used together, so that when the exit can also save the file. 

5, vi command list

1, the following are some of the keys in the command mode function 
h represents a left cursor character 
l denotes the right the cursor one character 
k represents the cursor line 
j represents a cursor by one line 
^ represents the cursor to the beginning of the line 
0 the number "0" , move the cursor to the beginning of the article 
G represents a cursor to the end of the article 
$ represents the cursor to the end of the line 
Ctrl + f scroll forward 
Ctrl + b scroll backward 
Ctrl + d flip ahead half screen 
Ctrl + u turned back half screen 
i character is inserted before the cursor position 
a cursor at a position after the character begins to increase 
o insert a new row, beginning from the first line input 
ESC retreat state from the command input state 
x delete characters after the cursor 
#x cursor deleted # of characters 
X (uppercase X) delete character before the cursor 
#X # delete characters before the cursor 
dd delete cursor line 
#dd # row number is deleted from the cursor line 
a word copy cursor position YW 
#yw copy the cursor position # word 
yy copy location of the cursor line 
#yy copied from the # line number of the cursor line 
p paste 
u cancel 
cw to change the position of the cursor one word 
#cw change # word at the cursor position 

2, the following are some of the instructions in the command mode 
w filename stored in the file being edited for the filename 
WQ filename stored in the file being edited for the filename, and exit vi 
q! Give up all changes and exit vi 
the SET NU display line numbers 
/ or? Search, in / enter're looking for 
n use the / or? together, looking for keywords if the content is not want to find, press n or backward (with / MS) or forward (with? MS) to continue to find until you find it. 

vi User's Manual

VI is the most commonly used unix text editor

to enter the command vi
vi filename: Open or create a new file, the first line and the first cursor
vi + n filename: open the file, and the n-th row first cursor
vi + filename: open the file, and the last line of the first cursor
vi + / pattern filename: open the file and places the cursor at the first string match the pattern
vi -R & lt filename: positive occurred at the last editing vi system crash recovery filename
VI filename .... filename: open multiple files, edit sequentially

move the cursor commands of
h: cursor one character
l: the cursor one character
space: the cursor one character
Backspace: cursor to the left a character
k or Ctrl + p: move cursor up one line
j or Ctrl + n: cursor down one line
Enter: cursor down one line
w or w: cursor right to a prefix word
b or B: cursor one character to the prefix
e or E: cursor right to a word suffix j
): cursor to end of the sentence
(: move the cursor to the first sentence
}: move the cursor to the beginning of paragraph
{: move the cursor to the end of the paragraph
nG: move the cursor to the n The first row
n +: cursor down n lines
n-: light Move n lines
n $: move the cursor to the end of the n-th row
H: Move the cursor to the top line
M: middle of the screen cursor to the line
L: a screen cursor to the last row
0 :( note the number zero) the cursor to the current line
$: Move the cursor to the end of the current line

of the screen roll commands of
ctrl + u: first turned to the file 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 file header down one screen
nz: the roller n-th line to the top of the screen, not when specify the n roll to the current line at the top of the screen.

Insert text type command
i: before the cursor
I: In the current line
a: after the cursor
A: A current line
o: open a new row below the current line
O: open new line above the current line
r: Replace the current character
R: replace the current character and the subsequent characters, press the ESC key until
s: starting from the current cursor position to input text alternative specified number of characters
S: delete the specified number of rows, and instead of the input text
ncw or nCW: modify the specified number of words
nCC: modify the specified number of rows

delete command
ndw or ndW: start and at the cursor is deleted word n-1
do: to delete the first row
d $: delete to end of line
ndd: delete the current and n-1 row after row
x or X: after deleting a character, deleting the cursor x, and before the cursor is deleted X
Ctrl + u: delete the text input mode input

Search and Replace command:
/ pattern: from the cursor to the beginning of the search pattern to the end of the file
pattern:? From the cursor to the beginning of the file first search pattern
the n-: repeat the last search command in the same direction
N: Repeat the last search command in the opposite direction
: s / p1 / p2 / g: all the current line p1 p2 are used alternatively
: n1, n2s / p1 / p2 / g: the first row n1 to n2 are all replaced by p1 p2
: G / p1 / S // p2 / g: all files are replaced by p2 p1

option
all: List all cases option
term: set terminal type
ignorance: ignore case in the search
list: display tab stop (Ctrl + I) and end of line sign ($)
number the: show line number
report: modify the display line-oriented command over the number of
terse: a brief warning message displayed
warn: go to another file in the current file is saved if no NO write information is displayed
nomagic: allow special characters in search mode, previously used without the "\" in
nowrapscan: ban vi in the search reaches both ends of the file, and from the other end of the beginning
mesg: allow other users to use vi show write write the information on your own terminal

last row command mode
: n1, n2 co n 3: The contents of the row between n1 n2 n3 row are copied to the first line
: n1, n2 m n3: n1 rows between the content to move to the next row of n2 n3 line
: N1, n2 d: n1 rows between the contents of the deleted row n2
: w: save the current file
: e filename: Open the file filename for editing
: x: save the current file and exit
: q: Exit VI
: Q is not !: save the file and exit vi
:! command: execute shell commands command
: n1, n2 w command:! the contents of the file to n2 n1 row line as the command input and execute, if not specified n1, n2, said the entire the contents of the file as a command input
: r command:! command of the output of the command into the current line.

 These are some basic vi command usage for subsequent read.

Guess you like

Origin www.cnblogs.com/jasonboren/p/10972364.html