Use of Vim

Source: Internet
Author: User
Tags add numbers

Basic concept: A powerful text editor developed by VI
Open File:
Vim file name
Vim + N File name —————— How many lines of file are opened directly
Vim three modes of operation
Command mode
Command mode toggle Input mode
Input mode
Last-line mode
Switching between three modes

Multi-Window function
Open multiple windows: sp+ file (sp opens the current file again by default)
Multi-Window switching: ctrl+w+j/k or Ctrl+w (by multiple)
Execute the command without turning off vim
:! Command
: shell-switch Shell command line, EXIT returns VIM
Multi-file editing
Open multiple Files: Vim file1 file2 File3
Show all open files--:files
Edit Next file: N
Edit Previous file: N
Block selection
In normal mode (press ESC to enter) The key v into the visualization mode, and then press the left or right keyboard or h,l key to achieve the text selection.
V: Select by character. Patterns that are used frequently
V: Select by row
CTRL + V: SELECT by block. Very powerful, only in a few editors have such a function. You can select a rectangular block, and the text inside the rectangle will be highlighted.

Basic operation of the last line mode
Save and exit
Save
: w--Save Changes
: W file path-Save as other file
Exit
: q--does not save exit
: q! --Force Save exit
Save and exit
: wq--Save Exit
: x--Save Exit
: wq! --Force Save exit
: e! Discard all changes and open the original file.
Paste other file contents in the current file
: r+ File path
Open new File Edit
: e+ File path
File content Substitution
: s/old/new--replaces the first character found in the current row
: s/old/new/g--replaces all characters found in the current line
: #, #s/old/new/g--Replace all strings in the line number "#,#" range
:%s/old/new/g--replaces all strings within the entire file
: s/old/new/c need to be manually confirmed by the user before ——— replacement
Delete the contents of the first line to the first line: N,nd
Copy the contents of the first line to the first line: N,ny

Basic operation of Command mode
Cursor movement
Move Cursor Direction
Left and right
Flip Screen operation
ctrl+f--back one page
ctrl+b--a page forward
ctrl+d--back Half page
ctrl+u--Half-page forward
Enter-turn backwards by line
In-line jump
Jump between characters
h--Left
j--under
k--on
l--Right
Note: You can add numbers before the letters to indicate a few characters to jump
Jump between words
w--jump to the beginning of the next word
e--jumps the ending of the current or last word
b--jump to the beginning of the current or the next word
Note: You can add numbers and jump to several words
Beginning line End Jump
0--jump to the beginning of the line
^--jump to first non-whitespace character at the beginning of a line
$--jump to end of line
Inline jump
g--jump to the last line
1g,gg--jump to the first line
NG: Jumps to the specified n-line
N "Enter"--Move the cursor down n rows

复制    yy——复制光标所在行的所有字符    nyy——复制光标开始往后n行    y$——复制光标开始到行尾字符    y^——复制光标开始到行首字符    y0——等同y^粘贴    p———粘贴在光标所在行的下方    P——粘贴在光标所在行的上方删除    字符        x——删除光标后面一个字符        X——删除光标前面一个字符        nx——删除光标后面连续n个字符    行内多个字符        d0——删除光标开始到行首的字符        d$——删除光标开始到行尾的字符        d^=d0    整行        dd——删除光标所在行        ndd——删除光标所在行及向下n行查找    /word——从上往下查找    ?word——从下往上查找    n——定位上一个查找结果    N——定位上一个查找结果撤销编辑与反撤销与重复执行上一个操作    撤下:u    反撤销:ctrl  +  R    “.”——重复执行上一个操作

DD is equivalent to clipping and can be pasted directly

Attention:
If you use Vim to edit a file during a process that is not normally closed, it will save your written, but unsaved, content to this cache file (ls-a view, the hidden file that begins with.), called the swap file.
Suggestions can be deleted directly and will not appear the next time you open the file.

Use of Vim

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.