VI Skill Collection

Source: Internet
Author: User

VIM Tricks Match & Replace
  • Match the whole word (eg:match printf but not snprintf/fprintf)
    You can use \< to match the beginning of a word and > to match the end:

      
         
       
    1. %s/\<printf\>/PRINTF/gc
  • match the current line to last line of file

     
         
       
    1. , $s / printf / printf / Span class= "PLN" >GC
  • match the current line to the next and line of file

     
         
       
    1. .,+ 2s / printf / printf / GC
  • Replace word contain/, eg. Printf->//print

      
         
       
    1. :s!printf!//printf!gc
Text selection

Link Address
If you want to does the same thing to a collection of lines, like cut, copy, sort, or format, your first need to select the T Ext. Get out of insert mode, hit one of the options below, and then move up or down a few lines. You should see the selected text highlighted

Key Description
V Selects entire lines
V Selects range of text
Ctrl-v Selects Colums
Gv Reselect block
Word & Line Completion

Link Address

Key Description
Ctrl-n Next word completion (similar word in the current file
Ctrl-p Previous word completion (similar word in the current file
Ctrl-x, Ctrl-l Line completion
Ctrl-w Erases word (insert mode)
Ctrl-u Erases line ... or command line

When we command set path value

 
   
  
  1. :set dictionary=/usr/share/dict/words

Then, Ctrl-x, Ctrl-k, the dictionary completion

Markers

Link Address
Use the markers to set places your want to hotfoot get back to, or to specify a block of text you want to copy or cut.

Key Description
Ma A Mark current position as mark A (can use a-Z)
' K Move to Mark K
d ' k Delete form current Positon to mark K
' A-Z Same file
Reformatting

Link Address
These is useful to reformat text paragraphs or chunks of code (Note: This does not Python code ...)

Key Description
v= Select text, then reformat with =
= Would correct alignment of code
== One line
Gq Reformat paragraph
Folding

Link Address
Use folds to collapse selected blocks. Useful if you had finished a subroutine and want to save window space, or maybe want to fold allboocks of comments

Key Description
Zo Open Current Scope fold
Zc Close current Scope fold
ZO Open current scope fold and sub scope fold
Zc Close current scope fold and sub scope fold
Insert text beginning multi-line of same columns

Link Address

    • Use + to select the first column of text in the Ctrl lines you want to V comment.
    • Then hits shift + and i type the text you want to insert.
    • Then hit Esc wait 1 second and the inserted text would appear on every line.


From for notes (Wiz)

VI Skill Collection

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.