Netrw open files into tabs in opposite vertical window
Asked Answered
P

3

8

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!

Palecek answered 2/2, 2013 at 18:41 Comment(0)
B
8

Almost got it with some .vimrc remaps and options.

It looks like this https://i.sstatic.net/eDblz.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.

Bodnar answered 28/1, 2015 at 12:25 Comment(4)
Is it possible to open up this sidebar at vim load? autocmd VimEnter * :Vexplore giving different netrw.Ami
@Ami yes, just split the autocmd over two lines autocmd VimEnter * rightbelow 20vs and then autocmd VimEnter * e . right below itBodnar
Thank You, upvoted! Works great! This code is one of the nicest netrw solutions! 1. One more thing that bugs me is, if I open a new file in a new tab, it's still opens a netrw itself. Is it possible to set not open a new netrw at every new tab, when you open a file with ENTER or CTRL+ENTER? 2. Is it possible to create a shortcut to open a new file in the background? It would be useful to open up really fast bunch of files in the background, without netrw.Ami
@Ami to open a file in a new tab without netrw, just hit t. To open a file in the same tab and automatically close netrw, you will need a new map. Something like nmap <silent> b <CR>:wincmd l<CR>:q<CR> then just hit b. I don't know how to open a file in "the background"... maybe a map to a function that saves the current tab number in a variable, opens the file in a new tab and then moves back to the original tab would do.Bodnar
N
2

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.

Neilneila answered 3/2, 2013 at 0:41 Comment(0)
L
1

As romainl said, tabs are not files (or buffers). So, if I re-interpret your question to mean: "I want to press t and have files appear in the opposite window...". Then I suggest reading :help netrw-C. If you really do mean "append" and not "appear", then that's more involved and before I expend the effort to figure out how to do so I'd like to know that that's what you really meant. The latest netrw (as of today, that's v153f) has additional options which are mentioned in that help reference I gave above.

Lighterage answered 30/5, 2014 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.