在 vim 中转到行的中间

teg*_*ggy 16 vim

我知道 0 到行首, $ 到行尾,但是中间有什么东西吗?

eph*_*ent 14

:call cursor(0, len(getline('.'))/2)
Run Code Online (Sandbox Code Playgroud)

  • 如果它被映射,这将非常有用,例如: :nnoremap gm :call cursor(0, len(getline('.'))/2)<cr> (4认同)
  • virtcol('$')/2 就足够了。 (4认同)

Joo*_*ing 10

打字gm可以,但它会按屏幕线移动(请参阅 参考资料:help gm)。为了让它与文本行一起工作,可以重新映射此命令:

map gm :call cursor(0, virtcol('$')/2)<CR>
Run Code Online (Sandbox Code Playgroud)


Luc*_*tte 7

这是一个将尊重硬标签和多字节字符的解决方案。

:exe 'normal '.(virtcol('$')/2).'|'
Run Code Online (Sandbox Code Playgroud)