How do you create a vim key mapping that requires numbers before the hotkey (like <G>)?

9

1

I want to create a mapping like the G hotkey that jumps to a line (e.g., to jump to line 10: 10G). How can I do that?

Belmin Fernandez

Posted 2012-04-10T15:55:17.553

Reputation: 2 691

Answers

13

You can obtain that number from the v:count or v:count1 variable. See

:help v:count

For example,

:map G :<C-U>echo v:count<CR>

garyjohn

Posted 2012-04-10T15:55:17.553

Reputation: 29 085

1Perfect. Got me down the right path. Needed to use exe though: nmap <tab> :<C-U>exe "buffer ".v:count<CR> – Belmin Fernandez – 2012-04-10T16:45:52.020