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
Related
I.e. is it possible in vim to edit large file in several simultaneously opened tabs in the following way: first part of text (that fill all vertical space), second - in the second pane, and so on.
if it is not possible in vim, maybe it's feature is implemented in other editors?
Synchronizes two vim panes
Lets say your window is 20 rows, then
:vsplit // splits window into left and right panes
^w^w // focuses right pane
20^e // scrolls right pane down 20 rows
:windo set scrollbind // syncronizes both panes
^w means press and hold CTRL and then press w. Likewise for ^e
:windo means :set scrollbind in all open panes
Implement it in a function
Wraps the above commands in a function and binds it to [
function! SyncScroll()
vsplit
execute "normal! \<c-w>\<c-w>" . winheight(0) . "\<c-e>"
windo set scrollbind
endfunction
nnoremap [ :call SyncScroll()<cr>
You can add the above function and mapping to your vimrc with :e $MYVIMRC and reload it with :source $MYVIMRC
ref:
vim
docs - scrollbinding
wiki - scrollbinding
I think you're looking for the MPage plugin. You probably want to install the latest version from DrChip's page.
VIM create new window above the current or on the left side as default.
To use VIM more naturally, I want it to work oppositely, and I have set
:set splitright
:set splitbelow
This works when I split a window using command
:split
or
:vsplit
However, this fails when I create a new empty window using command
:new
or
:vnew
Is there any solution for the second situation?
You have only to add "below" before the command:
:below new
:below vnew
and from :help below
:rightb[elow] {cmd}
:bel[owright] {cmd}
Execute {cmd}. If it contains a command that splits a window,
it will be opened right (vertical split) or below (horizontal
split) the current window. Overrules 'splitbelow' and
'splitright'.
Doesn't work for |:execute| and |:normal|.
For the mapping discussed in the comments you can use this one:
:cnoremap new ^Bbelow ^Enew
you get:
^B by typing ctrl+v ctrl+
b
^E by ctrl+v ctrl+
e
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()}
here is my problem:
i'm using taglist and nerdtree.and set quickfix window displayed no matter if it has context.
and in my vimrc, i set them toggled in a fixed order, so i can get a layout i want.
but when i use C-o, C-i, C-], it will jump to a file, and if i want the features of taglist and nerdtree i should quit it and open it again.
but it will break the layout i want. so i have to quit all and open the file again.
so, is it possible to desable some features in some specific window?
thanks for any help.:)
You can disable certain commands for buffers via :map <buffer>; for sidebar windows like from NERDTree, that's good enough, as they always display the same (scratch) buffer. For example, to disable <C-O> in NERDTree:
:autocmd FileType nerdtree nnoremap <buffer> <C-o> <Nop>
I don't fully understand your question, but another approach (as it is hard to fully control where Vim places new buffer contents) would be to extend your "build your window layout" function from your .vimrc to first clean up any existing NERDTree / TagBar windows, so that you can call it later on (e.g. via a mapping) to "fix up" your layout again.
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.