Set default window in Vim for opening all files/buffers - vim

Is it possible in Vim to set a default window for opening all files and buffers there?
Consider the following scenario:
I'm using Netrw and I'm positioned into the window that has the file list. Then I use :buffer or the wildmenu to open a file and it opens right there. I want the file to be opened in a default window, no matter where I'm positioned.
Thanks in advance.

I'm not sure if that's what you are looking for but you can use the :Lexplore command. It opens netrw in a vertical split in the current directory (:pwd). You can then open a file in the other vertical split. I haven't used it much, so I don't know it's exact behavior when you have multiple splits. You can open an additional a vertical split by using v in the netrw buffer.
I have the following mapping which opens netrw in a small vertical split:
nnoremap <silent> <leader>le :Lexplore<bar>vertical resize 30<CR>

Related

How to auto-close vim's initial buffer on file open?

So I'm using ctrlp and nerdtree. I found it troublesome whenever I enter vim, open a file by ctrlp or nerdtree, my cursor always jump to a newly opened window while the initial empty buffer window is still opened, occupying the screen. Then I always have to do <C-w>j <C-w>q -- while I've trained myself to do it with my mechanical memory, I guess there should be some smart ways to auto-close the empty window once any file is firstly opened.
Appreciate all help/tip provided in advance. This is my current .vimrc.
Update:
Thanks #romainl and for NERDTree I've no issue now. I'm checking how to configure ctrlp though.
Pressing enter will open the file in the same window, as #romainl said.
However, another tip: If you want to see only the current window, you can run
:only
which will hide all but the current split (buffers will be hidden)
I have remapped it to <leader>o
" maximize current visible window
nnoremap <Leader>o :only<cr>

how to make Taglist window cannot be placed by opened file

I like Taglist in Vim very much. However, when I open a new file or click the file name in the BufferExplor, the file will display in the Taglist window. Is there method to keep the Taglist window cannot be used to display the file opened? When I open a file, how to use a new window in the Vim?
Thank you!
When you're inside the TagList window, don't use :edit. Either use a command list :split or :vsplit to open the file, or move to another window first (via <C-W><C-W> etc.) The typical layout is a small TagList sidebar to the left, and a big editing area right of it. Move there first.
As to plugins like BufferExplorer, they either need to be able to recognize those "special" windows, or again you have to use the "open in split window" command in them. I personally use custom mappings to toggle such plugins, so that there is only one at a time displayed in the sidebar, thereby avoiding this issue.

in VIM, How to set the initial window size via file browser?

I'm using vim to browse through different folders. (i.e., issue :tabe . command in vim)
However, when I open the file either in split window (pressing 'o') or in vertical split window(pressing 'v'), the newly opened window size is really small. (while meanwhile, vim's file browser's windows stays pretty big which I don't really need).
I know that I can manually change the window size by Ctrl+W with either -/+ or split, or for vertical split, or '=' to make the window sizes equal; but that's too troublesome.
I want to check if there're existing ways to set the default size of the window opened using "o" or "v" to be bigger?
Thanks a lot ;)
The new window should take half of the height or half of the width of the current window which can give you small windows pretty quickly.
The option that defines that proportion can be found in :help netrw:
let g:netrw_winsize = 75
Note that using this method will make any further split even smaller than before:
let g:netrw_winsize = 50 (default)
|-netrw--------------------------------------------|
|-netrw------------------|-file--------------------|
|-netrw------|-file------|-file--------------------|
let g:netrw_winsize = 75
|-netrw--------------------------------------------|
|-netrw------|-file--------------------------------|
|-netrw|-file|-file--------------------------------|
The "problem", here is that netrw splits its own window, not the previous window.
Netrw can be used to open the file under the cursor in the current window, in a split window or in another tab but the way it splits its own window makes it hard to use it the way you want. AFAIK, the most common usage is:
open netrw with :Ex,
navigate,
hit <CR> to open the file under the cursor in the current window,
edit,
re-open netrw in its latest state with :Rex (for Peter Rincker),
GOTO 2
An alternative is to use :Vex to open netrw in a vertical split and use P to open the file in the previous window.
I'm afraid Netrw is not really designed to work like what you seem to want it to work. IMO, netrw is more like an "open…" dialog than the kind of file explorer pane you can see in most editors/IDEs. I'd suggest you either get used to it or try NERDTree which has only a subset of netrw's features but is designed to be more like those file explorer panes.
Actually the split size is not relative to netrw, it's the default size vim sets for newly created splits, so if you want to resize the actual split which is in you case the navigator (netrw) you can use this commend:
:vertical resize 30
There is :Lex now to open a left explorer. You can place let g:netrw_winsize=30 in your vimrc file to keep the explorer small.

Netrw open files into tabs in opposite vertical window

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!
Almost got it with some .vimrc remaps and options.
It looks like this http://i.imgur.com/rUf19SF.png
Usage:
run vim.
hit shift enter. this will open netrw as a sidebar (a small split window to the right) and focus it.
browse as usual and hit enter to open a file. this will open it in the left window by default and focus it.
hit control-w control-w. this will focus netrw again.
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.
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.
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.

Vim NERDTree re-size vsplit

I am using the NERDTree plugin for Vim. When using the s: open vsplit command, is it possible to resize the windows so that the file is taking up a larger portion of the screen than the directory tree?
[EDIT 1]
I have attached a screeshot of my split view using NERDTree:
I have installed NERDTree to ~/.vim
[EDIT 2]
I do not appear to have ~/.vimrc. I have included a screenshot of /etc/vim/.vimrc
You should give more context, like paste your .vimrc and add a screenshot because (what I understand is) the behaviour you want is AFAIK NERDTree's default behaviour.
The only situation I can imagine where a new vertical split would be smaller than NERDTree is when you already have a bunch of vertical splits and Vim is adjusting their width to accomodate the new one.

Resources