Reputation: 12371
I'm using vim to program and I just want to make a shortcut for comment.
Here is how I set in .vimrc
:
vnoremap <F7> :%s/^/\/\//g
I just want to add //
in front of each selected line. However, when I press <F7>
and press Enter
in visual mode, I get an error:
E488 Trailing characters
Upvotes: 0
Views: 1578
Reputation: 12795
Note that when you press F7
it just simulates pressing all the keys in the string. As soon as it presses :
it gets into a state
:'<,'>
When it then types in all the rest of your command it gets into:
:'<,'>%s/^/\/\//g
Which is meaningless (%
after '<,'>
doesn't make sense). If you just remove %
from your command, it will already work. Even better, add <CR>
at the end so that you don't need to press Enter:
vnoremap <F7> :s/^/\/\//g<CR>
Upvotes: 1