Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot map asterisk (*) key in VIM correctly

I'm trying to map * for resizing windows like this in my vimrc:
map * <C-W>-
This doesn't work in normal mode but works when using visual mode.
(by pressing <C-W>- manually, it works in normal mode)
Is there a reason why it doesn't work with my mapping? How can I use asterisk in normal mode?

like image 537
Marc C Avatar asked Sep 17 '26 22:09

Marc C


1 Answers

map * <C-W>- is a recursive mapping: if anything in that mapping is already mapped to something else at the time of usage it is that something else that will be executed.

It is generally advised to use non-recursive mappings for most mappings except when you purposely use another mapping in your mapping.

The non-recursive variant of your mapping would be:

noremap * <C-W>-

Note that :map covers normal mode, visual mode, select mode, and operator-pending mode which may have unintended consequences. You should always use the most specific command available, in this case:

nnoremap * <C-W>-
like image 177
romainl Avatar answered Sep 20 '26 18:09

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!