Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
1  
You can actually just use 175zz. –  Random832 Apr 19 '13 at 12:44
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.