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:
%s/\<printf\>/PRINTF/gc
-
match the current line to last line of file
-
, $s / printf / printf / Span class= "PLN" >GC
-
match the current line to the next and line of file
-
.,+ 2s / printf / printf / GC
Replace word contain/, eg. Printf->//print
: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
: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