I have a large body of LaTeX text (a whole book) which has \textit{} and \textbf{} commands interchanged in some places. In other places they are completely missing. How do I create quick shortcuts in Vim so that I can do the following:

  • Switch between \textit{} to \textbf{} and vice versa without affecting what is inside {}.
  • Wrap word or phrase under cursor into either of the \textit{} or \textbf{} commands.
  • Remove either the \textit{} or \textbf{} commands where they are not needed but put in by mistake.

1 Answer 1


If you use the vimtex plugin, you can:

  1. Change an enclosing command using csc:

    enter image description here

  2. According to the help, a ysc corresponding to the commands offered by surround.vim isn't available, but can be added. See :h vimtex-faq-surround:

    Q: |vimtex| provides `dse`, `dsc`, `cse`, and `csc`.  These seem to be inspired by
       |surround.vim|.  Does |vimtex| also provide the corresponding `yse` and `ysc`?
    A: The mentioned mappings are indeed inspired by |surround.vim|.  However,
       |vimtex| does not provide `yse` and `ysc`.  If you use |surround.vim|, then
       the asked for mappings may be easily added if one adds the following lines
       to ones `vimrc` file: >
      augroup latexSurround
         autocmd FileType tex call s:latexSurround()
      augroup END
      function! s:latexSurround()
         let b:surround_{char2nr("e")}
           \ = "\\begin{\1environment: \1}\n\t\r\n\\end{\1\1}"
         let b:surround_{char2nr("c")} = "\\\1command: \1{\r}"
  3. Delete an enclosing command using dsc.

  • Thanks, I will check it out and let you know how it worked out.
    – Ketan
    Commented Feb 4, 2016 at 2:30
  • 4
    I just want to mention that the current support for commands is only very simple. This is because it is really quite hard to parse LaTeX/TeX commands, i.e., how can I know the number of arguments to a specific command? (Answer: I can't, if I don't know the command definition.) Thus csc only works if the cursor is on the actual command or the first argument. Commented Feb 4, 2016 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.