windows - 在 Vim 的 BufWritePost 上将光标更改为另一个窗口

标签 windows vim split

我有一个函数,无论何时调用它,它都会拆分窗口并显示一些信息,并将光标放在这个新窗口中。

到目前为止一切顺利。

但是我正在实现一个 autocommand,它将触发相同的功能,并且一切正常,除了光标永远不会像未使用自动命令运行时那样更改为打开的窗口。

触发这个的行看起来像:

 autocmd! BufWritePost *.py call MyFunction()

正如我所说,当您手动调用 :call MyFunction() 但使用自动命令时效果不佳。

我认为 Bram 提到过自动命令实际上并不意味着分割窗口甚至移动光标。

有什么办法解决这个问题还是我做错了什么?

最佳答案

按照 ZyX 在对原始问题的评论中所说的,听起来这可行:

function MyFunction()
    [ have all commands you currently have]
    [ . . . ]

    " then as last line include call to feedkeys()
    " this will stuff keystrokes into key buffer
    " and get executed after MyFunction() ends
    " remember that location will always be in 
    " original window, i.e, window that vim
    " was in when autocommand was triggered
    " so if new window is below original
    " window you could use this:

    " feedkeys call below edited to reflect ZyX's
    " improvement of \<C-\>\<C-n> to guarantee
    " we're in Normal mode before using window
    " movement key combo

    call feedkeys("\<C-\>\<C-n>\<c-w>j", 'n')

endfunction

关于windows - 在 Vim 的 BufWritePost 上将光标更改为另一个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6221191/

相关文章:

windows - 在doFirst中的命令行之后跳过Gradle任务执行

c++ - Windows 中的 C++ 何时需要 "extern C "?

windows - 在另一个窗口中运行 Windows 应用程序

python - 拆分字符串并将分隔符保留为拆分字符串 block 的一部分,而不是单独的列表元素

python - 正则表达式在 Python 中拆分单词

c++ - Exe 在 BackupRead Windows 函数中崩溃

git - 在 Vim 中打开文件会打开 vim diff?

linux - 从 vi 编辑器复制一行/多行到命令行

windows - 你如何让一个文件在 Windows 中从 vim 可写?

c# - 在 Windows Phone 中将字符串拆分为多个文本框