1

I'm trying to edit my init.vim to allow quick, custom retabbing with one key. My current attempt is as follows (the replace text in the last command is a tab character inputted in insert mode):

nnoremap <C-i> :%s/\s\+$//ge<CR>:%s/ \{2,}/ /ge<CR>
vmap <C-i> :'<,'>s/\s\+$//ge<CR>:'<,'>s/ \{2,}/ /ge<CR>

The normal mode map works perfectly, but I can't figure out why the visual map doesn't. The only thing it does is report:

E488: Trailing characters

Why doesn't the visual map work the same way as the normal mode map, and is what I'm attempting impossible?

2

The '<,'> in your first command get inserted automatically when entering : from visual mode. Remove them.

  • 1
    Also you don’t need vmap; just vnoremap – D. Ben Knoble Jul 15 at 23:27
  • 1
    xnoremap to map only visual mode without mapping select mode. See :h map-modes – Peter Rincker Jul 16 at 15:54
  • @PeterRincker agreed – D. Ben Knoble Jul 16 at 16:17
  • Thanks! My retabbing works now! – Joe Egan Jul 18 at 16:29

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.