Setting netrw like NERDTree
nmap <silent> <f2> :NERDTreeToggle<cr>to toggle nerdtree window. How can I do the same with netrw?
nerdtree window is not shown in the buffer list(
:ls). netrw is listed in the buffer list. How can I make it not listed?
:bncommand works but
:bpcommand does not work in the netrw window. Is this a bug?
The 'Vexplore' command opens a vertical directory browser. You can build on this by adding the following code to your .vimrc file to toggle the vertical browser with Ctrl-E (for example):
" Toggle Vexplore with Ctrl-E function! ToggleVExplorer() if exists("t:expl_buf_num") let expl_win_num = bufwinnr(t:expl_buf_num) if expl_win_num != -1 let cur_win_nr = winnr() exec expl_win_num . 'wincmd w' close exec cur_win_nr . 'wincmd w' unlet t:expl_buf_num else unlet t:expl_buf_num endif else exec '1wincmd w' Vexplore let t:expl_buf_num = bufnr("%") endif endfunction map <silent> <C-E> :call ToggleVExplorer()<CR>
The code above tries to open the Explorer window on the left hand side of the screen at all times; I use it with multiple split vertical windows open.
[OPTIONAL] You might like to add the following lines to your .vimrc to improve the browsing experience:
" Hit enter in the file browser to open the selected " file with :vsplit to the right of the browser. let g:netrw_browse_split = 4 let g:netrw_altv = 1 " Change directory to the current buffer when opening files. set autochdir
Vim: you don't need NERDtree or (maybe) netrw, This is because by default netrw doesn't use a tree to display the files/directories, its more like doing an ls but you can configure netrw to print a� IMHO NERDTree has a much cleaner API. Manipulating the tree is a lot saner using NERDTree than Netrw. Although I too agree to this vimcast, and since I like nerdtree better, I have my own fork of vinegar
netrw v150, there's
:Lexplore, which will toggle a
netrw window on the left-hand side.
Using Netrw Instead of NERDTree for Vim, I used nmap <silent> <f2> :NERDTreeToggle<cr> to toggle nerdtree window. How can I do the same with netrw? nerdtree window is not shown in the buffer� The NERDTree Introduction. The NERDTree is a file system explorer for the Vim editor. Using this plugin, users can visually browse complex directory hierarchies, quickly open files for reading or editing, and perform basic file system operations.
Setting netrw like NERDTree - vim - html, Out of the box I feel like Netrw is a horrible experience especially when coming from NerdTree Duration: 15:11 Posted: Feb 24, 2020 how to make netrw set current pwd. let g:netrw_keepdir= 0 in vimrc. start from $HOME dir. launch vim. :Lex and browse to a dir. gn to make it current treetop. cd to make it current pwd [ :pwd shows it's been correctly set for the netrw window] open a file from the netrw listing.
let g:netrw_browse_split = 4 let g:netrw_altv = 1
works best for me.
*g:netrw_browse_split* when browsing, <cr> will open the file by: =0: re-using the same window =1: horizontally splitting the window first =2: vertically splitting the window first =3: open file in new tab =4: act like "P" (ie. open previous window) Note that |g:netrw_preview| may be used to get vertical splitting instead of horizontal splitting.
I think the best behavior is described by option 4. By pressing enter, file is opened on the other split, avoiding an overpopulation of splits.
Vim: Is Netrw A Better Alternative To NerdTree, I dug around in the documentation and found a couple of built-in settings for netrw that made it look and feel relatively close to NERDTree. First,� nerdtree-git-plugin. A plugin of NERDTree showing git status flags. The original project git-nerdtree will not be maintained any longer. Installation. Use your favorite package manager. Here is the example of using vim-plug
Here is my version of toggle function, based on Nick's answer. Now you can use hotkey from any pane, not only from netrw's pane. In Nick's version it causes an error, also I did some code cleanup and remap it to Ctrl-O, because Ctrl-E is used by default to scroll down by one line.
" Toggle Vexplore with Ctrl-O function! ToggleVExplorer() if exists("t:expl_buf_num") let expl_win_num = bufwinnr(t:expl_buf_num) let cur_win_num = winnr() if expl_win_num != -1 while expl_win_num != cur_win_num exec "wincmd w" let cur_win_num = winnr() endwhile close endif unlet t:expl_buf_num else Vexplore let t:expl_buf_num = bufnr("%") endif endfunction map <silent> <C-O> :call ToggleVExplorer()<CR>
Variable "t:expl_buf_num" is global for current tab, so you can have one Explorer per tab. You can change it to "w:expl_buf_num" if you want to be able to open Explorer in every window.
Keep focus in Explorer
Also I like to have this at my .vimrc:
" Open file, but keep focus in Explorer autocmd filetype netrw nmap <c-a> <cr>:wincmd W<cr>
Ellen Gummesson • Make netrw really behave like Nerdtree, Maybe I just don't know what Nerdtree is for? What's it's main idea? Do the people who use it just not realize that netrw has a tree view setting? 30 comments I was wondering why [neo]vim doesn't have something similar. It would be quite� Suggested options to behave like NERDTree:" absolute width of netrw window let g:netrw_winsize = -28 " do not display info on the top of window let g:netrw_banner = 0 " tree-view let g:netrw_liststyle = 3 " sort is affecting only: directories on the top, files below let g:netrw_sort_sequence = '[\/]$,*' " use the previous window to open file let g:netrw_browse_split = 4
Why does NerdTree exist? What's wrong with netrw? : vim, I have let g:netrw_browse_split = 4 in my vimrc under the comment "These settings cause Netrw file explorer to behave more like NERDTree"�
Replace netrw window when opening a file, Whilst NerdTree is indeed great, after using splits in Vim constantly and and the like or just look at a directory structure and that's when I use NETRW. toggle I then setup the directories I needed in my .vimrc like this:
Vim File Navigation and Bookmarking with NETRW, Setting netrw like NERDTree. I used nmap <silent> <f2> : NERDTreeToggle<cr> to toggle nerdtree window. How can I do the same with netrw?
- Do not forget to look at preview before posting question or answer. You got all
- I would complement/put together Nicks answer with: "resize" vi.stackexchange.com/questions/10988/toggle-explorer-window/…
- Awesome! Thanks for this.
- After opening a file, and toggling (to close), line 7 gives an error:
E16: Invalid range: 2wincmd w, Vim 8.0.4. Any ideas how to resolve?
- Nice! Much better than a custom function.
- After opening a file, toggling gives the error:
line 8: E16: Invalid range: 2wincmd w. In fact this gives the error whenever toggling when the explorer isn't the active window. Possible some problem with VIM8?
- If you want filetype-based highlighting, check gitlab.com/bimlas/vim-high
- Yep - I now do this myself, and have updated my answer accordingly.
- Great solution! Have you noticed the flash of the file contents before rendering the NETRW pane? Do you have an idea of what could be? Thanks again!
- @betoharres this is probably due to Vim's bell. Here's how to deactivate it (set it to "visual" then tell it to do nothing)
- I like your function, been using it a while! However, you don't want to remap <c-o>, that's opposite of <c-i> (pair of mappings I use a lot). Last, you remap <c-a> in any filetype, try that instead!