Question

I've opened a file and modified it - now I want to do :Explore without splitting.

It splits - because I have an unsaved buffer. By default this is nice, becasuse Vim generally doesn't allow to switch files, until you do something with the modified buffer (save or discard changes).

But I have set hidden option, so I can jump from buffer to buffer, switch files and everything - and save or not when I feel I want to. It seems Netrw doesn't follow this policy. How could I help it?

One way I know of is to map netrw explore to save & explore, but I'm not sure if autowriting is a good way of doing things... I am actually using other autowriting settings now, but I was just rethinking to maybe get rid of them.

Was it helpful?

Solution

So here is the function, that does just that:

function! ExploreWithHidden()
    let s:cw = getcwd()
    lcd %:p:h
    enew
    Explore
    cd `=s:cw`
endfunction

Seems to work like expected.

OTHER TIPS

You could use :Texplore instead. This is the same as explore except in a new tab (and will have no splits).

:h Texplore


Another thing you could do is use :lcd %:p:h to change the current working directory to the directory of the file. Then use :enew to create another buffer then open explore. (Make sure hidden is on if the buffer is modified)

:command! BExplore :lcd %:p:h | enew | Explore

To run the command use :BExplore.

The old buffer will be sitting in the background and the explore window is pointing at the directory the file was in.

You could just upgrade your netrw -- its up to v153s at http://www.drchip.org/astronaut/vim/index.html#NETRW, and it does avoid the split if the modified buffer is hidden.

tpope's vim-vinegar operates like this. It maps - to Explore the current file's directory. (That's the same key netrw uses to go up one directory.) It uses the current window instead of splitting.

When the current file is modified:

  • If you have 'hidden' set, it will not split and Explore from the current window.
  • If you do not have 'hidden' set, it will issue an error and do nothing.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top