简体   繁体   中英

vim vnoremap: E488 Trailing characters

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM