Super User is a question and answer site for computer enthusiasts and power users. 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 know 0 goes to the beginning of line and $ goes to the end, but is there something for the middle?

share|improve this question
up vote 8 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

Here is the best solution that I have found. Jumping exactly to the middle of the line is not very practical. You will most likely still need to move the cursor a few positions after moving to the middle. What if you could jump to a specific character? Many people just search for the character, then hit "next" until they reach it. This is slow. The Easy-motion plugin offers a better solution.

My favorite is <leader><leader>s then the character you want to jump to. Easy Motion replaces all matches with different letters for you to choose from. See the tutorial. Its a life-changing plugin...

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .