Glam Prestige Journal

Bright entertainment trends with youth appeal.

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

5 Answers

:call cursor(0, len(getline('.'))/2)
4

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

map gm :call cursor(0, virtcol('$')/2)<CR>
3

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

:exe 'normal '.(virtcol('$')/2).'|'

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...

Personally I use:

map g1 :call cursor(0, virtcol('$')/0)<CR>
map g2 :call cursor(0, virtcol('$')/4)<CR>
map g3 :call cursor(0, virtcol('$')/2)<CR>
map g4 :call cursor(0, virtcol('$')/3*2)<CR>
map g5 :call cursor(0, virtcol('$'))<CR>

To center vertically 0% - 25% - 50% - 75% - 100%

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lectus sapien, rutrum quis vestibulum vitae, fringilla ac nisi.

For example if you wanna go to the word 'adipiscing'. Then you press g2w (go 25% + one word).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy