我想做这样的事情:我选择一段文本,然后按 Ctrl-B,所选文本被 ** 或我选择的其他符号包围。我在想,如果我能以某种方式标记选择的开始和结束位置,我可以将 Ctrl-B 映射到视觉模式下的某个组合键,在这些标记上移动并放置所需的文本。
我怎样才能这样做呢?
无需定义您自己的映射 - Tim Pope 的环绕.vim https://github.com/tpope/vim-surround就是为这种事情而生的!该插件提供了映射,可以轻松删除、更改和添加文本周围的环境。
In your case, after you've made your selection in visual mode, just type S*, and your code will be surrounded by asterisks.
Surround commands work with standard motions, and in normal mode as well. If you want to change the surrounding characters (say, from *
to '
), you can do cs*'.
The README https://github.com/tpope/vim-surround#surroundvim涵盖了许多值得尝试的通用案例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)