vim - 如何在vim列表中的单词之间添加引号?

标签 vim vi

我有以下列表:

[torunn,sentry,moonstone,avispa,phil coulson]

是否可以使用Vim将其更改为这样?:

["torunn","sentry","moonstone","avispa","phil coulson"]

最佳答案

vim-surround的帮助下和一个宏,很简单:

我假设您的光标位于第一个字母(在本例中为“t”):qqys/\v,|]<cr>"nlq99@q

让我们一步步分解:

qqys/\v,|]<cr>"nlq99@q
qq               q       # record a macro in the q register
  ys                     # surround something with something
    /\v,|]<cr>           # search for comma or closing bracket
              "          # surround until there with double-quotes
               n         # jump to the next match
                l        # go one to the right
                  99@q   # run the macro 99 times (will stop at first failure)

搜索查询\v,|]刚刚开机v ery magic 模式,然后匹配逗号或 ( | ) 右括号。我们不需要转义括号,因为我们没有打开括号。

关于vim - 如何在vim列表中的单词之间添加引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50646052/

相关文章:

vim - 映射键在 Vim 中的正常模式和插入模式之间切换

vim - 在 VIM 中,如何写入所有( :wa), 但仅用于非隐藏缓冲区?

linux - 为什么我不能 sudo 回显/etc/中的一行?

vim - 在 vim 中聚焦时间缓冲区

bash - 防止 bash vi 多行崩溃

docker - 在 docker 容器的文本编辑器中无法正确显示特殊字符

vim - 如何让特定的文件扩展名表现得像 .vimrc 文件中的 .html?

Vim Split 和 VSplit 行为

linux - 关于 CentOS 或任何 Linux 机器中的可执行路径

vim - Vim高亮显示单词列表