如何在Vim中快速引用/取消引用单词并更改引用(例如从“到”)?我知道环绕的事。vim插件,但我想只使用vim。
当前回答
这里有一些地图可能会有所帮助:
:nnoremap <Leader>q" ciw""<Esc>P
:nnoremap <Leader>q' ciw''<Esc>P
:nnoremap <Leader>qd daW"=substitute(@@,"'\\\|\"","","g")<CR>P
如果您没有更改mapleader变量,那么使用\q" \q'或\qd激活映射。它们分别在光标下的单词周围添加双引号,在光标下的单词周围添加单引号,在光标下的单词周围删除任何引号。
其他回答
VIM for vscode做得很好。如果你不使用vscode,它是基于一个vim-surround。
一些例子: "test",光标在引号内,类型为cs"',以'test'结束 "test",光标在引号内,类型ds",以test结束 "test",光标在引号内,输入cs"t,然后输入123>结束 < 123 >测试 用光标在单词上测试测试类型锯)结束于(测试)
用引号括住所有单词:
s/\(\w\+\)/"\1"/g
之前:
aaa,bbb,ccc
后:
"aaa","bbb","ccc"
环绕。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:改变环境 ':单引号 :改为双引号
推荐文章
- 如何回到行之前编辑的最后一个在Vim?
- 如何跳转到一个特定的人物在vim?
- 如何删除一个大的文本块而不计算行?
- 在Vim/Vi中,如何将光标移动到前一个单词的末尾?
- 如何在vim中自动删除尾随空格
- 为什么Vim使用~扩展名保存文件?
- 如何在Vim或Linux中将空格转换为制表符?
- 我如何使用vimdiff来解决git合并冲突?
- 在Vim中删除当前缓冲区的文件名/路径
- Git在终端提交时打开VIM,但无法返回终端
- 请参阅编辑器中的换行符和回车
- 如何在NERDTree中显示隐藏文件(以句点开始)?
- 如何复制一个选择到OS X剪贴板
- 如何删除(不削减)在Vim?
- Vim:在可视模式下快速选择文本块的方法