Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know 0 goes to the beginning of line and $ goes to the end, but is there something for the middle?

share|improve this question

3 Answers 3

up vote 6 down vote accepted
:call cursor(0, len(getline('.'))/2)
share|improve this answer
This would be fairly useful if it were mapped, e.g: :nnoremap gm :call cursor(0, len(getline('.'))/2)<cr> –  Heptite Nov 29 '10 at 22:55
virtcol('$')/2 is enough. –  Luc Hermitte Nov 30 '10 at 1:34
@Luc Hermitte: Nice, but not exactly the best behavior when hard tabs are involved. –  ephemient Nov 30 '10 at 3:54
That's why I use virtcol instead of col. :). But indeed we should use | and not cursor(). BTW, len() won't give any better result. Moreover, len will give other troubles with multi-bytes characters. –  Luc Hermitte Nov 30 '10 at 9:05

Here is a solution that will respect hardtabs, and multi-bytes characters as well.

:exe 'normal '.(virtcol('$')/2).'|'
share|improve this answer

Typing gm would do it, but it moves by screen lines. In order to get it working in with text lines, one can remap this command:

map gm :call cursor(0, virtcol('$')/2)<CR>
share|improve this answer
gm seems to move cursor to middle of screen, but if my line of text is shorter than the length of the screen, it doesn't take me to the middle. Sorry for not clarifying. –  teggy Nov 29 '10 at 20:56
@teggy: I see. I modified my solution to remap gm to go to the middle of text line. As you can see, it combines solutions from ephemient and Luc Hermitte. –  JooMing Nov 30 '10 at 9:55
As ephemient pointed out, it still has an issue with hard tarbs as cursor() counts them as one character each. Moreover, it won't work with multi-bytes characters either. –  Luc Hermitte Nov 30 '10 at 10:24
+1 for noting a builtin command –  Cheezmeister May 21 '14 at 18: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.