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

7
  • 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) :-|. Commented Mar 13 at 8: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 Commented Mar 13 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 :-| Commented Mar 13 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 Commented Mar 13 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. Commented Mar 13 at 13:15

2 Answers 2

1

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

a set nohidden or lua equivalent fixed the issue.

7
  • I believe this is only true for NERDTree not for :e or :Explore. Do you confirm? If so maybe could you adapt your question. Commented Mar 13 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 Commented Mar 13 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? Commented Mar 13 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 neovim.io/doc/user/vim_diff.html#vim-differences
    – D. Ben Knoble
    Commented Mar 13 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. Commented Mar 14 at 3:28
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.