vim - How to quickly select a word and surround it with a special character while developing a program?
怪我咯
怪我咯 2017-05-16 16:42:14
0
3
871

For example, there is a word

dcustmsg

I have selected the word in v mode. Is there any shortcut key to add quotation marks on both sides of the word to make it

"dcustmsg"
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
黄舟

The configuration file adds functions and key mappings as follows:

function! s:surround()
    let word = expand("<cword>")
    let wrap= input("wrap with: ")
    let command = "s/".word."/".wrap.word.wrap."/"
    execute command
endfunction
nmap cx :call <SID>surround()<CR>

In this way, place the cursor on the word in normal mode, and then use the shortcut key cx. It will prompt the characters to be filled on both sides. Just enter the characters and press Enter.
For details, please refer to: How to repeatedly add text on both si...

过去多啦不再A梦

You can write a vim macro by yourself
In normal mode, the cursor is placed in the middle of the word
bi"<ESC>ea"<ESC>
Just record the above paragraph as a macro and use it.

習慣沉默

diwi"<C-r>0<Esc> #Cut the string and copy it into double quotes...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template