Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor jumps to start of vim buffer (if fugitive and projectionist installed) #1164

Closed
5 tasks done
edwardsnjd opened this issue Nov 4, 2020 · 10 comments
Closed
5 tasks done

Comments

@edwardsnjd
Copy link

Problem / Steps to reproduce

Thanks for this great tool! This issue seems to be an interaction between fzf.vim, vim-fugitive and vim-projectionist. I am posting the issue here first because it is triggered when running a fzf command. I'll cross-post it to those other projects if this doesn't jump out as an issue with fzf.

Problem

fzf.vim commands work as expected but when the fzf window is closed, the cursor in the buffer has jumped to the top. This only happens if the vim-fugitive and vim-projectionist vim plugins are also installed and enabled.

Steps

  1. Install vim-plug
  2. Install vim-fugitive, vim-projectionist, fzf and fzf.vim plugins (see below for a minimal .vimrc to repro)
  3. Open a buffer and move the cursor so it's not at the first character
  4. Run :Maps (or any of the other built in fzf commands) to open a fzf window
  5. Close the fzf window (Ctrl-c)
  6. Check the cursor position

Expected: The cursor is where you left it.

Actual: The cursor is at the start of the buffer.

(The following screen capture shows the issue, then how disabling one of the tpope plugins seems to fix the issue.)

2020-11-04 23 21 15

Environment

  • OS: OS X
  • Shell: bash
  • Vim: Huge vim without GUI (see below for version output)
  • Terminal emulator: Reproduced in iTerm2, Alacritty, and Terminal.app

Minimal .vimrc:

set nocompatible

call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-projectionist'
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
call plug#end()
Vim version
$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 24 2020 22:29:54)
macOS version
Included patches: 1-1900
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              +perl              +title
-clientserver      +job               +persistent_undo   -toolbar
+clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       +lua               +ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              -mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -lintl -framework AppKit  -L/usr/local/opt/lua/lib -llua5.3 -mmacosx-version-min=10.15 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.32.0/lib/perl5/5.32.0/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc  -L/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -lpython3.9 -framework CoreFoundation  -lruby.2.7 

Similar issues

These issues seemed similar but didn't describe my issue:

@Terr
Copy link

Terr commented Nov 24, 2020

Thanks for finding out that fugitive and projectionist are the cause of this. I'm having the same issue and I also have both those plugins installed. And, indeed, it only happens when both plugins are enabled.

My environment: Linux and macOS, Vim 8.2.2035 (self-compiled) and using ZSH + tmux as a shell (but it also happens in a plain sh).

I think it started after fzf switched to using a popup window. Everything works fine in fzf v0.22.0 but no longer in v0.23.0

@civrot
Copy link

civrot commented Nov 27, 2020

I am having the same issue, but just when projectionist is enabled. Fugitive doesn't seem to cause any issues for me.

@edgarjs
Copy link

edgarjs commented Dec 6, 2020

I noticed this when trying out the FZF layout as window. But if I leave it as down it doesn't happen.

@ivanbrennan
Copy link

Sounds like this may be the same issue, and one step closer to the root cause: vim/vim#5820

@nathandrewts
Copy link

Thanks @edgarjs – moving it to down solved it for me.

I added let g:fzf_layout = { 'down': '~40%' } to my ~/.vimrc file 👍

srsudar added a commit to srsudar/dotfiles that referenced this issue Feb 4, 2021
Without this, I was getting problems with the vim popup window scrolling
to the top using fzf. Absolute wizard responsible for figuring this out:

junegunn/fzf.vim#1164
@srsudar
Copy link

srsudar commented Feb 4, 2021

Wow, great job figuring that out. I just removed vim-projectionist because I wasn't using it, but what a strange error. Thanks.

mmrwoods added a commit to mmrwoods/vim-projectionist that referenced this issue Apr 2, 2021
Vim patch 8.2.0413 enables BufFilePre and BufFilePost autocmds for
terminal buffers. This causes the cursor to jump to the start of the
current buffer when projectionist is enabled and a terminal popup window
is created, for example by either the FZF.vim or vim-floaterm plugins.

Terminal popup windows are created by starting a hidden terminal buffer
and then creating a popup to show that terminal buffer. Projectionist's
BufFilePost autocmd is now triggered for these hidden terminal buffers,
and somewhere along the line this causes the cursor to jump to the top.

I'm not sure exactly what causes this cursor jump, but one workaround is
to add a condition to the autocmd to only call ProjectionistDetect if
the autocmd file name refers to a file that actually exists/isreadable.

This seems reasonable to me, so this commit just adds that condition.

More information:
vim/vim#5820
junegunn/fzf.vim#1164
tpope#155
mmrwoods added a commit to mmrwoods/vim-projectionist that referenced this issue Apr 2, 2021
Vim patch 8.2.0413 enables BufFilePre and BufFilePost autocmds for
terminal buffers. This causes the cursor to jump to the start of the
current buffer when projectionist is enabled and a terminal popup window
is created, for example by either the FZF.vim or vim-floaterm plugins.

Terminal popup windows are created by starting a hidden terminal buffer
and then creating a popup to show that terminal buffer. Projectionist's
BufFilePost autocmd is now triggered for these hidden terminal buffers,
and somewhere along the line this causes the cursor to jump to the top.

I'm not sure exactly what causes this cursor jump, but one workaround is
to add a condition to the autocmd to only call ProjectionistDetect if
the autocmd file name refers to a file that actually exists/isreadable.

This seems reasonable to me, so this commit just adds that condition.

More information:
vim/vim#5820
junegunn/fzf.vim#1164
tpope#155
@edwardsnjd
Copy link
Author

Sounds like this may be the same issue, and one step closer to the root cause: vim/vim#5820

It looks like the underlying Vim issue has just been closed by this patch 👏:
vim/vim@1e6bbfb

(I haven't confirmed the behaviour yet.)

@mmrwoods
Copy link

mmrwoods commented Apr 4, 2021

@edwardsnjd I've just tested the latest vim from github and it does fix this problem :-)

mmrwoods added a commit to mmrwoods/vim-projectionist that referenced this issue Apr 4, 2021
Vim patch 8.2.0413 enables BufFilePre and BufFilePost autocmds for
terminal buffers and also introduces a minor bug affecting nested
autocmds, which causes the cursor to jump to the start of the current
buffer when projectionist is enabled and a terminal popup window is
created, for example by either the FZF.vim or vim-floaterm plugins.

More information:
vim/vim#5820
junegunn/fzf.vim#1164
tpope#155

Though this bug has now been fixed in vim, it may take a while to make
its way though to package repositories and onto peoples' machines, so
this commit works around the issue for now by simply avoiding calling
ProjectionistDetect for terminal buffers. It does this by checking that
the autocmd file name refers to a file that actually exists rather than
checking that the &buftype is "terminal" because the &buftype has not
been set to "terminal" at the time the BufFilePost autocmd is triggered.
mmrwoods added a commit to mmrwoods/dotfiles that referenced this issue Apr 5, 2021
Workaround for terminal popup cursor jump issue, cursor jumps to start
of buffer when using FZF.vim with a terminal popup window (the default).

More information:
vim/vim#5820
junegunn/fzf.vim#1164
tpope/vim-projectionist#155
@pbnj
Copy link

pbnj commented May 20, 2021

I can second @mmrwoods that after updating vim (brew upgrade vim), the problem is fixed for me as well.

@edwardsnjd
Copy link
Author

@pbnj @mmrwoods Thanks for following up. Yep, I also agree that Vim has resolved the underlying issue now. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants