2

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.

Luigi
  • 866
  • 13
  • 34
  • 1
    If I were you I would file a change request. This seems like something that should be supported by netrw. Try [vim_use](http://groups.google.com/group/vim_use), the netrw author is active there and will likely respond. – glts Jul 02 '13 at 20:03

4 Answers4

3

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.

Luigi
  • 866
  • 13
  • 34
1

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.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • Thx for answer, but I aim for opening in same window. – Luigi Jul 02 '13 at 19:49
  • The thing about `Explore` is that it opens netrw pointed at directory current file exists in. Creating a new buffer and doing `Explore` opens it pointing at current working directory. Same result as doing `:e.`. I was thkining however about something along these lines - like doing a split and closing previous window, but I don't know how to 'close previous window'. – Luigi Jul 02 '13 at 20:20
  • Very close fit, thank you. I think I have to make it a function, to store cwd in a var, and after doing `Explore` bring it back. Or maybe there is a trickier way of doing that? – Luigi Jul 02 '13 at 20:32
  • @Luigi you might be able to do something with `:cd -` but I'm not sure – FDinoff Jul 02 '13 at 20:43
1

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.

user21497
  • 1,061
  • 8
  • 9
0

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.
idbrii
  • 10,975
  • 5
  • 66
  • 107