Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netrw open files into tabs in opposite vertical window

Tags:

vim

netrw

Imagine I have :Vex after starting vim. I want to be able to press t and have the tabs appended to the opposite window rather than the Netrw window. Is this possible?

If I press P I can open the file into the split window but I would like to be able to tab through the files in the vertical split whilst having my Netrw window visible - just like Sublime or Komodo.

Possible?

And yes, I've scoured :h netrw!

like image 499
HankHendrix Avatar asked Feb 02 '13 18:02

HankHendrix


2 Answers

Almost got it with some .vimrc remaps and options.

It looks like this http://i.imgur.com/rUf19SF.png

Usage:

  1. run vim.
  2. hit shift enter. this will open netrw as a sidebar (a small split window to the right) and focus it.
  3. browse as usual and hit enter to open a file. this will open it in the left window by default and focus it.
  4. hit control-w control-w. this will focus netrw again.
  5. browse as usual but this time hit control-enter to open a file. this will open it in a new tab that also contains the netrw sidebar.

The .vimrc config:

" netrw magic
" enable mouse usage. makes it easier to browse multiple tabs
set mouse=a
" hide netrw top message
let g:netrw_banner=0
" tree listing by default
let g:netrw_liststyle=3
" hide vim swap files
let g:netrw_list_hide='.*\.swp$'
" open files in left window by default
let g:netrw_chgwin=1
" remap shift-enter to fire up the sidebar
nnoremap <silent> <S-CR> :rightbelow 20vs<CR>:e .<CR>
" the same remap as above - may be necessary in some distros
nnoremap <silent> <C-M> :rightbelow 20vs<CR>:e .<CR>
" remap control-enter to open files in new tab
nmap <silent> <C-CR> t :rightbelow 20vs<CR>:e .<CR>:wincmd h<CR>
" the same remap as above - may be necessary in some distros
nmap <silent> <NL> t :rightbelow 20vs<CR>:e .<CR>:wincmd h<CR>

Caveats:

The netrw "sidebar" in each tab is independent, meaning the current directory in a tab may not be the same in another tab. Suggestions? Thought of using the netrw buffer in every "sidebar" window, but netrw uses a new buffer whenever changing directories.

like image 165
unione Avatar answered Sep 30 '22 19:09

unione


You seem to be confusing Vim's "tabs" with the "tabs" you can find in virtually every other program.

Unlike other implementations, Vim's tabs are not tied to a buffer. In Vim, "tabs" behave like what you would call "workspaces": they are meant to keep together one or more windows. Those windows could display any buffer and you can very well end up with the same buffer displayed in multiple windows in multiple tabs!

With that in mind, it would be very wrong to use them like you want. "Tabs" don't represent files and jumping to another "tab" is not equivalent to jumping to another file at all.

The window created by :Vex is a normal window. Like all the other windows, it is contained in a "tab" and can't live outside of a "tab". And you can't have "tabs" inside of windows.

So, basically, what you ask is impossible.

If you are on a Mac and this "other-editor-like feature" is really important for you (more important than, say, embrace the Vim way), you could try this MacVim fork that adds a "regular" file explorer outside of the buffer/window/tab trio. You could also try PIDA which tries to build an IDE around Vim; including a separate file explorer.

like image 21
romainl Avatar answered Sep 30 '22 20:09

romainl