Skip to content

Instantly share code, notes, and snippets.

@LanHikari22
Created February 15, 2021 01:17
Show Gist options
  • Save LanHikari22/6b568683d81cbb7a2252fac86f6f4a4b to your computer and use it in GitHub Desktop.
Save LanHikari22/6b568683d81cbb7a2252fac86f6f4a4b to your computer and use it in GitHub Desktop.
Remap vim-surround to 'z' to allow vim-sneak to use 's' in operator mode
" documentation and source are credited to https://github.com/mgarort
" Make vim-sneak mappings more consistent in visual mode by making s go to next match and S
" go to previous match, while keeping vim-surround functionality through z
" (mnemonics: vim-zurround) Explained in this GitHub issue:
" https://github.com/justinmk/vim-sneak/issues/268
"
" So now the behaviour is:
" - Normal: s and S to move with sneak
" - Visual: s and S to move with sneak, z to surround (zurround)
" - cs and ds: change/delete matching characters (), [], {}... with
" vim-surround
let g:surround_no_mappings= 1
xmap <S-s> <Plug>Sneak_S
xmap z <Plug>VSurround
nmap yzz <Plug>Yssurround
nmap yz <Plug>Ysurround
nmap dz <Plug>Dsurround
nmap cz <Plug>Csurround
omap s <Plug>Sneak_s
" S mapped with v to make it inclusive, similarly to other backward motions in
" my config (0 mapped to v0, ^ mapped to v^, etc)
omap S v<Plug>Sneak_S
@LanHikari22
Copy link
Author

Credits: mgarort/dotvim#1

@mgarort
Copy link

mgarort commented Feb 15, 2021

Great! Thanks for making a gist.

Kudos to @ggandor too since I learnt about g:surround_no_mappings from him.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment