Linux VIM Basic command

Source: Internet
Author: User


Linux VIM command:
1.
Vim
#Enter vim in the command line to enter the vim editor
2.
i
#Click the i button, the lower end shows --INSERT--
# Insert command, any character in vim may have a role
3.
Esc
# Exit i (insert) command for other commands
7.
:! command
Temporarily leave vi to execute the command display result in command line mode! E.g
:!ls
#Execute shell command ls during editing
8.
:sh
#Enter the shell command line, after executing the command, ctrl+d exits and re-enters the vim editor to continue editing.
Under the shell command, execute ctral+l to complete the clear screen.
12.
:set number or :set nu
#Let the file in the editor display the line number
13.
:set nonumber or :set nonu
#In contrast to the previous command, the line number is not displayed.
14.
:help i
#View Insert Command Help
15.
u
#Undo the previous step
16.
/Fedora
#find Fedora characters
17.
:s /Fedora/Redhat
# Replace Fedora characters with Redhat (replace only the line where the cursor is located)
18.
Dw
# delete the word
Dd

19.
o
#Open a blank line
20.
Vim + filename
#[Edit the last line of the file for editing
twenty one.
Vim +n filename
#Enter the file nth line for editing
twenty two.
:1,.s/redhat/fedora
The #. number indicates the current line, that is, the line where the cursor is.
# Replace the first redhat character from the first line to the current line (.) as fedora
twenty three.
:1,.s/redhat/fedora/g
# Replace all redhat characters from the first line to the current line (.) to fedora, g
Global flag
twenty four.
:1,$s/redhat/fedora/g
#$ indicates the last line
# Replace all redhat characters from the first line to the last line to fedora
25.
:%s/redhat/fedora/g
#Same command 26.
:%s/\/fedora/g
# Replace all redhat words in the first line to the last line as fedora
#字, instead of characters
27.
:f
#Display file content, status, etc.
#ctrl+g command




                               

                             VIM command Daquan
