vim - 运行 ex 命令以在正常模式下从函数转到行
我有一个在 InsertEnter autocmd 上运行的函数设置。在函数中我想跳到特定行。
所以到目前为止我已经尝试过(简化)的是:
function JumpToLineBeforeScroll()
echom "function runs"
exe ":10"
return ""
endfunction
autocmd InsertEnter * call JumpToLineBeforeScroll() | set cul
我使用 mode()
验证了该函数运行时它处于正常模式(如果错误,请纠正我)。函数运行但行跳转不起作用。我该如何让它发挥作用?
注意:我实际上想要实现的是在插入模式下鼠标滚动,切换到正常模式,保存当前行号,然后滚动。然后,一旦我按 i
再次进入插入模式 (InsertEnter
),我想跳回到滚动之前的最后一行。因为这需要一些条件,所以我想将其保留在函数中,而不是在 autocmd
行本身中编写整个代码。
谢谢!
I have a function setup to run on InsertEnter autocmd. In the function I want to jump to a specific line.
So what I have tried (simplified) is this so far:
function JumpToLineBeforeScroll()
echom "function runs"
exe ":10"
return ""
endfunction
autocmd InsertEnter * call JumpToLineBeforeScroll() | set cul
I verified using mode()
that while this function runs it is in normal mode (pls correct me if wrong). Function runs but the line jump is not working. How do I get this to work ?
Note: What I am actually trying to achieve is on mouse scroll while in insert mode, switch to normal mode, save the current line number and then scroll. Then once I press i
to enter insert mode again (InsertEnter
) I want to jump back to the last line I was on before scroll. As this would need some conditionals I want to keep this in a function instead of writing the entire code in the autocmd
line itself.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以
gi
存在:)现在在了解
gi
并意识到:normal
的工作原理之后,我已经达到了这个配置,它完美地适合我的用例。事实证明autocmd
实际上并不需要,因为:startinsert
也存在:)我仍在使用
didScroll
因为我并不总是想要每当我按i
时,都会执行gi
操作。如果这是设置,则正常模式下的任何导航都将毫无意义,因为当输入返回插入时我将返回到同一行。So
gi
exists :)Now after learning about
gi
and realising how:normal
works, I've reached this config which works for my usecase perfectly. And turns outautocmd
is not actually needed for this as:startinsert
also exists :)I'm still using
didScroll
since I dont always want to do agi
whenever I pressi
. If that's the setup any navigation in normal mode would be pointless as I would be back to same line when enter back insert.