tpope/vim-surround — Issue #47: request for new surround type: LaTeX command
Author: majewsky
Created: 2012-02-06 14:12:11+00:00
State: open

There is already "ys..l" for surrounding something in a LaTeX environment, e.g. type (from normal mode)

```
ysiwl
center
```

for the effect

```tex
foobar -> \begin{center}foobar\end{center}
```

Similar to "l", I added to my local copy the letter "c" which wraps not in a LaTeX environment, but in a LaTeX command, e.g.

```
ysiwc
textbf
```

has the effect

```tex
foobar -> \textbf{foobar}
```

Here's what I added to s:wrap in my surround.vim, near the code that creates the environments. My code is based on the behavior of "f" as in "function".

```vim
elseif newchar ==# 'c' || newchar ==# 'C'
" LaTeX command
let cmd = input('command: ')
if cmd != ""
let before = substitute(cmd,'{$','','').'{'
let before = '\'.substitute(before,'^\','','')
let after = '}'
if newchar ==# 'C'
let before .= ' '
let after = ' ' . after
endif
endif
```