vim-surround
vim-surround copied to clipboard
Switch to get LaTeX command instead of environment functionality for \ similar to < for XML tag
If I need to put something into a LaTeX environment it's usually a longer piece -- one or more paragraphs --, and it's anyway most convenient to just open a line, type in the \begin{} line, move down, open another line and type in the \end{} line.
For me a far more common use case is that I'm marking up an existing text and want to surround a smaller text object -- a word/WORD/sentence -- with a command, making the text object the argument of the command. To handle the cases beyond the most common commands I've put the following in my .vimrc:
autocmd FileType tex let b:surround_{char2nr("\\")} = "\\\1\\\1{\r}"
I would like to have a switch to change between the
environment and command argument behavior of the \
target and back. Even if that can't be I hope you put
the above customization as an example in the
documentation, since I believe very many who regularly
mark up text written by others for LaTeX would find it
very useful.
A cosmetic and hence not very important wish would be for the
prompt to appear just as \ similar to < with an XML tag.
Why not just have 2 different targets? There's no shortage of them.
A concise prompt does sound slick.
Technically there is some consistency with the suggested behavior but I agree with @tpope on this, typing \begin{<env>} is pretty long and using 2 different targets as explained here and simplified here could be used directly in ftplugin/tex.vim:
let b:surround_{char2nr("e")} = "\\begin{\1environment: \1}\n\t\r\n\\end{\1\1}"
let b:surround_{char2nr("c")} = "\\\1command: \1{\r}"