I have two opened buffers (i.e. A and B) and one window. Currently I see A, I would like to open B in vertical window. To do it in horizontal window I can hit Ctrl+w ^, how to do it in vertical window? And how to change horizontal windows to vertical windows?
To display your two buffers vertically, you can use :
:vsplit #
or the short version
:vs #
To reorganize your layout from horizontal to vertical, you must use:
<C-W>K : will move the current windows to to the top with a horizontal split
<C-W>J : will move the current windows to to the bottom with a horizontal split
<C-W>H : will move the current window to the the left with a vertical split
<C-W>L : will move the current window to the the rigth with a vertical split
See :help windows.txt for more information
You may use Vertical Split
Ctrl+Wv
command line :vertical split
open a vertical split: :vs
go to that split (assuming it's on the right: CTRL-W l
open buffer B there: :b B
Related
How do I scroll the other window in :vsplit in VIM? I've looked everywhere, but all websites are talking about how to sync both windows to scroll together. I want to look at one file, edit it, while scrolling the other.
I'm fairly (ok, quite) certain there's nothing built in to do this, not least of all because it only makes sense when there are exactly two windows. For that specific case, however, you can use a mapping. Put these in your ~/.vimrc:
nmap <a-j> <c-w>w<c-e><c-w>w
nmap <a-k> <c-w>w<c-y><c-w>w
This will make Alt+J scroll down and Alt+K up, you can change those as you like. If you want it to work with more windows, you'll have to write a script.
" SCROLLING FOR OTHER SPLIT WINDOWS (JUST 2 WINDOWS)
nmap <M-j> <c-w>w<c-e><c-w>wh " Scroll down one line other pane
nmap <M-k> <c-w>w<c-y><c-w>wh " Scroll up one line other pane
nmap <M-d> <c-w>w<c-d><c-w>wh " Scroll down half screen other pane
nmap <M-u> <c-w>w<c-u><c-w>wh " Scroll up half screen other pane
nmap <M-f> <c-w>w<c-f><c-w>wh " Scroll down one screen other pane
nmap <M-b> <c-w>w<c-b><c-w>wh " Scroll up one screen other pane
<M> is Meta, Opt, or Alt key. When I tested the shortcut, my cursor in the current window go forward 1 character. So I ended mapping the bindings with h. But these work whenever you don't reach the first or last line of your other pane or the cursor will just switch to your current pane then start scrolling.
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.
How can you switch your current windows from horizontal split to vertical split and vice versa in Vim?
I did that a moment ago by accident but I cannot find the key again.
Vim mailing list says (re-formatted for better readability):
To change two vertically split
windows to horizonally split
Ctrl-w t Ctrl-w K
Horizontally to vertically:
Ctrl-w t Ctrl-w H
Explanations:
Ctrl-w t makes the first (topleft) window current
Ctrl-w K moves the current window to full-width at the very top
Ctrl-w H moves the current window to full-height at far left
Note that the t is lowercase, and the K and H are uppercase.
Also, with only two windows, it seems like you can drop the Ctrl-w t part because if you're already in one of only two windows, what's the point of making it current?
Ctrl-w followed by H, J, K or L (capital) will move the current window to the far left, bottom, top or right respectively like normal cursor navigation.
The lower case equivalents move focus instead of moving the window.
When you have two or more windows open horizontally or vertically and want to switch them all to the other orientation, you can use the following:
(switch to horizontal)
:windo wincmd K
(switch to vertical)
:windo wincmd H
It's effectively going to each window individually and using ^WK or ^WH.
The following ex commands will (re-)split any number of windows:
To split vertically (e.g. make vertical dividers between windows), type :vertical ball
To split horizontally, type :ball
If there are hidden buffers, issuing these commands will also make the hidden buffers visible.
In VIM, take a look at the following to see different alternatives for what you might have done:
:help opening-window
For instance:
Ctrl-W s
Ctrl-W o
Ctrl-W v
Ctrl-W o
Ctrl-W s
...
Horizontal to vertical split
Ctrl+W for window command,
followed by Shift+H or Shift+L
Vertical to horizontal split
Ctrl+W for window command,
followed by Shift+K or Shift+J
Both solutions apply when only two windows exist.
After issuing the window command Ctrl+W, one is basically moving the window in the direction indicated by Shift+direction letter.
Opening help in a vertical split by default
Add both of these lines to .vimrc:
cabbrev help vert help
cabbrev h vert h
cabbrev stands for command abbreviation.
:vert[ical] {cmd} always executes the cmd in a vertically split window.
Inspired by Steve answer, I wrote simple function that toggles between vertical and horizontal splits for all windows in current tab. You can bind it to mapping like in the last line below.
function! ToggleWindowHorizontalVerticalSplit()
if !exists('t:splitType')
let t:splitType = 'vertical'
endif
if t:splitType == 'vertical' " is vertical switch to horizontal
windo wincmd K
let t:splitType = 'horizontal'
else " is horizontal switch to vertical
windo wincmd H
let t:splitType = 'vertical'
endif
endfunction
nnoremap <silent> <leader>wt :call ToggleWindowHorizontalVerticalSplit()<cr>
Following Mark Rushakoff's tip above, here is my mapping:
" vertical to horizontal ( | -> -- )
noremap <c-w>- <c-w>t<c-w>K
" horizontal to vertical ( -- -> | )
noremap <c-w>\| <c-w>t<c-w>H
noremap <c-w>\ <c-w>t<c-w>H
noremap <c-w>/ <c-w>t<c-w>H
Edit: use Ctrl-w r to swap two windows if they are not in the good order.
I use horizontal and vertical window splits in religiously in VIM and up until recently, I enjoyed the comfort of two commands to effectively hide (or minimize) my horizontal splits. I set them up adding the following lines to my .vimrc file:
set winminheight=0
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
Hitting Control-j or Control-k navigates through horizontal splits by going up or down. What I'd like to accomplish is the same thing for vertical splits by showing or hiding the left or right split using Control-Shift-h and Control-Shift-l; h moving to the left, l moving to the right. I have tried the following with little to no success:
set winminwidth=0
map <S-C-L> 500<C-W>h<C-W>_
map <S-C-H> 500<C-W>l<C-W>_
The action would be similar to utilizing Control-w-< and Control-w->, only moving the vertical split completely to the left or write, not just one line at a time.
Any ideas on how to accomplish this? Thanks.
First up, you won't be able to use <S-C- (shift + control) in your code (see below). But you can use the 'mapleader' as your "shift" and then use the <C-h> and <C-l> like you want to. Like this:
set winminwidth=0
nmap <Leader><C-h> <C-W>h500<C-W>>
nmap <Leader><C-l> <C-W>l500<C-W>>
The common leader keys in vim are comma and back-slash:
:let mapleader = ","
But you'll find that this gets annoying to require 3 keystrokes for this, so you might as well just drop the control key stroke. This way (if your leader is comma) you can just press ",h" and ",l" to go to the splits to your left and right:
set winminwidth=0
nmap <Leader>h <C-W>h500<C-W>>
nmap <Leader>l <C-W>l500<C-W>>
" (FTW) :D
...
A guy named Tony Chapman answers why you can't use control + shift:
Vim maps its Ctrl+printable_key
combinations according to ASCII. This
means that "Ctrl+lowercase letter" is
the same as the corresponding
"Ctrl+uppercase letter" and that
Ctrl+<key> (where <key> is a printable
key) is only defined when <key> is in
the range 0x40-0x5F, a lowercase
letter, or a question mark. It also
means that Ctrl-[ is the same as Esc,
Ctrl-M is the same as Enter, Ctrl-I is
the same as Tab.
So yes, Ctrl-s and Ctrl-S (i.e. Ctrl-s
and Ctrl-Shift-s) are the same to
Vim. This is by design and is not
going to change.
Try
set winminwidth=0
map <S-C-L> <C-W>h<C-W>|
map <S-C-H> <C-W>l<C-W>|
This doesn't move a window completely to the left or right (that's <C-W>H and <C-W>L), it just moves the cursor to the left (or right) window and maximizes that window horizontally.
See :help CTRL-W_bar for more.
Crl-w 1 |
will minimize current window in Vim.