哪些 Vim 命令可用于引用/取消引用单词? [英] What Vim command(s) can be used to quote/unquote words?

查看:38
本文介绍了哪些 Vim 命令可用于引用/取消引用单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Vim 中快速引用/取消引用单词并更改引用(例如从 '")?我知道 surround.vim 插件,但我只想使用 Vim.

How can I quickly quote/unquote words and change quoting (e.g. from ' to ") in Vim? I know about the surround.vim plugin, but I would like to use just Vim.

推荐答案

surround.vim 将是您最简单的答案.如果你真的反对使用它,这里有一些你可以做的例子.不一定是最有效的,但这就是编写环绕.vim 的原因.

surround.vim is going to be your easiest answer. If you are truly set against using it, here are some examples for what you can do. Not necessarily the most efficient, but that's why surround.vim was written.

  • 引用一个词,使用单引号
    ciw'Ctrl+r"'
    • ciw - 删除光标所在的单词,并以插入模式结束.
    • ' - 添加第一个引号.
    • Ctrl+r" - 插入 " 寄存器的内容,也就是最后一个 yank/delete.
    • ' - 添加结束引号.

    • 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.

      • di' - 删除单引号括起来的单词.
      • hP - 将光标向左移动一个位置(在开头引用的顶部)并将刚刚删除的文本放在引用之前.
      • l - 将光标向右移动一个位置(在开头引用的顶部).
      • 2x - 删除两个引号.

      • 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.

      • 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.

      这篇关于哪些 Vim 命令可用于引用/取消引用单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