vim editor to use reprint

Disclaimer: This blog is reproduced in https://www.cnblogs.com/libaoliang/articles/6961676.html learning for personal use

 

vi editor is all Unix and Linux standard editor in the system, he is equivalent to windows Notepad system, as its latest powerful not inferior to any text editor. He is our use Linux systems indispensable tool. Because of the Unix and linux any version of the system, vi editor is exactly the same, after learning it, you will be unimpeded in the Linux world.

vim has the ability to program editing, font color discrimination may grammatical correctness, easy programming;

vim can be used as an upgraded version of vi, he can use a variety of colors way to show some special information.

vim syntax will automatically determines the execution of the program according to the file type extension, or at the beginning of the information in the file, determining contents of the file, and then to display the color information of the program code in general.

vim it added a lot of extra features, such as support for regular expression search, multi-file editor, block copy and so on. This is a great feature for when we modify some configuration files work on Linux.

What 1.vi/vim that?  

  ① vi is the abbreviation for Visual Interface, you can visualize the interface

  ②vim is vi iMprove acronym, that is an enhanced version of vi (with syntax coloring)

2.vim mode What? How to switch?

  ① three modes

   Command Mode (default): When just entering vim, the default is the command mode, you can copy the lines, delete rows and so on. 
   Input Mode: You can enter content. 
   Line mode: In most below, in addition to editing mode, you can enter many administrative commands

  ② mode switch

Copy the code
   → command mode input mode: 
     I: in front of the current cursor character input mode into 
     I: current cursor line into an input line of the first mode 
     a: after the current cursor character input mode into 
     A: in the end of the line the cursor is located, into an input mode 
     o: below the current cursor line, the new line, and into the input pattern 
     O: the line above the current cursor, the new line, and into the input mode 
     s: cursor to delete characters 
     r: replace the cursor at the character input mode → command mode 
     ESC key command line mode mode → 
     enter: line mode can be turned
   
   
  Line mode - Operation
  Line mode command mode → 
     ESC key    
Copy the code

3. How to use vim to open the file?

  Vim ① / path / to / somefile: vim followed by the file path and file name, if the file exists, open the Edit File window, if the file does not exist, create a file

      [root@libaoliang ~]# vim /etc/inittab  

   ② vim + #: Open the file and locate the first row #, # stands for Digital

     [root@libaoliang ~]# vim +3 /etc/inittab  

   

  ③ vim +: open the file, locate the last line

      [root@libaoliang ~]# vim + /etc/inittab  

  ④ vim + / PATTERN: open the file, locate the first match PATTERN to be the first line of the line

     [root@libaoliang ~]# vim +/start /etc/inittab 

    

 4. Close the file

  The last line mode: 

   w: Save 
   q: quit 
   wq or x: save and exit, wq save and exit, and x is 
   q! : Force Quit 
   w! : Force Save, administrators have permission

  In command mode:

   ZZ: Save and Exit

5. Move the cursor
  command mode:

Copy the code
   ① moving character by character 
     h: left 
     l: Right 
     j: Down 
     k: up 
     #h: # characters move 
   ② moved in units of the word 
     w: to the next word of the first word 
     e: skip to the next or current word endings 
     b: Skip the current or previous word word first 
     #w: indicates that the mobile # words 
   within the line ③ Jump 
     0: absolute first line 
     ^: the first line of the first non-blank character 
     $: the absolute end of the line 
   between ④ line Jump 
     #G: Jump to the first line # 
     G: the last line
Copy the code

  The last line mode:

   ① line between jump 
      directly to the input line number Enter

6. scroll :

  Command mode 
    Ctrl + f: turn down one screen 
    Ctrl + b: turn up one screen 

    Ctrl + d: turning down half screen 
    Ctrl + u: turned up half screen 

7. Delete

  Command mode

Copy the code
    ① To delete a single character: 
      X: delete a single character at the cursor 
      #x: Remove the cursor backward and total # characters 
    ② delete command: D 
      D command combination with a jump command, such as: dw represents the position of the cursor to delete the The first word a word all the characters 
      # dw, # de, # db : #dw means to delete the current cursor position and at the back of the # words to all the characters in the first word 
      dd: delete the current cursor line 
      #dd: delete the row containing the current cursor the line #
Copy the code

  The last line mode:

 
 
  Location sign
 
 
Line mode, the delete command d may be combined with the above position of the symbol used   
     StartADD, EndADDd: Delete all rows to EndADDd StartADD position, for example: 10,15d: Remove all the contents 10 to 15 rows 
     .d: Delete cursor line, with dd

