我有以下列表:
[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/