3

我希望 netrw 资源管理器在打开文件后自动关闭。

例如:

  1. :Lex打开文件资源管理器
  2. 打开文件
  3. 打开后,文件资源管理器会自动关闭。

我试过设置:

autocmd FileType netrw setl bufhidden=wipe

但它不起作用。

其余相关.vimrc设置:

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
4

2 回答 2

1

我从另一个 Stack Overflow 答案(链接如下)中获取了这个片段,并将其添加到 BufWinEnter 事件中以解决这个问题。

" Close after opening a file (which gets opened in another window):
let g:netrw_fastbrowse = 0
autocmd FileType netrw setl bufhidden=wipe
function! CloseNetrw() abort
  for bufn in range(1, bufnr('$'))
    if bufexists(bufn) && getbufvar(bufn, '&filetype') ==# 'netrw'
      silent! execute 'bwipeout ' . bufn
      if getline(2) =~# '^" Netrw '
        silent! bwipeout
      endif
      return
    endif
  endfor
endfunction
augroup closeOnOpen
  autocmd!
  autocmd BufWinEnter * if getbufvar(winbufnr(winnr()), "&filetype") != "netrw"|call CloseNetrw()|endif
aug END

原始答案在这里: https ://vi.stackexchange.com/questions/14622/how-can-i-close-the-netrw-buffer

这个特别是https://vi.stackexchange.com/a/29004

于 2021-09-02T11:48:45.370 回答
-2

尝试使用:Explore, :Sexplore,:Hexplore:Vexplore代替:Lexplore. 主要原因:Lexplore是在一侧或另一侧有一个持久的探索者;当您选择带有<cr>.

于 2020-12-15T23:52:45.097 回答