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()}
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.
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.
I use NERDTree plugin, and I want to create a mapping that focuses NERDTree window and enters search mode (to easily select files, of course). The difficult part here is focusing NERDTree window. I want the mapping to work from any window - even from the NERDTree window itself. So how can I focus that window using vimscript?
I found out that NERDTree's buffer has name "NERD_tree_1" (if only one NERDTree buffer exists, but that's enough for me). Can I somehow use it to focus a window containing that buffer?
use the :NERDTreeFocus command. You can bind it to a key, for example:
noremap <F2> :NERDTreeFocus <BAR> call feedkeys('/') <CR>
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