# Surround on tex files

I have both vimtex and surround plugins installed(and ultisnip if matters). When doing surround in visual mode (using S) on a tex file, and when I press \ next I get immediately \begin. I am not sure how to change this. I want to surround by \{ sometimes.

(S in visual mode mapped to <plug>VSurround)

This behavior is from vim-surround. From its source code, pressing either l or \ will result in \begin.

To change the default behavior, refer to :h surround-customizing.

• First, find the number corresponding to \. In this case, we would find it with :echo char2nr("\\"), which gives 92.

• Then, declare the variable corresponding to this number. In this case, this would be

let g:surround_92 = "\\{ \r \\}"


If you prefer not to have a space betweeen the surroundings and the surrounded text, use

let g:surround_92 = "\\{\r\\}"


In the above, \r is the placeholder for the surrounded text.
Note that since our surroundings contain \, we have to escape it by doubling the backslash.
Also, since this is specific to .tex files, it is better to use b:surround_92 instead of g:surround_92.