(turn) vim commonly used shortcut key two

Source: Internet
Author: User
Tags control characters diff ranges save file scp file

Turn from: http://www.cnblogs.com/wangkangluo1/archive/2012/04/12/2444952.html keyboard Move (move)

Everything is moving from the keyboard
K-On Up
J-Down
H-Left
L-R Right
Z---redraw the screen, the current cursor changes to the first line of the screen (redraw at top of window)
Ctrl-f, skip to next page (PAGE down)
Ctrl-b, skip to previous page (page UP)

Jump Command (jumps)

The jump command is similar to the < forward >< back > button in the Viewer
CTRL] and follow Link/tag transfer (follow Link/tag)
Ctrl-o, go back to the last jump
Ctrl-i, jump back to the next (go forward)
: Ju--Show all the places where you can jump (print jumps list)

Redo/Reply

Undo, U
Ctrl-r-Redo
The undo of vim is a tree structure, and you can go back anywhere in the structure.
: Undo 2 to 2 layer of structure (undo to Tree 2)
: Undolist Show all Undo lists (show undo list)
: Earlier 10s, undo to 10 seconds ago editor (undo to seconds ago)
: Earlier 10h, undo to 10 hours ago editor (back to hours ago)
: Earlier 1m, undo to 1 minutes ago (back to 1 minutes ago)
The following is an explanation of the tree structure of undo
.....
........ |
.... Change 1
........ |
..... one too
.......... /........\
.... Change 2 .... Change 3
....... | .............. |
......... me too .... Me
........... |
..... Change 4
...... |
... not a.

Visual mode (visual)

V-Enter Visual mode
Can be used as block editor in Visual mode.
Visual Block Ctrl-v

Printing (print)

: hardcopy print Vim content (print text)
Mixed visual Mode (visual) to select the area to print
I haven't tried. Whether you can print values directly (should be possible) For example: 1,15hardcopy print the first 15 lines

Write a file as a Web page format (HTML)

: Source $VIMRUNTIME/syntax/2html.vim, change, current, open file to HTML

Formatting (format)

Dos/windows and Unix/linux are not the same for the end of the file. Vim can be directly set/changed format
Paper Order: Set Fileformats=unix,dos can change the format of the file (changes format)

