2

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?

1 Answer 1

3

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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