Opening vim with splits, vertical resize not working properly - vim

Im trying to get nvim to open with a vertical split and then two terminals on the right side.
+--------------+
¦ ¦ ¦
¦ file ¦ t1 ¦
¦ ¦-----¦
¦ ¦ t2 ¦
¦ ¦ ¦
+--------------+
However, the autocmd that does :vertical resize only works to enlarge the window, not shrink it. So +20 works, but not -20. Anyone know what the problem might be?
au VimEnter * vsplit
au VimEnter * :wincmd l
au VimEnter * :vertical resize +20

Sorry, I can't add a comment,
My answer does not match your question but may be helpful
Maybe you can try the plugin:
GoldenView
This will resize your active window automatically

Related

How to make Netrw Explorer appears automatically on the left side when opening a new tab

my problem is quite simple, but I can't figure how to solve it. So I wanted to have a tree file explorer, thus I searched and found netrw. Online, I managed to find a good configuration that I modified a little and put in my .vimrc :
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 3
let g:netrw_altv = 1
let g:netrw_winsize = 25
augroup ProjectDrawer
autocmd!
autocmd TabNew * :Vexplore
autocmd VimEnter * :Vexplore
augroup END
So thanks to that, the tree appears when I enter vim, and if I click on a file it opens in a new tab. But in this tab, the content of the splitted screens are inverted : I get the content of the file in the little left screen, and the tree in the large right screen. I tried to modify the .vimrc config, changing Vexplore to Lexplore, but I get the same result... what must I do to get what I want ?
autocmd TabNew * :Vexplore!
Should do the trick.

Netrw <cr> behavior, new split under modified vsplit

I used to use Nerdtree but I am switching to Netrw. In my .vimrc I have:
let g:netrw_browse_split = 4
let g:netrw_altv = 1
autocmd VimEnter * Vex
autocmd VimEnter * set winfixwidth
The Behavior currently is that when I press enter the file will open on the right split which is what I want. This works correctly as long as the buffer remains unmodified. If the buffer is modified, pressing enter in the netrw split brings up a prompt asking me if I want to save.
The behavior I want is that if I have a modified buffer open in the right vsplit, and I press enter on a different file in the netrw split, to open a split in the right vsplit like this:
----------------
|Netrw|Modified|
| | |
| |--------|
| |New |
----------------
Is this possible with Netrw?

Track Active Item in NERDTree

NERDTree has :NERDTreeFind to find the current file in the tree.
How can I make NERDTree update the current file in tree automatically whenever I switch files?
This should do it, but be aware that the frequent updates make switching buffers quite slow:
:autocmd BufEnter * if &filetype !=# 'nerdtree' | NERDTreeFind | wincmd p | endif
The conditional avoids triggering a find if the NERDTree sidebar itself is entered.

Vim put cursor in the middle of screen after buffer switch

When I switch buffer and then go back to it (when I get back to any buffer that was previously opened), cursor is placed in the middle of the screen, loosing previous screen position (e.g. cursor at top of the screen). Maybe this is the normal behaviour of vim, but is there any way to fix this?
This problem happens when I use :bn and bp: to switch buffers. However this behaviour does not happen when switching between tabs which is really strange.
See http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers
" When switching buffers, preserve window view.
if v:version >= 700
au BufLeave * if !&diff | let b:winview = winsaveview() | endif
au BufEnter * if exists('b:winview') && !&diff | call winrestview(b:winview) | endif
endif

How to center horizontally the contents of the open file in vim?

how do I make vim horizontally center the text of the open file?
I don't want to modify the file, just to change the way vim displays it.
To be more clear, when I open a file I currently have this situation:
|<------ textwidth=80 ------->|<-------------- padding -------------->|
|lorem ipsum dolor sit amet..
|dsdsda da dsa dsa
What I'd like to have is the following:
|<--- padding/2 --->|<------ textwidth=80 ------->|<--- padding/2 --->|
| lorem ipsum dolor sit amet..
| dsdsda da dsa dsa
Of course, for every value of textwidth and padding.
Vim isn't meant to be a single, centered document editor (when programming, you want to fill every single pixel with relevant information), so there are only workarounds:
a) You can achieve a larger left margin by expanding the fold column. Unfortunately, this is limited to 12 character cells:
:let &foldcolumn = (&columns - &textwidth) / 2
b) You can create an empty padding window to the left (and potentially also to the right, for symmetry).
:execute 'topleft' ((&columns - &textwidth) / 2 - 1) . 'vsplit _paddding_' | wincmd p
The annoying window split can be cleared with:
:hi VertSplit guifg=bg guibg=NONE gui=NONE
I think you could reach the point using screen.
you can open three different windows tiled vertically with
CTRL+a , SHIFT+|
then move to the second one.
Exist several plugins that allow you to get that look, most of them seem to be inspired by Writeroom editor for MacOS.
See for example this screenshot of the the VimRoom plugin, or just search the web for "vim writeroom plugin".
I use NERDTree for that reason. NERDTree is a file explorer for vim. You can load NERDTree at startup with any width you like:
This is how I run NERDTree at startup to get what you see in the image. I use vim-plug (a package manager for vim) to load NERDTree.
# Load NERDTree Plugin via vim-plug
call plug#begin()
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
call plug#end()
let g:NERDTreeWinSize=60 # Set NERDTree width.
NERDTreeToggle # Open NERDTree at startup.
au VimEnter * wincmd l # Remove focus from NERDTree window at startup.
I was looking for something similar and thanks to #ingo-karkat answer I managed to create a function to toggle the center content on/off.
function! WriteRoomToggle()
let l:name = '_writeroom_'
if bufwinnr(l:name) > 0
wincmd o
else
let l:width = (&columns - &textwidth) / 5
execute 'topleft' l:width . 'vsplit +setlocal\ nobuflisted' l:name | wincmd p
execute 'botright' l:width . 'vsplit +setlocal\ nobuflisted' l:name | wincmd p
endif
endfunction
Suggested options and mappings:
" hide vertical split separator
hi VertSplit guifg=bg guibg=NONE gui=NONE
" Do not resize windows on close (good if you also use NERDTree)
set noequalalways
" toggle writeroom on/off
map <silent><Leader>v :call WriteRoomToggle()<CR>
" delete buffer without closing the window
command! Bdelete if len(getbufinfo({'buflisted':1})) > 1 | bprev | bdelete# | else | bdelete | endif
noremap <Leader>x :Bdelete<CR>

Resources