How to fast change focus between tabs in neovim? - vim

How to fast change focus between windows in neovim? I dont know how to make it.

A quick reference from usr_08.txt
CTRL-W h move to the window on the left
CTRL-W j move to the window below
CTRL-W k move to the window above
CTRL-W l move to the window on the right
CTRL-W t move to the TOP window
CTRL-W b move to the BOTTOM window
If you're a new user (and have done vimtutor), I highly recommend going through the user manual (or at least skim through it, so that you learn the basics of Vim) - :h user-manual.

Both for Vim and NeoVim, why don't you give a try to this plugin I've created to allow easy movement between, and "management" of, windows and tabs?
I you go to that page, you'll see I've included a GIF showing the keys I press and what they do. Essentially you press leader+w to enter a "window management"-mode which interprets any key as if it was preceded by Ctrl-W.

Related

How can I switch windows in Vim

I am using Vim and I am unable to switch to one of my windows by using the default bind keys <ctrl+w> j. I have three windows open and the bottom right window is inaccessible. Why is this happening?
<ctrl> + w + w works for me.
If you :sp or :vsp to split a pane, <ctrl> + w + w will allow you to navigate between them.
It appears as if you have taken something similar to the following course of action
vim <some-file>
:vs <some-other-file>
<C-w> l // to get to the right window
:term // to open up a terminal session within right right window
<C-w> j // to move to the bottom right window (a normal vim window)
:q
vim <file> // within the terminal inside the right vim window
:sp <file> // split that window
Now it will appear as if you have three vim windows, when in reality, you have four:
Two outer (the left, and the right terminal session)
Two within the right window's terminal session
This is quite a precarious position because whether you are in the outer left or right session, the outer buffer (not sure if this is the correct word so please correct me if I'm wrong) will always captures the <C-w> control character for some reason.
You can see this by looking where the <C-w> shows up on the screen when you press it. If I have replicated your environment correctly, it shows up in the bottom right corner below the outer buffer's right window.
As a workaround to this, instead of using <C-w> to proc window navigation, you need to use:
:winc j
to navigate to the bottom right window.

Changing the size of the split screen in vimdiff

I only know two commands for dealing with vimdiff:
Ctrl-w Ctrl-w switches windows and Ctrl-w = makes the two windows equal width if they became uneven due to, for example, resizing the terminal.
How can I make the left screen much larger than the right, for instance?
You can use any windowing command in vimdiff, for example CTRL-w < to make the left window one column smaller. This can also be combined with a count, for example CTRL-W 5> to make the right window 5 columns smaller. Consult the help page with :help CTRL-w to get a list of window commands.
Additionally, you can use the mouse to change the size of the windows by clicking the boundary between both windows and dragging it into a direction. You might have to enable mouse support by issuing :set mouse=a first.

How to jump to the rightmost window with just one keystroke?

I found the window manager in vim is quite powerful. We can use it to split the window to whatever we want it to be. But when the numbers of the windows comes to more then 4, it will caused one problem: it's quit hard to jump to the rightmost window. Because the rightmost window is used to display taglist in my vim. I don't like the way that type CTRL+w for twice or more times to jump to the rightmost window. Is there a more easier way to do it?
:nmap <C-\> <C-w>200l
then you press ctrl-\ will let you go to the most right window.
actually you don't need to press c-w many times. if you have 10 windows opened, and now you are in 3rd window, you just type ctrl-w 10 l. to go to the right most window.
from help:
CTRL-W_l| CTRL-W l go to Nth right window (stop at last window)
you just need give a N
If the previous window was TagList, you can use <C-w>p to jump to it.
You can also use <C-w>b to jump to the last window at the bottom-right.

Two basic questions with NERDTree — switching windows and finding files

I am using vim with NERDTree to develop, but not good at it. I have two questions with NERDTree:
How to move cursor between nav window and edit window without mouse?
How to go to one special file node (named xxx) in nav window directly by keyboard?
The NERDTree plugin creates a Vim buffer, and displays it in a Vim window. So you can use any of your normal Vim commands.
(1) Thus, if your edit window is to the right of the NERDTree window, you would use: ctrl + Wl to go to right window and ctrl + Wh to go to left window. or ctrl + w twice to toggle between the two.
(2) To go to a special file, simply search for it while in the NERDTree window:
/xxx
Hit ENTER to end the search at the line, and then ENTER again to open the file in the previous window and go to it.

How to jump back to NERDTree from file in tab?

I usually:
Choose the needed file.
Open it in a tab(t character, by default).
But how I can jump back to NERDTree to open one more file in a tab?
Temporary solution I use now in my .vimrc file:
map <F10> :NERDTree /path/to/root/of/my/project
But it's not very useful to start navigation again and again from the root directory.
Ctrl-ww
This will move between open windows (so you could hop between the NERDTree window, the file you are editing and the help window, for example... just hold down Ctrl and press w twice).
Ctrl+ww cycle though all windows
Ctrl+wh takes you left a window
Ctrl+wj takes you down a window
Ctrl+wk takes you up a window
Ctrl+wl takes you right a window
NERDTree opens up in another window. That split view you're seeing? They're called windows in vim parlance. All the window commands start with CTRL-W. To move from adjacent windows that are left and right of one another, you can change focus to the window to the left of your current window with CTRL-w h, and move focus to the right with CTRL-w l. Likewise, CTRL-w j and CTRL-w k will move you between horizontally split windows (i.e., one window is above the other). There's a lot more you can do with windows as described here.
You can also use the :NERDTreeToggle command to make your tree open and close. I usually bind that do t.
If you use T instead of t there is no need to jump back because the new tab will be opened, but vim's focus will simply remain within NERDTree.
You can focus on a split window using # ctrl-ww.
for example, pressing:
1 ctrl-ww
would focus on the first window, usually being NERDTree.
Since it's not mentioned and it's really helpful:
ctrl-wp
which I memorize as go to the previously selected window.
It works as a there and back command. After having opened a new file from the tree in a new window press ctrl-wp to switch back to the NERDTree and use it again to return to your previous window.
PS: it is worth to mention that ctrl-wp is actually documented as go to the preview window (see: :help preview-window and :help ctrl-w).
It is also the only keystroke which works to switch inside and explore the COC preview documentation window.
ctrl-ww Could be useful when you have limited tabs open. But could get annoying when you have too many tabs open.
I type in :NERDTree again to get the focus back on NERDTree tab instantly wherever my cursor's focus is. Hope that helps
The top answers here mention using T to open a file in a new tab silently, or Ctrl+WW to hop back to nerd-tree window after file is opened normally.
IF WORKING WITH BUFFERS: use go to open a file in a new buffer, silently, meaning your focus will remain on nerd-tree.
Use this to open multiple files fast :)
You can change the tabs by ctrl-pgup and ctrl-pgdown. On that tab you came from the NERDTree is still selected and you can open another tab.
In more recent versions of NERDTree you can use the command :NERDTreeFocus, which will move focus to the NERDTree window.
gt = next Tap
gT = previous Tab
if you want you can enable the mouse support editing ~/.vimrc file.
put set mouse=a
after that you enable files click in NERDTree.
All The Shortcuts And Functionality is At
press CTRL-?

Resources