context.vim
context.vim copied to clipboard
Plugin breaks window stack?
I ran into this while using this plugin with https://github.com/pechorin/any-jump.vim but I am able to reproduce it without it.
To reproduce:
- Open a buffer and scroll to a location where the context window shows up.
- Open a new window, for example
:vs test. - Attempt to go back to the previous window with
:wincmd p
Bug: For me, it will not change windows the first time that command is run. This is already a bug. However, when :wincmd p is ran again, it will go to the context window instead of the buffer window.
Tested on this init.vim:
call plug#begin()
Plug 'https://github.com/wellle/context.vim'
call plug#end()
Doesn't seem like there's a fix for this from what I can tell. Workarounds are already used to navigate between buffers for redraws. Is there a way to move windows without affecting the stack, or call commands to modify those windows without navigating to them?
Thanks! I think we could do something similar to here to restore the previous window: https://github.com/wellle/visual-split.vim/blob/master/plugin/visual-split.vim
This also breaks behavior of Ctrl+P (:CtrlPMRUFiles), Nerd Tree and similar when multiple windows are open.
Eg.
- open two windows and let context window appear.
- go to second opened window.
- call for
:CtrlPMRUFilesand choose some file to open
expected: have selected file open in second window
actual: selected file is open in first window
This won't trigger if context window is not opened or context plugin is disabled
Thanks for bringing this back to my attention, I forgot about this.
It seems like what wellle linked was in specific:
https://github.com/wellle/visual-split.vim/blob/423a25911b3e8da04a28d29f205e1059a06e6afa/plugin/visual-split.vim#L147-L152
function! s:reset_previous_window(previous_winnr)
" Switch to remembered window and back again to reset previous window to
" what it was before we overwrote it.
execute a:previous_winnr.'wincmd w'
wincmd p
endfunction
I can integrate this into the context.vim codebase since a quick grep suggests this function isn't being used, and create a PR sometime.
It would be awesome. Please do this, I can test the fix and report.
This bug only happens on Neovim for me. Running Neovim 0.5 and Vim 8.2
I can't get it to work... I keep getting this error
Error detected while processing function context#update:
line 90:
E121: Undefined variable: w:context
E15: Invalid expression: w:context.needs_layout
diff --git a/autoload/context/popup/nvim.vim b/autoload/context/popup/nvim.vim
index af8cf95..e7329c3 100644
--- a/autoload/context/popup/nvim.vim
+++ b/autoload/context/popup/nvim.vim
@@ -50,9 +50,27 @@ function! context#popup#nvim#redraw(winid, popup, lines) abort
" NOTE: because of some neovim limitation we have to temporarily switch to
" the popup window so we can clear the highlighting
" https://github.com/neovim/neovim/issues/10822
+
+ " As a result we also need to reset the previous window. Code adapted from
+ " visual-split.vim
+ let win_count = winnr('$')
+ if win_count > 2
+ wincmd p
+ let previous_winnr = winnr()
+ wincmd p
+ endif
+
execute 'noautocmd' bufwinnr(buf) . 'wincmd w'
call clearmatches()
+
+ " Reset previous window
wincmd p
+
+ if exists('previous_winnr') && previous_winnr != winnr()
+ wincmd p
+ execute previous_winnr.'wincmd w'
+ wincmd p
+ endif
endfunction
function! context#popup#nvim#close(popup) abort
I've tried different variations of the above. I think it has something to do with autocmds running.