1

In classic Vi/Vim when I opened a previously unopened file with ctrlp, NERDTree, etc. and the current file/buffer was unsaved, it would open the new file in a horizontal split.

After switching to Neovim, this functionality worked. Then after installing telescope.nvim this behavior ceased. I uninstalled telescope and the desired behavior began again until here in the last day or so.

Now if I don't to save a file and open a new one, then :q I get an error about an unsaved buffer. The previous horizontal split behavior was preferable. How do I get this back? I have included a link to my dotfiles which includes my original .vimrc for vim classic and my lua config for Neovim.

Edit/Update:

A simple .vimrc with

set nocompatible

produces this behavior. However an larger init.vim or init.lua with supress this behavior. I'm confused

webermaster
  • 121
  • 5
  • Would it be possible for you to provide the simplest init.vim or init.lua to reproduce the problem? It would also help to have a step by step description of the "old" behavior on Vim with again the simplest vimrc file. I must admit that I don't know how you get the "old" behavior (some screenshot could help too) :-|. – Vivian De Smedt Mar 13 '24 at 08:38
  • I update the question with the contents of a minimal .vimrc. Open a file with :edit, make a change but do not :w Then :edit another file or ``:Ex` to open netrw and you'll see the unsaved buffer preserved and the new file/netrw opened in a split – webermaster Mar 13 '24 at 13:00
  • I'm afraid I can't reproduce the behavior (if :set hidden? is set no nohidden I can open a new buffer in the main split if the main split buffer is not saved). With a simple vimrc you suggest the :Explore command is not available). I'm afraid we need more information about the minimal vimrc you are using :-| – Vivian De Smedt Mar 13 '24 at 13:11
  • just tested, the same content in t init.lua does not do the same for nvim. I'm confused as to how it was working in the first place – webermaster Mar 13 '24 at 13:11
  • The :Sexplore let you open the new buffer in a new horizontal split. Maybe :Explore as been replaced by :Sexplore in your "old" system at least when the current buffer was not saved. – Vivian De Smedt Mar 13 '24 at 13:15
  • Or :split is replacing :edit. – Vivian De Smedt Mar 13 '24 at 13:26
  • is there a way I can alias this or something in my nvim config? – webermaster Mar 13 '24 at 13:27

2 Answers2

1

After much experimentation, classic vim sets nohidden by default. Neovim sets hidden by default.

a set nohidden or lua equivalent fixed the issue.

webermaster
  • 121
  • 5
  • I believe this is only true for NERDTree not for :e or :Explore. Do you confirm? If so maybe could you adapt your question. – Vivian De Smedt Mar 13 '24 at 13:46
  • I confirmed for :edit, and Ex. I guess I should also do thisd for ctrlp and/or telescope as that is where I saw the behavior change; after installing telescope while trying to enable ThePrimegen/harpoon – webermaster Mar 13 '24 at 14:37
  • Could your precise what you mean by I confirm for :edit and :Ex? Do you mean that :edit and :Ex have the same behavior as :NERDTree (opening a split when the current buffer is modified and the hidden option is not set)? I my tests it is not the case. Maybe NERDTree is hijacking Ex? – Vivian De Smedt Mar 13 '24 at 14:56
  • A typically useful way to debug these things is to apply How to debug my vimrc, though in this case you'd also want to include things from the output of :set and from https://neovim.io/doc/user/vim_diff.html#vim-differences – D. Ben Knoble Mar 13 '24 at 21:00
  • 1
    @VivianDeSmedt I'm seeing the same behavior between :edit, :Ex, ctrl-p, and NERDTree.

    However when I install telescope, instead of opening a split like the others above, it opens the new buffer in the background, and the unsaved file remains in the current unsplit window. Working on that bit now.

    – webermaster Mar 14 '24 at 03:28
  • Interesting. I can't reproduce that behavior myself at least for :edit (but I do with :Explore, NERDTree or CtrlP) – Vivian De Smedt Mar 14 '24 at 15:23
  • Maybe could you accept your own answer. It allow the question to rest :-) – Vivian De Smedt Mar 21 '24 at 06:33
0

The following code introduces the Ex command

function! Explore()
  if !&hidden && getbufinfo(bufnr('%'))[0].changed
    Sexplore
  else
    Explore
  endif
endfunction

command! Ex call Explore()

This new Ex command triggers :Sexplore if:

  • The current buffer is modified and
  • The hidden option is off

and :Explore otherwise.

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37