junegunn / fzf.vim

fzf :heart: vim
MIT License
9.53k stars 582 forks source link

Opening files via FZF results in relative line numbers being disabled, even when using the latest neovim #503

Open yorickpeterse opened 6 years ago

yorickpeterse commented 6 years ago

Using the latest version of neovim (0.2.1) it seems FZF still has some issues with disabling relative line numbers. To test this I used the following config:

set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
call plug#end()

set number
set rnu

autocmd VimEnter * PlugClean! | PlugUpdate --sync
autocmd TermOpen * setlocal nonumber nornu

The TermOpen autocmd is present to disable line numbers for terminal windows. Using this config (or my actual config for that matter) will result in relative line numbers being disabled when opening a split via FZF. For example:

  1. Go to a directory with a bunch of files
  2. Open a file the normal way, observe how rnu is working
  3. Type :Files and search for a file, then hit C-V to open a vertical split
  4. Observe how rnu is disabled and instead we're left with just regular line numbers

This is using fzf.vim commit 4b9e2a03fe8389da852b0059bd7d0dfffd380956 and fzf commit 2cd0d4a9f7a0a0a86c1ee70da9fb970ec18eac50.

yorickpeterse commented 6 years ago

Here's a somewhat clumsy recording to showcase this: https://asciinema.org/a/WzTx9FzTxWjScCQrYTQlKpPFK

yorickpeterse commented 6 years ago

This doesn't appear to happen when removing autocmd TermOpen * setlocal nonumber nornu, but then you're left with line numbers enabled in terminal windows.

yorickpeterse commented 6 years ago

Note that this only happens when you open a split. If you open a file the normal way then rnu is left as-is.

yorickpeterse commented 6 years ago

Neovim version v0.2.2-35-g30a21830d suffers from the same problem unfortunately.

yorickpeterse commented 6 years ago

You can somewhat work around this by doing the following:

Get rid of the autocmd TermOpen, then add the following somewhere in your vimrc:

function! s:openTerm(vertical)
  let cmd = a:vertical ? 'vnew' : 'new'
  exec cmd
  term
  setlocal nonumber nornu
  startinsert
endfunction

command! Term call s:openTerm(0)
command! Vterm call s:openTerm(1)

You can then open terminals using :Term / :Vterm without line numbers, while FZF will continue to work as you'd expect.

myobie commented 3 years ago

@YorickPeterse can you try to restore your own config, but using the TerminalWinOpen event instead? For example:

autocmd TerminalWinOpen * setlocal nonumber norelativenumber

This works for me to open terminal (even with ++curwin) without line numbers without fzf.vim messing with my line number config for buffers.