Vim 移动到主键和结束键上文本的开始和结束
我希望只需按Vim 移动到主键和结束键上文本的开始和结束,vim,Vim,我希望只需按和即可移动到行的非空白文本的开头和结尾。我已经用启动并运行了它: " <home> goes to the beginning of the text on first press and to the " beginning of the line on second press. It alternates afterwards. nn <expr> <home> virtcol('.') - 1 <= indent('.') &
和
即可移动到行的非空白文本的开头和结尾。我已经用
启动并运行了它:
" <home> goes to the beginning of the text on first press and to the
" beginning of the line on second press. It alternates afterwards.
nn <expr> <home> virtcol('.') - 1 <= indent('.') && col('.') > 1 ? '0' : '_'
“在第一次按下时转到文本的开头,然后转到
“第二次按下时,行的开头。之后轮换。
nn病毒醇('.')-11?'0' : '_'
但我就是无法让它在
中运行:
" <home> goes to the beginning of the text on first press and to the
" beginning of the line on second press. It alternates afterwards.
nn <expr> <home> virtcol('.') - 1 <= indent('.') && col('.') > 1 ? '0' : '_'
“在第一次按时转到文本的末尾,并转到行的末尾
“第二次印刷。
nn virtcol('.')
当我按下
时,光标不移动。但是如果我随后按:
,则会显示文本:,.+x
,其中x
是上述表达式的返回值。此命令在行之间移动,而不是在我想要的列之间移动
有人能告诉我在第二种情况下我做错了什么吗?需要注意的是,我必须说我已经配置了
virtualedit=all
,这意味着我可以将光标移动到一行文本的长度之后。问题在于,映射只返回当前行最后一列的编号或窗口的宽度,但实际上并没有移动光标
您可以使用$
和|
在行上移动光标:
:nn <expr> <end> virtcol('.') == virtcol('$')-1 ? winwidth(0)-1.'\|' : '$'
:nn virtcol('.')==virtcol('$')-1?winwidth(0)-1。“\\”:“$”
要在第一次按时到达非空白文本的末尾,您可以尝试g
()
“在第一次按时转到非空白文本的末尾
“在第二次按压时,移动到该行的末尾。
:nn virtcol('.')==searchpos('.*\zs\S','n')[1]?winwidth(0)-1.“\\”:“g”
要查找最后一个非空白文本的位置,可以使用
函数(返回带有匹配的行和列位置的列表-因此需要追加searchpos()
仅获取列的编号(列表的第二个元素)李>[1]
表示非空白字符\S
设置匹配的开始\zs
表示前面的所有字符,尽可能多*
" <end> goes to the end of the non-whitespace text on first press
" and to the end of the line on second press.
:nn <expr> <end> virtcol('.') == searchpos('.*\zs\S','n')[1] ? winwidth(0)-1.'\|' : 'g_'