Is it possible to make the surround plugin work on `TeX-style quotes' and ``TeX-style double quotes''? (Normally, if `this is quoted'| and `this', va' will select from the first closing mark to the second (if the cursor is at |).)


2 Answers 2


You can create a customize surround by defining a variable g:surround_{key code}

So for example you could do

let g:surround_96 = "`\r'"

Where 96 is the key code for `. You can make this more readable by putting by letting vim determine the key code by using

let g:surround_{char2nr("`")} = "`\r'"

\r will be replaced by the relevant text. If you only want this to work in tex files you can put it in an autocmd

autocmd FileType tex let b:surround_{char2nr("`")} = "`\r'"

Usage would be ysiw`. Read :help surround-customizing

  • thanks! Two follow up quæstions: (1) I suppose to delete with ds' one has to replace of of the marks to match the other first? (2) What is the difference between using autocmd FileType … (in .vimrc?) and putting the command in .vim/after/tex.vim ?
    – Toothrot
    Oct 10, 2015 at 10:42
  • @Lawrence (1) Most likely. (2) autocmd FileType is closer to placing the commands in .vim/ftplugin/tex.vim I don't think tex.vim would even get sourced in that location. The after director is normally for overriding command in the standard runtime (or plugins you don't want to edit)
    – FDinoff
    Oct 10, 2015 at 13:31
  1. An alternative choice of characters are q and Q which do not overwrite a builtin surrounding (`):

    autocmd FileType tex let b:surround_{char2nr("q")} = "`\r'"
    autocmd FileType tex let b:surround_{char2nr('Q')} = "``\r''"
  2. (IMPORTANT) However, you cannot delete or change custom surroundings of vim-surround. Intuitively one would try dsq or csQq which do not work. Also dot-repeat is not as convenient since you have to enter again q.

    If you want to have this, consider switching to the plugin vim-sandwich. The default mappings are little bit different: saiwl' would add `text', srbl" would change it to ``text'', and sdb would remove them again. sa, sr, sd for add, replace and delete surrounding. l' for latex single quotation marks, l" for latex double quotation marks. It also defines a text-object (default ib), to allow for convenient selection with vib what the OP has asked. It can be repeated to extend the selection with vibib....

  3. A convenience feature of vim-surround which is not well known is following shortcut: use the change command to actually add a surrounding to a word, WORD, sentence or paragraph with one of the special target specifiers [wWsp]. To surround the current paragraph with a quotation the command is cspQ.

    :h surround-targets

    The letters w, W, and s correspond to a |word|, a |WORD|, and a |sentence|, respectively. These are special in that they have nothing to delete, and used with |ds| they are a no-op. With |cs|, one could consider them a slight shortcut for ysi (cswb == ysiwb, more or less).

    A p represents a |paragraph|. This behaves similarly to w, W, and s above; however, newlines are sometimes added and/or removed.

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.