Understanding the VIM Editor

Source: Internet
Author: User
Tags first string save file

Vi/vim Powerful editor

    • command 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

    • Move Cursor Class command

h : Move the cursor one character to the left

L : Move the cursor right one character

space: Move the cursor right one character

Backspace: Cursor moves left one character

k or ctrl+p: Move the cursor up one line

J or Ctrl + N : Move the cursor down one line

Enter : Move the cursor down one line

W or w : Move the cursor right one word to the beginning of the word

b or b : The cursor moves left one word to the beginning of the word

e or e : Move the cursor right one word to the end of the word

) : Move the cursor to the end of the sentence

( : The cursor moves to the beginning of the sentence

}: Move the cursor to the beginning of the paragraph

{: Cursor moves to end of paragraph

NG: Cursor moves to the beginning of nth

n+: The cursor moves down n rows

N: The cursor moves up n rows.

    • Screen Tumbling Class command

Ctrl+u The first half screen to the file
ctrl+d Half screen to file end
ctrl+f One screen to the end of the file
ctrl+b One screen to the top of the file
NZ rolls the nth row to the top of the screen, and rolls the current line to the top of the screen when n is not specified.

    • Insert Text

 i before cursor  
I at the beginning of the current line  
a after the cursor  
a
o
O    
R  
R
s
S Deletes the specified number of rows and replaces the   with the text entered;
NCW or NCW
Modify a specified number of words  
NCC modifies the specified number of rows  

number: Show line numbers
Report: Displays the number modified by the line-oriented command
Terse: Displays a short warning message
warn: Displays no write message if the current file is not saved when you go to another file
nomagic: Allows the use of special characters that are not preceded by "\" In search mode
Nowrapscan: Prohibit VI from the other end when the search reaches the end of the file
MESG: Allow VI to display information that other users write to their terminal using write

    • End Line Command

: N1,N2 Co n3 copies the contents of the N1 line to the N2 line below the N3 line
: n1,n2 m n3 moves the contents of the N1 line to the N2 line below the N3 line
: n1,n2 d Deletes the contents of N1 rows to N2 rows
: W Save current file
: E filename opens file filename for editing
: x Save current file and exit
: Q Exit VI
: q! do not save the file and Exit VI
:!command Execute shell command
: n1,n2 W!command The contents of the N1 line to the N2 line in the file as input to the command and executes it, and if you do not specify N1,N2, the entire file contents as the input of the command
: R!command The output of command commands to the current line

    • Cursor movement 

J or down ARROW to move down one line
K or up ARROW to move up one line
h or left arrow moves left one character
L or RIGHT arrow move one character to the right
W move right One word
W Move right to a space-delimited word
b Move one word to the left
B Move left a space-delimited word
0 move to the beginning of the line
ctrl-f Page forward
ctrl-b Back Page
NG to Nth row
G to last line

    • Delete text

R replaces one character
C Modify the text until you press ESC
CW modifies the next word
CNW Modify the next n words

    • Save and exit


ZZ Save and exit
: w filename        Write file
: W Write file
: x Save (if the current file has been modified) and exit
: q! Do not save file, exit directly
: Q Exit VI

    • VI Editor start and exit directly into the editing environment $ VI
    • Enter the editing environment and open (new) file $ VI myfile
    • Exit VI Edit Environment Enter the last line command to discard the changes to the file and exit the editor: q!
    • Save file Save changes to open file in VI Editor: W
    • Save as file saves the contents of the VI editor as the specified file name: W myfile
    • Exit VI Editor multiple methods not modified exit does not modify the file opened in the VI editor, or has saved the changes, exit the VI editor directly: Q
    • Save the file in the VI Editor and exit the VI editor: WQ
    • Do not save quit discard changes to the contents of the file and exit the VI editor: q!

Move the cursor and turn the page action H move the cursor to the left L move the cursor k up move the cursor J down move the cursor CTRL + F forward full page Ctrl + B back full page Ctrl + U forward Half page Ctrl + D turn half page backward

    • Quick jump in line ^ move the cursor quickly to the beginning of the line character $ move the cursor quickly to the end of the bank character W move the cursor quickly to the first letter B of the last word in the position of the current cursor quickly jumps to the first letter of the previous word at the current cursor position E quickly jumps the cursor to the end of the last word in the position of the current cursor quick jump between insiders
    • Command function: Set NU display line number in editor: Set Nonu suppress line number in editor 1G jumps to the first line of the file G jumps to the end of the file #G跳转到文件中的第 # line
    • Enter input mode I at the current cursor into insert state A after the current cursor into the insertion state A will move the cursor to the end of the current line, and into the insertion state o insert a new row below the current line, the cursor moves to the beginning of the new line, into the insertion state o insert a new row above the current line, the cursor moves to the beginning Into the Insert State CW deletes the current cursor to the end of the word, and enters the insertion state C $ Deletes the current cursor to the ending of the line and enters the Insert state c^ command deletes the character from the beginning of the current cursor (excluding the character on the cursor) to the start of the insertion state
    • Input mode of the edit key operation direction key to the left and right direction of the cursor move home quick positioning cursor to the beginning of the line end quick position cursor to the end of PageUp text page up pagedown text PAGE DOWN backspace delete the character to the left of the cursor Del Delete character at cursor position
    • Delete action x Remove the single character at the cursor at the DD delete cursor row DW Delete all characters of the current character to the end of the word (including spaces) de removes all characters from the current character to the end of the word (not including the trailing spaces of the word) d$ Delete all characters from the current character to the end of the line d^ delete all characters from the current J Delete line breaks at the end of the line at which the cursor is located, equivalent to merging the contents of the current and the next line

Replace operation

    • : S/old/new replaces the first character "old" string found in the current row with "new"
    • : S/old/new/g replaces all the string "old" found in the current row with "new"
    • : #, #s/old/new/g Replace all strings "old" with "new" in the line number "#,#" range
    • :%s/old/new/g replaces all strings "old" with "new" in the entire file range
    • : s/old/new/c the C command at the end of the Replace command, prompting the user to confirm each substitution action

Undo Action

      • U cancels the last operation and restores the result of the operation
      • You can use the U command multiple times to recover a multi-step operation
      • U cancels all operations on the current line
      • Ctrl + R Restores operations that use the U command to undo

Copy and paste operations

      • YY copies the contents of the entire row of the current line to the VI buffer
      • YW Copy the contents of the current cursor to the end of the word to the VI buffer
      • y$ Copy the contents of the current cursor to the end of the line to the VI buffer
      • y^ Copy the contents of the current cursor to the beginning of the line to the VI buffer
      • P reads the contents of the vi buffer and pastes it to the current position of the cursor (without overwriting the contents of the file)

String Lookup Operations

      • /word from top to bottom in file find string "word"
      • Word bottom finds the string "word" in a file
      • N locates the next matching found string
      • N locates the previous matched lookup string

Understanding the VIM Editor

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.