首页 > 解决方案 > 在 gVim 中插入特定字符串而不是制表符或空格

问题描述

由于我在 vim 中使用 LaTeX 文档,因此我希望能够在\quad按下制表符时插入而不是制表符空间(而不必手动替换/插入它们)。有没有可以做到这一点的设置?如果没有,有没有像这样工作的插件?

标签: vimvim-plugin

解决方案


While you can use inoremap to change Tab to \quad in insert mode, that means that you lose the original Tab functionality...

This might be worth it if you're sure that you'll never want to use Tab, but what will you do when you face a similar problem of wanting some latex-specific text? You could try and find a second key to map... but each addition will take up a new key that already had some function.

The way I would handle this would be to use iabbrev to map some unlikely sequence of keys like ;q to \quad:

iabbrev ;q \quad

This has the advantage that you can build up a whole set of insert mode abbreviations, all consistently starting with ; followed by a letter or two that you can choose to be easily remembered. And you get to keep all the original functionality.


推荐阅读