我有一个函数,无论什么时候它被分割的窗口,并显示一些信息,把光标放在这个新的窗口。
到现在为止还挺好。
但是我正在实现一个autocommand
,它将触发相同的function,除非游标不会像使用自动命令一样运行时,不会改变到打开的窗口。
触发此行的行如下所示:
autocmd! BufWritePost *.py call MyFunction()
就像我说的那样,当你手动: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, ie, 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-\>\<Cn> to guarantee " we're in Normal mode before using window " movement key combo call feedkeys("\<C-\>\<Cn>\<cw>j", 'n') endfunction