tpope / vim-surround

surround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease
https://www.vim.org/scripts/script.php?script_id=1697
13.47k stars 445 forks source link

Switch to get LaTeX command instead of environment functionality for \ similar to < for XML tag #42

Open bpj opened 12 years ago

bpj commented 12 years ago

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.

tpope commented 12 years ago

Why not just have 2 different targets? There's no shortage of them.

A concise prompt does sound slick.

doronbehar commented 6 years ago

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}"