Use and configuration of vim

Source: Internet
Author: User

From "Bird Brother's private cuisine", the third, people's post and telecommunications publishing house

Simple use of vim:

Execution method:vim filename < open or new filename>

Three modes : General mode, edit mode, command line mode

General mode----> Edit modeI: Before the current indicator,o: Next line at the current prompt
a: The current prompt Next,R: Wipe backwards
<----ESC
General mode----> command line mode: Execute command,/down search,? Search up
<----ESC


Move Cursor
H,j,k,l: Move left, move down, move up, Move Down
0 or home: Move to the front of the bank
$ or end: Move to the end of the bank
1G or GG: Move to First line
NG: Move to Nth row
G: Move to the last line
N+space: Move n characters backwards
N+enter: Move n rows down

Find and replace
/word: Find word down
? Word: Find Word up
N: Move to next target
N: Move to previous target
: n1,n2s/word1/word2/g: Word1 is replaced with Word2 from N2 to N2
: 1, $s/word1/word2/g: replace word1 with Word2 from the first line to the end
: 1, $s/word1/word2/gc: replace word1 with Word2 from the first line to the end

Delete Copy and paste
X: Delete Forward
X: Remove Backward
DD: Delete cursor in the row
NDD: Delete cursor down n rows
D0: Delete cursor to the front
d$: Delete cursor out to the last
D1G: Delete cursor out to the first line
DG: Delete cursor to last line

YY: The copy cursor is in the row
Nyy: Copying the next n rows of the cursor
Y0: Copy from cursor to front of the bank
y$: Copy from cursor to bank last
Y1G: Copy from cursor to first line
YG: Copy from cursor to last

P: Copy to a line on the cursor
P: Copy to the next line of the cursor

U: Undo Last Action
Ctrl+r: Repeat Last Action

command Line
: q[!] : Exit, plus exclamation force exit
: w[!] : Save, add exclamation point to force save
: wq[!]: Save exit, add exclamation force
ZZ: If there are changes to save the exit, if no changes to directly exit
: W[filename]: Save as filename
: R[filename]: Introduce the filename content behind the cursor
: n1,n2 w FileName: Save N1 to N2 content in filename
:! Command: Temporarily leave VI to execute commands

Block Selection
V: Character selection
V: Line Selection
Ctrl + V: Block selection, rectangular selection data
Y: Copy the selected block
D: Delete the selected block

Multi-file editing
Vim filename1 filename2
: N: Edit Next file
: N: Edit Previous file
: Files: Lists all files currently open by this vim

Multi-window display
: SP FileName: Opens another file
: SP: Bring this file again in this window
ctrl+w+k/: Previous window
ctrl+w+j/: Next window
CTRL+W+Q: Close the current window

Chinese coding problem
DOS and Linux segment line characters
In DOS, CR and LF are both segments, and only LF in Linux
Dos2unix [-kn] File NewFile
Unix2dos [-kn] File NewFile
-K Preserve the date of the source file
-N Keep Source file

Language Conversion
Iconv--list: Output iconv supported encoding
Iconv-f Original code-T new code [-O newfile]
View File Encoding
File-bi filename
: Set fileending

Use and configuration 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.