doctopus
doctopus

Reputation: 5647

Why does netrw open file in a small vertical split only on the first time explorer is opened?

Problem:

  1. Open Vim
  2. Type :Lex to open netrw file explorer and open a file in a vertical split using v
  3. As you can see in the image below, the space allocated to the split is tiny.
  4. This only happens on the first time netrw file explorer is opened. If I close the file explorer and follow step 2 again and open a file again using v, I get the expected behaviour as shown in the 2nd image below.

.vimrc settings:

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_altv = 1
let g:netrw_winsize = 25
noremap <C-x> :Lex<CR>
autocmd FileType netrw setl bufhidden=wipe

Actual behaviour: enter image description here

Desired behaviour: enter image description here

Upvotes: 5

Views: 1441

Answers (2)

Igor Linder
Igor Linder

Reputation: 11

:Iexplore sets the g:netrw_chegwin variable so that all subsequent :Explore split commands will also open the selected buffer on the same window as :Lexplore

If you use :Lex, the variable g:netrw_chegwin gets set to 2, and even after you close the :Flex window, the variable remains set.

So if, for example you use :Sex after using :Lex, the file that you select will open in the window that was being used by :Lex, which is probably not what you want.

To make :Explore splits behave as they normally do, you can reset by:

let g:netrw_chgwin = -1

Upvotes: 0

Igor Linder
Igor Linder

Reputation: 11

You need to select an open directory as working

add in your expression: %:p:h

  • % - current file name
  • :p - expand to full path
  • :h - head (last path component removed)

ex:

nnoremap <leader>dd :Lexplore %:p:h<CR> 

Upvotes: 0

Related Questions