: Set Ff=unix, set file to UNIX format (set files in UNIX formats)
: Set Ff=dos, set file into DOS format
: Set FF? Check the current file format (check the format of
If you change the format, the direct: W archive will be saved as a new format.

Encryption (encryption)

Vim can add a password to a file
Vim-x file name (filename), enter the password 2 times, save the files every time you need a password to enter (encrypt the "file with password)
When Vim processes encrypted files, it does not authenticate the password, that is, when you open the file, VIM does not use the password to decrypt the document, regardless of whether the password you entered is correct. If the password is wrong, what you see will be garbled, and will not remind you of the password error (this increases the security, there is no place to know whether the password is correct) of course, if you use a fast enough machine for the poor lifting hack, vim can be uncovered

VIM syntax display (syntax)

: syntax enable-open syntax color display (turn on syntax color)
: Syntax clear-down syntax color (remove syntax color)
: Syntax off full grammar function (turn off syntax)
: Syntax manual, manual set Syntax (set the syntax manual, when need syntax Use:set Syntax=on)

Enter special characters (special character)

Ctrl-v code on it.
For example Ctrl-v 273? Get?

Binaries (binary file)

Vim can display, edit 2 carry Files

Vim-b datafile
: Set Display=uhex, this will be displayed as Uhex. Used to display some characters that cannot be displayed (control characters, etc.) (display in Uhex play Non-display char)

:%!xxd. Change current file display as 2 rounding
:%!xxd-r, change binary to text format (convert back to text)

Auto-complete (auto-completion)

VIM itself has auto-complete function (this is not to say Ctag, but vim built-in)
Ctrl-p-Backward Search auto-complete (search backward)
Ctrl-n, forward Search auto-complete (search forward)
Ctrl-x+ctrl-o-Auto-complete code completion

Automatic Backups (Backup)

Vim can help you to automatically back up files (save the time, the previous file back up)
: Set backup, open Backup, the name of the built-in file is the source file name plus a ' ~ ' (enable backup default filename+~)
: Set Backupext=.bak, set backup file name as source file name. bak (change backup as Filename.bak)

Automatic backup The problem is that if you save a file multiple times, your backup file will be overwritten, and you can only have the last backup of the file you saved. It doesn't matter, VIM also provides Patchmode, this will take your first original file back down, will not change
: Set Patchmode=.orig. Save the original file as the file name. Orig (keep orignal file as Filename.orig)

Open, Save and exit (Save & Exit)

: W-Save file (write file)
: w! Forced Save (Force write)
: Q-to exit files (exit file without Save)
: q! Forced exit (force quite without save)
: E filename to open a file named filename (open file to edit)
: e! FileName---Force open a file, all unsaved things will be lost (forces open, drop dirty buffer)
: Save file as filename, SaveAs filename

Editing instructions (Edit)

A--Insert after Light table (append after cursor)
A--insert at end of row (append at end of the line)
I--To insert before cursor (insert before cursor)
I--In the first non-whitespace word match either insert (insert before-Non-blank)
Insert a new line under the O-cursor (open lines below)
Insert a new row above the cursor (open line above)
X--delete something under the cursor (or later) (delete under and after cursor)
For example, X is deleted under the current cursor, 3x is deleted under the cursor + cursor after the 2-character
X--Delete the character before the cursor (delete before cursor)
Remove (delete)
Can delete a line with DD, or 3DW delete 3 words and so on
J--The next line will be mentioned here (join lines)
Replace character R (replace characters)
Replace multiple characters (replace mode–continue replace)
GR--no change to layout replacement (replace without affecting layout)
C--like the D key, but is removed to enter the input mode (same as "D" but after the delete, in insert mode)
Delete a row (like DD) but enter input mode after deletion (same as "DD" but after delete, in insert mode)
S--delete character, same as (d), but enter input mode after deletion (same as "D" but after delete, in insert mode)
S4s will delete 4 characters into input mode (delete 4 char and put in insert mode)
~--Change the case, big change small, small change size (changes, upper-> lower or lower->upper)
Gu to lowercase (change to lower case)
For example, GUG will turn the cursor current to the end of the file to lowercase (change lower case all the the-the-end)
GU to uppercase (change to upper case)
For example, GUG will turn the cursor current to the end of the file to full capitalization (change upper case all the end)

Copy and paste (copy & paste)

Y--copy (Yank line)
YY---Copy the current row (Yank)
"{a-za-z}y) copy the information to a deposit (Yank the link into register {a-za-z})
For example I use "Ayy so in a, copy a line, and then I use" byw copy a word in the Register B
Paste the time, I can choose to paste a inside the thing or b inside, this is like multiple copies of the same version
*y-This is a copy of the information into the system (can be posted in other programs) (Yank to OS buffer)
P--Current under cursor paste (paste below)
P---current cursor paste (paste above)
"{a-za-z}p. Paste a registered content (paste from register)
For example, "AP then just post the contents of me in deposit a before the current cursor." "BP posted the contents of B before I put it on the current cursor.
"*p, read information from the clipboard of the system and paste it into vim (paste from OS buffer to vim)
Reg--Show all contents in the Register (list all registers)

Bookmark (Mark)

Bookmarks are a very powerful feature in Vim, and bookmarks are divided into file bookmarks and global bookmarks. A file bookmark is a different location in your tag file, and you can quickly jump to the desired location within the file. A global bookmark is a location that marks a different file. That means you can jump quickly in different files.

M{a-za-z}, save the bookmark, lowercase is the file bookmark, can be used (A-Z) in any letter mark. Uppercase is a global bookmark, marked with any letter in uppercase (A-Z). (Mark position as bookmark. When lower, only stay in file. When upper, stay in global)
' {a-za-z} ' to jump to a bookmark. If it is a global bookmark, the bookmarked file is turned on to the marked line (go to mark. in file {A-Z} or global {A-z}. In global, it will open the file)
' 0--jump to the location of the last exit from the file you are editing
"-Jump as the last hop (go to end jump)
', jump to the last edit location
G ' {mark} ' jumps to bookmarks (jumping to {mark})
Delete a bookmark:d elm{marks} (delete a mark) For example: Delma then delete the bookmark a
:d elm! Delete all bookmarks (delete all marks)
: Marks display system all bookmarks (show all bookmarks)

Logo (TAG)

: Ta-to-jump sign (jumping to tag)
: TS--Displays the match flag and jumps to a flag (list matching tags and select one to jump)
: Tags--show all logos (print tag list)

Running external commands (using an external program)

:! Directly run an external command in the shell (call any external program)
:!make to run the make command directly in the current directory (run make on present path)
: R!ls Read the input of externally run commands, and write to Vim in the course. The output of the LS is read here (read the outputs of LS and append the result to file)
: 3r!date-u Input The results of the external command date-u in the third line of vim (read the date-u, and append result to 3rd lines of file)

: W!WC the content of vim to external instructions. This allows the WC to process the contents of vim (send Vim's file to external command.)
Vim has some built-in for common directives, such as WC (count words) (Vim has some buildin functions, such like WC)
G Ctrl-g calculate the number of words for the currently compiled file (Word count on current buffer)
!! Date, insert current time (insert present date)

Editing of multiple files (edit multifiles)

Vim can edit multiple files, such as
Vim A.txt b.txt C.txt opened 3 files

: Next, edit next (next file in buffer)
: next! Force edit the next file, which means if you change the first file (forces to next files in buffer if current buffer changed)
: Wnext save file, edit next (Save the file and Goto next)
: args--Find the name of the file currently being edited (find out which buffer was editing now)
Edited last file by:p revious (previous buffer)
:p revious! Force edit last file, same as: next! (Force to previous buffer, same as:next!)
: Last file, edit final buffer
: First file (first buffer)
: Set Autowrite, set automatic save, when you edit the next file, the currently editing file if changed, will be automatically saved (automatic write the buffer when you switch to next buffer)
: Set Noautowrite-off auto-save (turn autowrite off)
: Hide e Abc.txt, hiding the current file, open a new file Abc.txt edit it (hide the present buffer and edit abc.txt)
: Buffers Show All files in vim (display all buffers)
: Buffer2, second in edit file (edit buffer 2)

Vim in a lot of things can be written in short, you do not have to type so troublesome, such as: Edit=:e,: Next=:n.

Split screen (split)

VIM provides split-screen functionality (same as split in screens)
: Split screens into 2 (split screen)
: Split Abc.txt, divides the screen into two, and the second new screen displays the contents of the Abc.txt (split the Windows, on New window, display Abc.txt)
: Vsplit split screen (split vertically)
: {d}split---set the number of split-screen lines, for example, I want a screen with only 20 rows, you can: 20split (split the windows with {D} line. 20split:open new windows with 3 lines S
: New and split screen and create a blank file in the screen (split windows with a new blank filename)
CTRL-W+J/K/H/L, use CTRL + W plus j/k/h/l to switch between different screens (switch, move between split screens)
ctrl-w+-/+-plus split screen size (change split size)
Ctrl-w+t to the top of the screen (move to the top windows)
Ctrl-w+b to the bottom of the screen (move to bottom window)
: Close a split screen (close splited screens)
: Only show cursor current screen, others will be turned off (only display active screens, close all others)
: Qall, exit all screens (quite all windows)
: Wall Save All screens (write to all windows)
: Wqall Save and exit all screens (write and quite all windows)
: qall! ---Exit all screens without saving any changes (quite all windows without save)
When the file is opened, the-o option allows you to open multiple files directly in the split screen (with-o option from command line, it'll open files and display in Split mode)
Vim-o a.txt B.txt

Today, some people say not to look at diff, in fact, vim can also be used to see the diff, this is also part of the split screen, here also write.

Vimdiff A.txt B.txt If directly to the-D option is the same vim-d a.txt B.txt
:d Iffsplit Abc.txt If you have now opened a file, like Vim to help you distinguish between your file and Abc.txt, you can use the Diffsplit in vim to open the second file, this time vim will split the way to open a second file , and by color, fold to show the difference of two files
This way, VIM will use color to help you distinguish between 2 files. If the file is larger (source) the duplicate part will help you fold up (folding later will say)
Now, Patch.
:d iffpatch filename by: Diffpatch The file name of your patch, you can display it in the current file plus your patch. Vim will split a new screen, display the patch information and use color to indicate the difference.
If you do not like the upper and lower contrast, like the left and right (more in line with the visual) can be added vert, for example:
: Vert Diffsplit Abc.txt
: Vert Diffpatch Abc.txt
After reading the diff, use: Only back to the original edited file, feel the color of the diff is still where, just use: Diffoff close.
There is a common diff in the:d iffu this is:d iffupdate shorthand, updated with

TAB

In addition to split, Vim can also use tab

: Tab Split filename--This is the way to display multiple Files with tab (Use tab to display buffers)
GT-To-next tab (go to Next tab)
GT-To-last tab (Go to Previous tab)
Vim most things can be done with a number, tab is the same
Jump to the first tab (switch to 1st tab), 0GT
Jump to the Fifth tab (switch to 5th tab), 5GT

Close all tabs to use Qall's instructions. In addition, let vim automatically start with the Tabnew way to open multiple files, you can use alias Linux: Add alias vim= ' Vim-p ' to ~/.BASHRC windows: Write yourself a vim.bat file, and then put it in path, file content: @echo off vim-p%* when you need to change multiple tab files, you can use: tabdo This command is equivalent to loop to all of your tab and then run the instructions. For example, there are 5 files in the tab, you need to change the name of a variable: ABC to DEF, you can use: Tabdo%s/abc/def/g so all 5 tab inside the ABC has become DEF

Folding (folding)

Vim Folding Function ... I remember it should have been released when the version 6 came out. This is very useful for people who write programs.
ZFAP-fold by paragraph (fold by paragraph)
Zo opens a folding (open fold)
ZC--Close a fold (close fold)
ZF--Create fold This can be used in v visual mode, can be directly to the number of rows and so on
ZR---open a certain number of folds, for example 3rz (reduce the folding by number like 3ZR)
ZM---fold a certain number (previously you defined the folding) (fold by number)
ZR---Open all folds (open all fold)
ZM--Close all folds (close all fold)
Zn-and-Off folding function (disable fold)
Start folding function (Enable fold) with ZN
ZO, open all folds under the cursor (open all folds on the cursor line)
ZC-to close all folds under the cursor (Close all fold at cursor line)
ZD, delete the cursor under the fold, this is not the deletion, just delete the folding mark (delete fold at cursor line)
ZD---Remove all folds under the cursor (delete all folds on the cursor line)
Folding by tab, Python Best (Ford by indent, very useful for Python)
: Set foldmethod=indent, after setting with ZM and ZR can switch off (use ZM ZR)

Saving (save view)

For VIM, if you set the fold, but exit the file, the collapsed part will automatically disappear, regardless of whether you keep the file or not. This is very inconvenient. So vim gives you a way to save records such as folding, tagging, bookmarks and so on. Best of all, Vim can hold up to 10 view per file, which means you can have 10 different tagging methods for the same file, which will be saved as you want.
: Mkview-Save Record (save setting)
: Loadview read record (load setting)
: Mkview 2, save record at deposit 2 (save view to register 2)
: Loadview 3, read from the Register 3 (load view from register 3)

Common directives (commands)

: Set IC setting is case insensitive when searching (search case insensitive)
: Set Noic is case-sensitive when searching. Vim is the default (case sensitive)
& Repeat Last ": S" (Repeat previous ": S")
. Repeat last command (Repeat command)
K-in man search for words under current cursor (Search man page under cursor)
{0-9} K-To find the chapter in man under the current cursor, for example, 5K is equal to man 5 (the search section of the man. 5K search for Mans 5)
: View command History--
Q: Open the VIM Command window (open VIM command windows)
: e-Open a file, vim can open HTTP/FTP/SCP file (open file. Also works with HTTP/FTP/SCP)
: E http://www.google.com/index.html-Here opens Google's index.html in vim (open Google's index.html)
: Replace catalog in vim with CD---current directory in Vim
Show vim current directory:P WD--Display pwd in vim
GF-Open file. For example, if you had a line in vim that says # include then pressing GF,VIM on the abc.h will open the Abc.h file (look for file.) If you have a files with #include and then the cursor is on Abc.h Press GF, it'll open the file abc.h in vim)

Recording instructions (record)

Q{A-Z} record instructions in a register (record typed char into register)
Q{A-Z} Insert the instruction before the register (append typed char into register{a-z})
Q-End record (stop recording)
@{a-z}, executing the instructions in the park (execute recording)
@@-> Repeat last instruction (repeat previours: @{a-z})
Or an example of how easy it is to understand.
I now put the QA command in a file, then enter ITest then ESC and then Q
Here QA means to record my instructions into a deposit, itest is actually divided into 2 steps, I is inserted (insert) written text is text and then use ESC return instruction mode Q end record. So I put the itest record in another deposit.
Below I execute @a then it will automatically insert the word test. @@ 就 the previous action, so it's still equal to @a.

Searching (search)

One of the super-powerful features of Vim is the search and replacement. If you are familiar with the positive expression (regular expressions) This search will be an unbeatable tool (the editor with RE is not much).

Speaking from the simple
#, Reverse search keywords under cursor (search the word under cursor backward)
*, forward search keywords under cursor (search the word under cursor forward)
(Search forward)
? --Up search (search back)
Here you can use/ABC or ABC to search up and down the ABC
To find the next end, for example, under (Find Next ")", You can find "()", "[]" and the shell common if, else these (find next brace, bracket, comment or #if/#else/#endi F

Speak in a few examples below
/a* This will search for a AA AAA
/\ (ab\) *-This will search AB abab ababab
/ab\+ This will search AB ABB ABBB
/folers\=, this will search for folder folders
/ab\{3,5}, this will search abbb abbbb abbbbb
/ab\{-1,3} and this will search for AB in abbb Match AB in abbb)
/a.\{-}b This will search for AXB (match ' axb ' in ' Axbxb ')
/a.*b, which is found at the beginning of any a (match a*b an Y)
/foo\|bar search foo or bar to search for 2 words (Match ' foo ' or ' bar ')
/one\|two\|three search 3 words (match ' one ', ' two ' or ' Three ')
/\ (foo\|bar\) \+-search foo, foobar, Foofoo, Barfoobar, etc. (Match ' foo ', ' foobar ', ' foofoo ', ' barfoobar ' ...) Br>/end\ (if\|while\|for\), search endif, Endwhile endfor (Match ' endif ', ' endwhile ', ' endfor ')
/forever\& This will search for ' for ' in forever but will not search for ' for ' in Fortuin because we gave & here. The limit (match ' for ' in ' forever ' would not match ' Fortuin ')

Special characters preceded by ^ can (for special character, user "^" at the start of range)
/"[^"]* "
Explain here.
"Double quotation marks are first caused (double quote)
[^] anything other than double quotes (any character, that's not a double quote)
* All other (as many as possible)
"End of the front quotation mark (double quote close)
The upper one will search for "foo", "3!x", including quotation marks (match "foo" and "3!x" include double quote)

More examples, such as searching for license plate rules, assume that the license plate is "1mgu103" that is, the first is a number, 3 uppercase subtitles, 3 numbers in the format. Then we can search directly for all the characters that match this rule.
(A sample License plate number is "1mgu103″. It has one digit, three upper case
Letters and three digits. Directly putting this to a search pattern)
This should be very understood, we search
\ number \ capital Letter \ Capital Letter \ Capital Letter \ number \ number \ number

/\d\u\u\u\d\d\d

Another way is to directly define a few numbers (otherwise if 30, do you want to hit 30 \u to go?) )
(Specify there is three digits and letters with a count)

/\D\U\{3}\D\{3}

Range can also be used to search (using [] ranges)
/[0-9][A-Z]\{3}[0-9]\{3}

Use a range search to list some ranges (range)
This is nothing to say, see it all understand, to all remember ... Use more to remember, with less to forget. Every time I see Help, hehe

/[A-Z]
/[0123456789ABCDEF] =/[0-9a-f]
\e
\ t
\ r
\b

Shorthand (item matches equivalent)

\d Digit [0-9]
\d Non-digit [^0-9]
\x hex Digit [0-9a-fa-f]
\x non-hex Digit [^0-9a-fa-f]
\s white space [] (and)
\s non-white characters [^] (not and)
\l Lowercase Alpha [A-z]
\l Non-lowercase Alpha [^a-z]
\u uppercase Alpha [A-z]
\u Non-uppercase Alpha [^a-z]

: Help/[]–> a special definition, can be used in vim to see (Everything about special)
: Help/\s–> Normal can also look directly (everything about normal)

Replace (string substitute) –rx

The substitution is actually the same as the search. Only the replacement is 2 values, one is what you search for, and the other is the string substitute (use Rx) to be replaced after the search.

%s/abc/def/, replacing ABC to DEF (substitute ABC to DEF)
%S/ABC/DEF/C, replace ABC to DEF, will ask you every time ok (substitute on all text with confirmation (y,n,a,q,l))
1,5s/abc/def/g-I only replace the ABC-to-def between the first line and the 15th row (substitute ABC to def only between lines 1 to 5)
54s/abc/def/, replace the ABC-to-def (only substitute ABC-def on line 54) with the 54th row

Combined with the above search positive expression, this replacement function ... is very strong. Many places in Linux are using positive expressions to do things, so learn to benefit from infinity.

Globals (Global)

This does not know how to translate, anyway vim is called global, you can search for something to perform some vim command. I was also 2-3 weeks ago because I read something special in the log, I learned to use it. (Find the match pater and execute a command)

Global's specific approach is G/pattern/command
: g/abc/p to find and display only ABC lines (only print line with "ABC")
: G/ABC/D---delete all lines that have ABC (delete all line with "ABC")
: V/ABC/D This will erase everything that is not in line with ABC (delete all lines without "abc")

Information Filtering (filter)

Vim is yet another powerful feature

! ---use! is telling vim to perform the filtering process (tell Vim to performing a filter operation)
!5G, from the cursor down 5 lines to execute the filter program (tell the VIM to start filter under cursor and go down 5 lines)

Start with a formal order, here's an example of sort:
!5gsort, starting with the cursor and executing sort, a total of 5 lines, that is, I just sort5 line only (this would sort the text from the cursor lines down to 5 lines)
! GSORT-K3-I can directly substitute the sort parameter, I want the third paragraph in the sort text (sort to the end of file by column 3)
!! -Value Filters the current row (filter

If you feel it! Such a method 5G is awkward (I think so) and can be done in standard command mode
! is actually a:., just (to type the command)
:., Start,end!sort here defines:., start line, end line! Run command
:., $!sort, from the current row until the end of the file (sort from.
:. 0,$!sort, from the beginning of the file to the end of the file (sort from start, to end)
:. 10,15!sort only between lines 10th through 15th of the file (sort between line 15)

(turn) vim commonly used shortcut key two

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.