I start GVIM in not-maximized window mode and split its window horizontally making sure the windows are equally sized. How can I preserve this equal-sized split view when I maximize the main GVIM window? Whenever I maximize GVIM forgets that the windows have been equally split.
Thanks.
The command to equalize splits is ^W= (ctrl-W =), or in a script, wincmd =.
To do this automatically, you can use:
autocmd VimResized * wincmd =
Related
I use a lot of tabs in my Vim workflow, and each tab may have several splits in them. I recently discovered in Preserving equal sized split view that having this line in my vimrc helps will automatically make my splits equally sized.
autocmd VimResized * wincmd =
However, it only seems to resize the current tab I'm on if I resize the window that Vim is in. For other tabs, the splits are still unequally sized. Is there a way to automatically resize the splits in all tabs when the window size changes?
You can use the :tabdo command to execute the sequence In all existing tabs. This already gets the job done:
autocmd VimResized * tabdo wincmd =
There's one possibly undesirable side effect though, it will end the command on the last tab. You can work around that by saving it and restoring it after the end of the command. It's easier to do so by defining a function.
function! ResizeWindows()
let savetab = tabpagenr()
tabdo wincmd =
execute 'tabnext' savetab
endfunction
autocmd VimResized * call ResizeWindows()
I changed my .vimrc file to automatically open two windows once I fire
$vim my_file.py
So in my .vimrc file I added following lines
vnew previewwindow
The problem is that I want to automatically modify each window and resize them in .vimrc and taking out the line numbers from previewwindow.
I know in vim I can switch between windows by +w but I do not know any Vim command that does so.
Is there any command such as :selectnext or :selectw previewwindow !? so the focus would switch to other window then I could apply every window specific commands.
Is there any command in vim that it accepts combined keystrokes as an argument so I can easily use that command with combined keystroke symbol to be implemented in .vimrc
In my case any command such as :sendkey( w) will work for me !?
In addition I am wondering how can I prevent a window to become smaller than a certain width and height (like minimum values for w and h)?
Thanks
You can prepend any window movement command with :wincmd. E.g. to move the cursor to the next window you would execute:
:wincmd w
See :help window-move-cursor
You're looking for :wincmd, so to switch to the next window (<C-W><C-W>), you'd use :wincmd w. This is a special command for window commands; in general, you can use :normal to execute normal mode commands, so :execute "normal! \<C-w>\<C-w>" would be equivalent here.
Consider I have a NERDTree window and more then 2 file view windows are opened in vim. In this case a common way to switch to NERDTree (navigating with several Ctrl+w g/h/j/k) is not very handy as it is not universal for all the open windows.
Is there a way to switch to NERDTree (or any other, may be) window directly?
<C-w>t
should do what you want.
You can make a mapping to do this:
nnoremap <silent> <Leader>t :NERDTreeFocus<CR>
Depending on your window layout, if NERDTree is near the top-left corner, it may have a fixed window number (:echo winnr() will tell you). You can then use [N]<C-w><C-w> to go to window number [N].
If your layout is more dynamic, it might make sense to include the window number in your 'statusline':
:set statusline+=\ %{winnr()}
Setup: MacVim with MiniBufExplorer plugin window spanning the entire top and Taglist plugin window on the right.
Due to the fact that I keep my Taglist on the right, whenever I open the quickfix window, it is positioned on the far right, below the Taglist window (with the same width as the Taglist window)
Is it possible to change the default opening position logic, so that the quickfix window will open below my main code window (down and to the left) or maybe span the entire width at the bottom of the Vim viewport?
While it is not possible to change the default split-window behavior
of the :copen command, one can approach the issue in two ways.
1. Use the commands that directly alter window splitting directions
(see :help :vertical and below until the “Closing a window” paragraph).
For instance, consider the commands:
:botright copen
or
:botright cwindow
to make the quickfix window open as the bottommost one, or even:
:vertical topleft cwindow
to open it to the top left of the current window.
These commands can be shortened to :bo cope, :bo cw, and :vert to cw, respectively. Also, one can, of course, create a short mapping or
a custom command for their quick invocation.
2. Alternatively, move the quickfix window to the bottom of the window
layout using an auto-command:
:autocmd FileType qf wincmd J
This trigger takes advantage of the fact that the quickfix window can
be easily distinguished by its file-type, qf. The wincmd J command
is equivalent to the
[Ctrl+W,
Shift+J]
shortcut sequence instructing Vim to move the current window to the
very bottom of the screen (see :help :wincmd and :help ^WJ).
By default, Vim opens the new window above the current one for horizontal splits, and to the left of the current one for vertical splits (:help opening-window). You can customize this behavior like most other things in Vim:
make the new window appear below the current window.
:set splitbelow
make the new window appear on the right.
:set splitright
I want have both NERDTree and TagList open at the same time, but I don't need for them to have the whole height of the screen. Instead I would like to have them split horizontally within a single vertical split.
More specifically, I want to be able to open one, say NERDTree, and have it take up the full height of the screen. Then when I open TagList, to have it horizontally split with the already open NERDTree window.
Is there a way to do this? Possibly even a non 'specific to these two plugins' way?
NERDTree and Taglist aren't going to open inside splits.
Let's say you have a split buffer on the left (for eg. source code), and Taglist on the right.
You can put this in a function, and invoke it with a mapping:
NERDTree " open NERDTree
wincmd J " move NERDTree to the very bottom
wincmd k " move the cursor to the above split (the source code buffer)
wincmd H " move the split to the very left
wincmd l " move the cursor back to the NERDTree split
resize 20 " resize the split height to 20
exe 'vertical resize ' . g:NERDTreeWinSize " reset the split width
This is pretty dodgy, but it works. You'll see a brief visual glitch while the split jumps around the screen.
Horizontal split:
:split
Vertical split:
:vsplit
Then when you have split your screen how you prefer, open nerdtree inside the desired frame.
(Or you can use abbreviation :sp :vsp like suggested by #Vivek Pandey).
I've posted a solution in a duplicate post here:
NERDTree & TList in
It involves editing the 'taglist.vim' script a bit to add a new split option when opening.