Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just got the idea that I wanted to make it so that Vim centered around a line when I jump to it.

Is there a way to make zz be executed automatically after I have called the colon command followed by only digits (:175 for example)?

share|improve this question
I'd use normal mode only 175Gzz – Bernhard Apr 19 '13 at 9:45
You can actually just use 175zz. – Random832 Apr 19 '13 at 12:44
up vote 1 down vote accepted

You can override normal-mode commands (like [N]G) with :nnoremap, but there's no hook for Ex commands (like the peculiar :[N]). Your only options are a hook on the CursorMoved event:

:autocmd CursorMoved * normal! zz

but that would affect all jumps, or a custom command, e.g. :[N]J, but that's even more typing.

Best re-teach yourself to use G (it's shorter, too!) and use this mapping:

:nnoremap <expr> G (v:count ? 'Gzz' : 'G')
share|improve this answer
Sweet! I've only used G to go to the end of the document before. Thanks a lot! :) – professorsloth Apr 19 '13 at 11:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.