Don't say you don't know it/a minute to bring you to know Vim's past life

Source: Internet
Author: User

In some questions about the text editor, I will mention that vim in the text editor is no editor can be out of its right, including Vim's old enemy Emacs, in this regard can not look at vim nape.
  
Ago
  
World
  

After these days of study, you should know that Linux is a text file dealing with the system, then how to deal with such a system? We have to learn how to create new files, delete files, modify files, and so on, so you need a text editing tool to do these things. And the most popular text editing tool in Linux is vi/vim; This article will give you a detailed account of how to use the Vi/vim text editor under the Linux operating system, a minute to understand Vi/vim's past life.
  
 The first thing we need to know is what is Vi/vim?


  
  Dielectric
  
Shaoxing

  
The VI Editor is the most basic text editor on Linux and Unix, working in character mode. Because no graphical interface is required, VI is a highly efficient text editor. Although there are many graphical interface editors available on Linux, the functions of VI in System and server management are unmatched by the graphical editors.
  
The VI Editor can perform many text operations, such as output, delete, find, replace, block operations, and so on, and users can customize them according to their needs, which is not available in other editing programs.
  
Vim is a text editor developed from VI. Code completion, compilation and error jumps and other convenient programming features are particularly rich, in the programmer is widely used.
  
  Special
  
Point

  
For VIM already has the basic understanding of you, certainly also wants to know its characteristic! It has three features that the public can understand!
  
Vi/vim is a plain text editor, it is not like Word can be typeset, you can adjust the font size, you can change the font
  
Vi/vim is just a text editing tool that can only manipulate the contents of text
  
VI is a full-screen text editor that will occupy the entire screen when editing text
  
Although it is not possible to adjust the font and size as Word documents do, the advantage is obvious.
  
1. Full keyboard operation, shortcut key combination, so that the efficiency greatly improved
  
2. Quick Start, light and fast
  
3. More expansion, sufficient enough
  
  There are three modes in the Linux vi/vim Text Editor: Command mode, input mode and last line mode. What is the difference between the three models?

  

  Mode
  
Expression

  
Command mode: is the default mode after the Vi/vim editor enters, for example, if you want to edit the file, then you need to enter "I" to make the current mode into insert mode or input mode, so you can edit the text. You can also let users execute commands, such as copying rows and pasting rows.
  
Input mode: As the name implies is to do the input of this article operation, that is, you can make changes to the file operation.
  
Last-line mode: Used to find text, save changes.
  
One of the things we need to focus on is the transition pattern between them, which is not easy
  
Command mode--input mode---Command mode
  
Command mode----last-line mode--command mode
  
Command mode--input mode
  
I:insert, in front of the character at which the cursor is currently positioned, into input mode
  
I: Uppercase I, converted to input mode at the beginning of the line where the current cursor is located
  
A:append, converted to input mode after the current cursor character
  
A: The end of the line at the current cursor is converted to input mode
  
O:open, creates a new row below the current cursor line and shifts to input mode
  
o: Uppercase O, not number 0, creates a new row above the current cursor line and converts to input mode
  
Input mode---Command mode
  
Esc
  
Command mode----Last-line mode
  
:
  
Last-line mode--command mode
  
ESC ESC

  

  
Now that we have a look at some of its big patterns and three features, we're going to start working on it! Text editing in a posture that is opened correctly do you have get? (Multi-MAP WARNING!!!) )
  
Open File Mode: The file is opened by default in command mode
  
Vim filename//Open File
  
Vim +n filename//Open File and navigate to Nth row
  
Vim +/pattern filename//Open the file and navigate to the beginning of the first match to the content of the/pattern
  
   Close File mode: Close file in last line
  
Command > meaning
  
q> exit wq> Save and exit
  
Q! > do not save exit w> save but do not exit
  
W! > forcibly save wq!> forcibly save and exit
  
x> forcibly save and exit
  
Command mode close file: ZZ
  
Move cursor
  
   Character-by- word movement
  
H: Move one character to the left
  
L: Move one character to the right
  
J: Move down one character
  
K: Move up one character
  
#h: Move the # characters to the left
  
#l: Move the # characters to the right
  
#j: Move the # characters down
  
#k: Move the # characters up
  
  move in a word unit
  
W: Move to the beginning of the next word
  
E: Jumps to the ending of the current or next word
  
B: Jump to the beginning of the current or previous word
  
