如何在Vim中快速引用/取消引用单词并更改引用(例如从“到”)?我知道环绕的事。vim插件,但我想只使用vim。


当前回答

对于VSCodeVim、Neovim和Macvim的用户,可以这样做

vwS"

你可以用你想用的任何东西来代替“”。 你可以用任何其他选择运算符替换w

其他回答

环绕。Vim是最简单的答案。如果你真的反对使用它,这里有一些你可以做的例子。不一定是最有效的,但这就是为什么要环绕。Vim写完了。

Quote a word, using single quotes ciw'Ctrl+r"' ciw - Delete the word the cursor is on, and end up in insert mode. ' - add the first quote. Ctrl+r" - Insert the contents of the " register, aka the last yank/delete. ' - add the closing quote. Unquote a word that's enclosed in single quotes di'hPl2x di' - Delete the word enclosed by single quotes. hP - Move the cursor left one place (on top of the opening quote) and put the just deleted text before the quote. l - Move the cursor right one place (on top of the opening quote). 2x - Delete the two quotes. Change single quotes to double quotes va':s/\%V'\%V/"/g va' - Visually select the quoted word and the quotes. :s/ - Start a replacement. \%V'\%V - Only match single quotes that are within the visually selected region. /"/g - Replace them all with double quotes.

这个怎么样?

 :%s/\'/"/g

在单词的周围加上引号:v i w S '

视图:选择光标下的单词 S:添加周边 ':单引号

将'改为":c s ' "

c:改变环境 ':单引号 :改为双引号

这里有一些简单的映射,可以用来引用和取消引用一个单词:

" 'quote' a word
nnoremap qw :silent! normal mpea'<Esc>bi'<Esc>`pl
" double "quote" a word
nnoremap qd :silent! normal mpea"<Esc>bi"<Esc>`pl
" remove quotes from a word
nnoremap wq :silent! normal mpeld bhd `ph<CR>

在选定的文本块周围添加单引号的可视化模式映射示例:

:vnoremap qq <Esc>`>a'<Esc>`<i'<Esc>