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.
Related
I have a NERDTree setup nicely on my Rails project:
Sometimes, when I do fuzzy finding (Ctrl + P), I would accidentally still be on left tab; when I went to the file, it would replace the nerdtree's left tab. See screenshot below:
Super simple question, but how can I bring up the Nerdtree display back up like the first screnshot?
You should just be able to run :NERDTree again.
Additionally, I have this setting in my .vimrc, to make it less likely I'll delete the NERDTree buffer by accident with I'm compulsively typing :bd
autocmd FileType nerdtree cnoreabbrev <buffer> bd :echo "No you don't"<cr>
Deleting the buffer will permanently put NERDTree in hell (Vim plugins are usually brittle). If you do that, you have to restart Vim.
Also, if you use tabs in Vim, you should get NERDTreeTabs (dead but it works) which keeps NERDTree open / closed / in the same state across all tabs you have open, which is a standard design practice in all editors except Vim. I have a mapping set up to toggle NERDTree:
nnoremap <Leader>nt :NERDTreeTabsToggle<cr>
steal from my my vimrc!
nnoremap <F2> :NERDTreeToggle<CR>
Press F2 twice. The first one will close the NERDTree panel and second one will bring it up again.
F2 can be any key of your choice.
If I open vim with vim . netrw provides me with a nice list of the files and directories in the current directory.
If I open a file using v the file opens in a very narrow split down the left hand side of the screen and the directory listing remains open in a wide split on the right hand side of the screen.
Ideally I'd like it to have the opposite effect. ie. Show the directory listing in a narrow split on the left hand side of the screen and show the file in a wide split on the right hand side of the screen.
Any help much appreciated.
Netrw v153 and later (May 28, 2014) gives you the :Lexplore command, which, by default, opens a directory listing on the left hand side and opens files to the right (by pressing <cr>).
Whilst Jonathan.Brink's answer works perfectly well, simply adding
let g:netrw_altv=1
to .vimrc also seems to do the trick...
See https://superuser.com/questions/1056929/open-file-in-vertical-split-in-vim-netrw/1062063#1062063 for more info.
I'm sure this could be improved upon you can write a custom mapping that target's the netrw filetype.
Stick this in your .vimrc:
" open file vertically to the right
augroup netrw_mappings
autocmd!
autocmd filetype netrw call Netrw_mappings()
augroup END
function! OpenToRight()
:rightbelow vnew
:wincmd p
:normal P
endfunction
function! Netrw_mappings()
noremap V :call OpenToRight()<cr>
endfunction
The only thing is that you need to use V rather than v. For some reason I was unable to override netrw's v command, but using the capital version seems better anyway since it's not overriding a default.
Whenever I open a split or cycle through git's history with .:Glog my cursor always ends up at the top or bottom of the page. I always hit z. to align the text and I was looking for an automatic way of doing this.
Thanks to the link from #michaelberkowski I was able to figure out the following workaround for vertical splits:
" Open vertical split with identical configuration to parent
function! AwesomeSplit()
:let savex=winsaveview()
vsplit
:call winrestview(savex)
endfunction
nnoremap <Leader>vs :call AwesomeSplit()<CR>
For navigating buffers with :.Glog I use vim-unimpared from Tim Pope. The shortcuts I use -- ]q and [q -- are just aliases for :cnext and :cprevious so I'll see if I can create a patch for vim-unimpared using winsaveview() and winrestview().
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.
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