Cursor control command
Command cursor movement
h Move one character to the left
j moves down one line
k moves up one line
l Move one character to the right
G moves to the last line of the file
:1 Move to the first line of the file
w moves to the beginning of the next word
W moves to the beginning of the next word, ignoring punctuation
e moves to the end of the next word
E moves to the end of the next word, ignoring punctuation
b moves to the beginning of the previous word
B moves to the beginning of the previous word, ignoring punctuation
L moves to the last line of the screen
M moves to the middle of the screen
H moves to the first line of the screen
(move to the beginning of the sentence
) moved to the end of the sentence
{ Move to the beginning of the paragraph
} Move to the beginning of the next paragraph
0 (number), | moved to the first column of the current row
^ Move to the first non-null character of the current line
$ moves to the last character of the current line
+, Enter moves to the first character of the next line
- Move to the first non-null character of the previous line
Add text to vi
Command insert action
a Insert text after the cursor
A inserts text at the end of the current line
i insert text before the cursor
I insert text before the current line
o Insert a new line below the current line
O Insert a new line above the current line
s delete the character at the cursor and enter insert mode
S delete the line where the cursor is located and enter insert mode
:r file reads the file file content and inserts it after the current line
:nr file reads the file file content and inserts it after the nth line
Esc back to command mode
Delete text in vi
Command delete operation
x delete the character at the cursor
Dw delete to the beginning of the next word
dG deletes the cursor line until the end of the file
Dd delete the entire line
Db delete the word in front of the cursor
:n,md delete n lines to m lines
d, d$ is removed from the cursor to the end of the line
d$ is removed from the cursor to the end of the line
d,d^ is deleted from the cursor to the beginning of the line
D^ delete from the cursor to the beginning of the line
Modify vi text
The number in front of each command indicates the number of times the command is repeated.
Command replacement operation
Rchar replaces the current character with char
R text escape Replace the current character with text until the Esc key is pressed
Stext escape replaces the current character with text
S or cctext escape replaces the entire line with text
Cwtext escape changes the current word to text
Ctext escape changes the rest of the current line to text
cG escape is modified to the end of the file
Find and replace in vi
Command find and replace operation
/text finds text forward in the file
?text finds text backwards in the file
n Repeat lookup in the same direction
N repeats the search in the opposite direction
:set ic ignores case when looking up
:set noic is case sensitive
:ranges/pat1/pat2/g replace oldtext with newtext
:m,ns/oldtext/newtext pass n on m lines, replace oldtext with newtext
& repeat the last :s command
:g/text1/s/text2/text3 find the line containing text1 and replace text2 with text3
:g/text/command Runs the command represented by command on all lines containing text
:v/text/command Runs the command represented by command on all lines that do not contain text
Copy text in vi
Command copy operation
Yy puts the contents of the current line into a temporary buffer
Nyy puts the contents of n lines into a temporary buffer
p puts the text in the temporary buffer into the cursor
P puts the text in the temporary buffer before the cursor
Undo and repeat in vi
Command undo operation
u Undo the last modification
U Undo all modifications to the current line
Repeat the last modification
, repeat the previous f, F, t, or T lookup command in the opposite direction
; Repeat the previous f, F, t or T lookup command
"np retrieves the last nth deletion (there is a certain number of deletions in the buffer, usually 9)
n Repeat the previous / or ? find command
N repeats the preceding / or ? command in the opposite direction
Save text and exit vi
Command save and / or exit operation
:w saves the file but does not exit vi
:w file saves the changes in file but does not exit vi
:wq or ZZ or :x save the file and exit vi
:q! Do not save the file, exit vi
:e! Discard all changes, edit from the last saved file
Options in vi
Option
:set all print all options
:set nooption turn off option option
:set nu prints the line number before each line
:set showmode shows whether it is an input mode or a replacement mode
:set autoindent inherits the indentation of the previous line, especially for multi-line comments
:set smartindent provides automatic indentation for C programs
:set list displays tabs (^I) and end-of-line symbols
:set ts=8 set tab stops for text input
:set window=n Set text window to display n lines
Status of vi
Option
Ctrl+g displays the file name, current line number, total number of lines in the file, and percentage of file location
:l Use the letter "l" to display many special characters, such as tabs and newlines
Locate paragraphs and place markers in text
Option
{ Insert { to define a paragraph in the first column
[[ Back to the beginning of the paragraph
]] Move forward to the beginning of the next paragraph
m(a-z) marks the current position with a letter, such as mz for the mark z
'(a-z) Move the cursor to the specified tag, such as Use 'z to move to z
Connect lines in vi
Option
J connects the next line to the end of the current line
nJ connection behind n lines
Cursor placement and screen adjustment
Option
H Move the cursor to the top line of the screen
nH Move the cursor to the nth line below the top line of the screen
M Move the cursor to the middle of the screen
L Move the cursor to the bottom line of the screen
nL moves the cursor to the nth line on the bottom line of the screen
^e(ctrl+e) scrolls the screen up one line
Ctrl+y scrolls the screen down one line
Ctrl+u will scroll half a page
Ctrl+d rolls the screen down half a page
Ctrl+b will scroll one page on the screen
Ctrl+f scrolls the screen down one page
Ctrl+l redraw screen
Z-return sets the current line to the top line of the screen
Nz-return sets the nth line under the current line to the top line of the screen
z. Set the current line to the center of the screen
Nz. Set the nth line on the current line to the center of the screen
Z- sets the current line to the bottom line of the screen
Nz- sets the nth line on the current line to the bottom line of the screen
Shell escape command in vi
Option
:!command Executes the shell command command, such as :!ls
:!! Execute the previous shell command
:r!command Read the input of the command command and insert it, for example: r!ls will execute ls first, then read in the content
:w!command takes the currently edited file as the standard input for the command command and executes the command command, such as :w!grep all
:cd directory changes the current working directory to the directory represented by directory
:sh will start a subshell and return ^ with ^d(ctrl+d)
:so file Read and execute commands in the shell program file
Macros and abbreviations in vi
(Avoid using control keys and symbols, do not use the characters K, V, g, q, v, *, = and function keys)
Option
:map key command_seq Define a key to run command_seq, such as :map e ea, whenever you can e move to the end of a word to append text
:map displays all defined macros in the status line
:umap key remove the macro of the key
:ab string1 string2 Defines an abbreviation so that when string1 is inserted, string1 is replaced with string2. When you want to insert text, type string1 and press Esc, the system inserts string2
:ab Show all abbreviations
:una string cancel string abbreviation
Indent text in vi
Option
When ctrl+i or tab is inserted into the text, the width of the movement is inserted, and the width of the movement is defined in advance.
:set ai turn on automatic indentation
:set sw=n sets the movement width to n characters
n> Move n lines to the right by a width, for example 3>> to move the next three lines and each line to the right by a moving width



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



Linux VIM Basic command


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.