Search code examples
vimvim-plugin

Insert a specific string instead of tabs or spaces in gVim


Since I'm working with LaTeX documents in vim, I want to be able to insert \quad instead of a tab space whenever I press tab (instead of having to replace/insert them manually). Is there any setting that could do this? If not, are there any plugins that work like this?


Solution

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