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


当前回答

用单引号括起来(例如)ciw'<C-r>"'<esc>可以,但重复就不行。试一试:

ciw'<C-r><C-o>"'<esc>

这将默认寄存器的内容“逐字”放置。现在你可以按了。任何一个词都要加引号。要了解更多信息,请参阅:h[elp] i_ctrl-r和关于:h text-objects文本对象的更多信息

来源:http://vimcasts.org/episodes/pasting-from-insert-mode/

其他回答

引用一个词,使用单引号 被'Ctrl + r”

这样做对我来说比较容易

ciw '' Esc P

环绕。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.

用单引号括起来(例如)ciw'<C-r>"'<esc>可以,但重复就不行。试一试:

ciw'<C-r><C-o>"'<esc>

这将默认寄存器的内容“逐字”放置。现在你可以按了。任何一个词都要加引号。要了解更多信息,请参阅:h[elp] i_ctrl-r和关于:h text-objects文本对象的更多信息

来源:http://vimcasts.org/episodes/pasting-from-insert-mode/

我使用的是vim-surround命令,本质上几乎是vim。

环绕。vim都是关于“环境”的:圆括号、括号、引号、XML标记等等。该插件提供了映射,可以轻松地成对删除、更改和添加这样的环境。

Plugin 'tpope/vim-surround' 

例如,要完全删除分隔符,请按ds”。 详情如下: https://github.com/tpope/vim-surround

VIM for vscode做得很好。如果你不使用vscode,它是基于一个vim-surround。

一些例子: "test",光标在引号内,类型为cs"',以'test'结束 "test",光标在引号内,类型ds",以test结束 "test",光标在引号内,输入cs"t,然后输入123>结束 < 123 >测试 用光标在单词上测试测试类型锯)结束于(测试)