Replace with the content of the copy
When there is a spelling error or if you want to rename an identifier, you need to replace the current name with the contents of the copy. For example, when invoking a function, the error is written:
void Letus_fuckit_with_vim () {
cout<< "great!";
}
Let_fuckat_with_vom ();
Just copy the name of the function above, and then switch the cursor to the misspelled word first. Then press VIWP and replace it:
void Letus_fuckit_with_vim () {
cout<< "great!";
}
Letus_fuckit_with_vim ();
V into visual mode, and then IW to select the word cursor, and finally press p to paste. IW said inner word
, the useful collocation also has yiw, the CIW and so on.
Second, copy the entire document
When we first started using Vim, the great God would tell us how to copy the entire file: Ggvgy, NB of the Great God will tell us: Ggyg. Now let me tell you:
Three, temporarily leave insert mode
When we are insert
in a pattern, we sometimes want to execute a command in normal mode and return to the insert
pattern immediately. You may need to press <esc> first, execute the command, and then press I.
VIM provides convenience for this:
When we need to temporarily leave insert mode and execute a command, <c-o>
vim automatically returns to insert mode after performing subsequent commands.
For example:
: Map <F5>:! g++% &&/a.out <CR>
: IMAP <F5> <c-o><F5>
Four, character lookup
VIM cursor Jump Although there are dozens of kinds of shortcuts, but you have not found that when we encounter a long word will be very weak, such as I want to replace the following description with keywords:
is not to constantly knock on the L (or knock several times {num}l), in fact, can use the Word lookup function. Just enter the FD to find the next letter D for the current line. Uppercase F can be found in reverse.
V. Search the current Word
Press * to search the word (word) where the current cursor is located, and press the next search again. Press # to search the previous.
* Match only the words that appear, there is no hyphenation in Chinese. If you find all the strings of the current word, you can use g*.
Six, the command mode paste
If you want global lookup to replace the word that the current cursor is in, we may need to tap it manually in command mode: %s/foo/bar/g
. But if the current cursor is on that word, you can paste it into the command after you knock it out:%s/
This is the <Ctrl+R> tool for Command mode, and the usage also includes pasting the current file path: <Ctrl+R>%
. See Help for more usage: :help c_CTRL-R
.
Seven, paragraph jump
This is almost useless for Chinese users, but we can be useful when editing code files. () can be transferred to the end of the first sentence, {} can be transferred to the end of the first paragraph.
Viii. Selection and tail jump
The Emmet plugin can perform HTML tag matching, you press the <c-y>d current label between the end and the end is selected. What do you want to transfer to the tail of the selected area? Press O to toggle closure, press V again to return to normal mode.
There are wood with special wants to jump between matching brackets! Press%!
Nine, the original automatic completion
If you don't use any vim plug-ins, VIM's auto complement is turned off by default. Vim can also enable powerful automatic completion without introducing plug-ins, and only need to set:
FileType plugin on
set Omnifunc=syntaxcomplete#complete
At any time, pressing <c-x><c-o>
will trigger automatic completion.
Reference: Http://vim.wikia.com/wiki/Omni_completion
Ten, search for a constituency
When you need to select a large section of text, you may want to enter visual mode, and then a regular search. For example, in Markdown, select a # #的内容可以这样操作: Move the cursor to the # #上 to select, press V to enter visual mode, enter/^## to match the next two level heading, and press K to go back to the previous line.
Xi. Copy the current file name
Use: let @"=expand("%")
You can copy the current file name, we can set a shortcut key to this command:
Nnoremap yf:let @f=expand ("%:t") <CR>
nnoremap yp:let @p=expand ("%:p") <CR>
Where YF copies the current file name to the Register F,YP copy full file path to register p. Then press "FP" and "pp" to paste separately.
12, not sensitive to case-insensitive search
You can add \c to any location in the pattern to perform case-insensitive searches, add \c to any location, and write case sensitive searches. You can set the set ignorecase to default to case insensitive searches, and you can set the set Smartcase: Ignore ignorecase settings when the pattern contains uppercase letters.
Summarize
The above is the entire content of this article, I hope this article of these tips can be for everyone's study or work to bring certain help, if you have questions you can message exchange.