1

How do I disable vim-surround in visual (selection) mode?

IE. If I hit shift+S I want to replace all the lines I have currently selected ( the normal vim functionality )

  • 1
    :h v_S is the same as :h v_s if current visual mode is linewise. – dedowsdi Dec 11 '19 at 23:43
3

You can simply unmap it just as any other mapping in Vim. But if doing this from vimrc you have to delay the unmap until the plugin was actually loaded. If using Vim8 builtin :h packages that happens after your vimrc has been processed. Therefore some additional steps must be taken. The rest is how to deal with this particular problem.

There are several ways to do so.

0) Actually, you can tell the plugin to disable all builtin mappings and create ones you really use manually:

    let g:surround_no_mappings = 1
    " copied from plugin/surround.vim
    nmap ds  <Plug>Dsurround
    nmap cs  <Plug>Csurround
    nmap cS  <Plug>CSurround
    nmap ys  <Plug>Ysurround
    nmap yS  <Plug>YSurround
    nmap yss <Plug>Yssurround
    nmap ySs <Plug>YSsurround
    nmap ySS <Plug>YSsurround
    " ----- remove these -----
    "xmap S   <Plug>VSurround
    "xmap gS  <Plug>VgSurround
    imap    <C-S> <Plug>Isurround
    imap    <C-G>s <Plug>Isurround
    imap    <C-G>S <Plug>ISurround

1) Unmap on VimEnter:

    augroup vimrc_unmap | au!
        autocmd VimEnter * ++once xunmap S
        autocmd VimEnter * ++once xunmap gS
    augroup end

2) Force early plugin load and then unmap it:

    packadd vim-surround
    xunmap S
    xunmap gS

3) "Polish" your setup from after/plugin/ subdirectory

~/.vim/after/plugin/final.vim

    " delete superfluous vim-surround mappings
    xunmap S
    xunmap gS
  • Thanks, I actually must have switched to vim-sandwich so the 3) solution using only xunmap S did the trick. Thanks! packadd didn't seem to ever work.. I use Plug 'machakann/vim-sandwich' to load it. – Funkodebat Dec 13 '19 at 2:46
  • Oh nvm, I can just run xunmap S right in vimrc. plug loads it early enough. Cool. – Funkodebat Dec 13 '19 at 2:48
  • @Funkodebat You have to force plugin load if using Vim8 builtin :h packages (or a minimalistic plugin manager built on top of it, such as minpac, vim-packager etc.). Otherwise you should consult your plugin manager documentation to find out if it delays plugin load or not, and how to change this. – Matt Dec 13 '19 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.