8. Paste command: p

  p (lowercase p): If the deleted or copied to the entire line , is pasted to the cursor line of the bottom , if the content copy or delete is a non-integer line is attached to the cursor characters of the rear 
  P (uppercase P) : If you delete or copy of the entire line , then paste it into the cursor line of the above , if the content is copied or deleted non-integer row , then paste the cursor to the character of the front

9. Copy Command: y

Copy the code
 Use the same d Command  
  Command mode
    yy: copy current line
    yw (y # w, ye, y # e, yb, y # b): Copy the current cursor position to the first contents word word # represents the number.
    Y # G: Replication when all the contents of the current position at rows #

  line mode
    StartADD, EndADDy: copy StartADD EndADDd all rows to position, for example: 10,15d: copy all the contents 10 to 15 rows
    + 3Y
: copy the current position to the lower row 3
Copy the code

10. Modify c: to delete the contents, converting the input mode

   c: Use with d

11. Replace: r

  r: single character replacement, replace the cursor to select the character 
  R: replace mode, the character can be replaced.

12. Undo editing operation: u (undo) 

  u: before you undo the last editing operation 
  #u: immediate withdrawal of # actions 
  Ctrl + r: Undo the last undo

13. Repeat once before the editing operation.

  .: For example, the last time dd delete a row, you can now enter repeat dd Deletion of the row.

 

14. visualization modes:
  

  Command Mode: 
    V: according to the selected character, the keyboard control the cursor across the region is selected     V: Select a rectangular, row control keyboard is a cursor across selected

15 . Finding :

  

  Line mode: 
    / the PATTERN: search backwards from the current position     ? PATTERN: Find forwardly from the current position     n: Find downwardly     N: up to find

16. Find and Replace

  S used in the command line mode 
    ADDR1, ADDR2 s / the PATTERN / String / GI 
    ADDR1, ADDR2 represents address; example 1, $ represents text ( % said full text) 
    G: replace a global- 
    i: represents ignore case

 17.vim open multiple files

Copy the code
vim FILE1 FILE2 FILE3 
 line mode   : next switched to the next file   : prev switch to a file   : last switch to the last file   : first switch to the first file
exit multiple files
  qa: All exit
Copy the code

18. The split-screen display a file

Copy the code
vim file open 
  Ctrl + w, s: a horizontal split window   Ctrl + w, v: window split vertically move the cursor between windows Ctrl + w, ARROW    such as Ctrl + w, → :( using arrow keys) to switch the cursor the right side of the window   , such as Ctrl + w, h (left), j (lower), k (a), l (R) window may be switched in the line mode : qa exit all windows

Copy the code

19. The sub-window editing multiple files

vim -o: horizontal division display 
vim -O: vertically divided display 
example: vim -o /etc/rc.sysinit / etc / inittab : /etc/rc.sysinit horizontal division display and / etc / inittab these two files

20. Save the current file to another part of a document

Line mode 
    w: represents save the current file 
    w / path / to / somewhere: Save the current file to the path specified for the local 
    ADDR1, ADDR2 w / path / to / Somewhere: ADDR1 to the specified address ADDR2 to save as text path designated place

21. The contents of another file to fill in the current file (r for read)

Line mode 
   r: / path / to / somefile 
example: vim /etc/rc.sysinit file open, line mode input: r / etc / inittab: All the contents of the file will be attached to the inittab file cursor rc.sysinit location of

22. (execute shell vim line mode) with interactive shell

Line mode 
command can! 
For example:! Ls / etc /: lists all files and directories under the / ect directory press enter edit mode back to vim

23. Advanced Topics

Copy the code
In line mode 
① display or cancel the line number 
        set nu (set number): display line numbers 
        set nonu: Cancel display line numbers ② display ignored or sensitive characters 
        set ic (set ignorecase): Ignore case 
        set noignorecase: distinction the case ③ set up automatic indentation 
       set ai (set autoindent): automatic indentation 
        set noai: cancel automatic indentation ④ found text highlighting or cancel the highlight 
    set hlsearch: highlight the searched text 
    set nohlsearch: cancel highlight searched text ⑤ syntax highlighting 
    syntax on: open the syntax highlighting 
    syntax off: turn off syntax highlighting



Copy the code

24.vim profile

Global vim configuration file: / etc / vimrc 
personal vim configuration file: ~ / .vimrc 
[root @ libaoliang ~] # echo "the SET NU" >> /root/.vimrc # root user to open a file with vim, display line numbers.

Guess you like

Origin www.cnblogs.com/azxh/p/12557513.html