2

In Vim you can travel to a given line by entering vim's command mode and enter that given line's number there.

I want a specific operation to always take place after moving to a line number in that way.
How do I do that?

This is intended to adjust the screen, by the way.

john-jones
  • 7,490
  • 18
  • 53
  • 86

1 Answers1

3

Normally you enter either of the following in order to jump to line #123 in command mode:

123G
123gg

You just need to find a key to map your new command to (I would recommend using the leader key, which was created for exactly this purpose):

noremap <LEADER>G G:YourCommand<CR>
noremap <LEADER>gg gg:YourCommand<CR>
" Now you can type 123\G instead (assuming you
" have not changed your default leader key)

Or, you can overwrite the existing key (not recommended, as it might mess up other scripts):

noremap G G:YourCommand<CR>
noremap gg gg:YourCommand<CR>
Community
  • 1
  • 1
soulmerge
  • 73,842
  • 19
  • 118
  • 155
  • Thank you, that helped. 'map G Gsk' now means my screen always gets adjusted automatically when moving using G. – john-jones Aug 17 '12 at 10:54