#w: Jumps to the beginning of the first # Word with the current cursor as a starting point
  
#e: Jumps to the ending of the first # Word with the current cursor as a starting point
  
#b: Jumps to the beginning of the first # Word with the current cursor as a starting point
  
   in-line jump
  
0: Number 0, jump to absolute beginning
  
: Jumps to the first non-whitespace character at the beginning of a line
  
$: Jump to absolute end of line
  
   Inline Jump
  
GG: Jump to the first line
  
G: Jump to the last line
  
#gg: Jump To Line #
  
#G: Jump To Line #
  
   Jump between sentences
  
(: Left parenthesis, jump to previous sentence
  
): Right parenthesis, jump to next sentence
  
   jump between paragraphs
  
{: Left curly brace, jump to previous paragraph
  
}: Closing curly brace, jump to next paragraph
  
   Flip Screen
  
CTRL+F: Flip one screen down
  
Ctrl+b: Turn up one screen
  
Ctrl+d: Flip Down half screen
  
Ctrl+u: Flip up half screen
  
   character editing
  
Edit command Meaning
  
x< Delete a single character at the cursor location
  
#x the position of the character at which the cursor is located and its trailing character, xp<, and its backward total # characters are removed
  
Delete command: D
  
Command mode d commands are often used in combination with jump commands, such as
  
d$: Indicates the deletion of the current cursor position to the end of the line
  
D: Indicates the deletion of the current cursor position to the first line of non-whitespace character position of the content
  
D0: Indicates the deletion of the current cursor position to the absolute beginning of the content
  
#d跳转符: Remove the # in the specified range of jumps, such as #dw #de #db
  
DD: Deletes the entire row of the line where the current cursor is located
  
#dd: Delete the # line including the line where the current cursor is located
  
D: Delete the contents of the line where the current cursor is located, leaving blank lines
  
Use of the D command in the last-line mode
  
Syntax:: startadd,endaddd
  
The Startadd and EndAdd here refer to a range, for example:
  
1,5D: Delete lines 1th through 5th
  
Range Representation Method:
  
Representation method Meaning
  
. The last line $< the current row of the cursor
  
+#< the line where the cursor is.
  
$-#< Countdown # line%< Full text
  
Copy command: yy
  
Paste command: P
  
P: Lowercase P
  
If the entire line is deleted or copied, paste it below the line where the cursor is located
  
If you delete or copy a non-full row, paste to the back of the character where the cursor is located
  
P: Uppercase P
  
If the entire row is deleted or copied, paste it above the line where the cursor is located
  
If you delete or copy a non-full row, paste to the front of the character where the cursor is located
  
Replacement: R
  
R: Replace mode, replace multiple characters
  
r#: Replace the character of the current cursor with #, where # can be any character
  
Undo Edit: U
  
U: Undo the previous edit operation, the Connect U command can undo the previous n edits
  
#u: Directly undo the previous # edit operation
  
Ctrl+r: Restore the last undo operation
  
Repeat the previous edit operation:.
  
   Visualization mode:
  
In visual mode, you can make all the edits you have made to the selected content.
  
V: Select content by character
  
V: Select content by rectangular block (row)
  
   Text Lookup:
  
/pattern: Find matching content from top down
  
? pattern: Find matching content from bottom to top
  
N: Find the next item from the top down
  
N: Find the next line from bottom to top
  
Find and Replace: s
  
The s command can only be used in the last line mode
  
   Syntax:
  
ADDR1,ADDR2 S/pattern/string/gi
  
1,5 s/abc/def/g:
  
means to replace all ABC with DEF for the first line to line fifth
  
Show or suppress line numbers in the last line mode:
  
Set Nu: Display line number
  
Set Nonu: Suppress line numbers
  
   VIM Text Editor
  
The most classical and practical antiquity artifact


  
If you are an IT person who needs or will be dealing with a Linux system, then learning how to work with Vim will definitely make your job a breeze!! Because many times, Linux as a server does not open the graphical interface, when the need for remote operation, you can only use the SSH "command character" shell interface to manipulate it, if you need to modify the server page code or configuration file, VI or VIM command is your best and most convenient is the most powerful partner! Believe me, learn physics VIM, go around the world is not afraid ...

文章来源:运维工程师培训(http://www.runtimewh.com/xwzx/hydt/3138.html)

Don't say you don't know it/a minute to bring you to know Vim's past life

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.