I just remapped some keys in my .vimrc
and I'm getting some wierd behavior.
When I select text in visual mode, and hit the delete key, it surrounds the highlighted text with ""...
Here's the relevant pieces of my .vimrc
"Using Vundle
Bundle 'tpope/vim-surround'
let mapleader= ","
let g:mapleader= ","
set backspace=eol,start,indent
"""""""""""""""""""""""""""""""""""""""""""""""""""
" => Surround Vim Shortcuts
"""""""""""""""""""""""""""""""""""""""""""""""""""
vmap ' S'
vmap " S"
vmap { S{
vmap } S}
vmap ( S(
vmap ) S)
vmap [ S[
vmap ] S]
" tags
vmap < S<
vmap > S>
" addressing the problem introduced by tags
vnoremap << <
vnoremap >> >
map <leader>s' ysiw'
map <leader>s" ysiw"
map <leader>s( ysiw)
map <leader>s[ ysiw]
map <leader>s{ ysiw}
map <leader>d' yss'
map <leader>d" yss"
map <leader>d( yss)
map <leader>d[ yss]
map <leader>d{ yss}
vmap <Leader>S <Plug>VSurround
Example:
def persisted?
false
end
# I select it in visual mode, hit delete and it becomes:
"def persisted?
false
end"
I know a lot of this configuration is personal preference so any advice is welcome, but more importantly, why am I getting this behavior?
When I try :verbose map <BS>
I get
s <BS> * b<BS>
Last set from ~/<...>/after/plugin/snipMate.vim
x <BS> "-d
This tells me that there is a Select-mode mapping that will enter a "b" (deleting the selected text and entering Insert mode) followed by an Insert-mode <BS>; the *
means that the b<BS>
will not be remapped; and this mapping is defined by snipMate.vim. There is also a Visual-mode mapping to "-d
. Since there is no *
, it will be remapped.
Something is broken: I cannot figure out where that second mapping comes from.
Maybe if I have the second mapping, so do you. If so, then the "
gets mapped (defined in your vimrc file) to S"
, and I guess that surround.vim does something with that. That more or less explains what you see. I am not sure what mode vim is in after all that, so I am not sure what the -d
at the end will do.
Try :xunmap <BS>
or :xnoremap <BS> "-d
and see if it helps. If so, try putting it at the end of your vimrc file. If that does not work, try putting it inside a VimEnter autocommand.
:help :map
:help map-modes