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.
Related
I am currently reading a manual about how to compile and run a program. Currently I have two terminals, one terminal shows the manual, the other terminal is where I follow the instructions and type the command. Is it possible to do those two things in one terminal. Just like show two files in one terminal. I want to read the instruction in the left side of the terminal window and type command in the right side of the terminal window. Any advice?
I don't know what's your problem, having two terminal emulator windows side by side is perfectly acceptable. If you really want to add complexity to your learning experience, you can try one of these terminal multiplexers:
tmux
dvtm
or, if such a thing exists for your platform, a terminal emulator with split windows like:
iTerm (Mac OS X)
Terminator (Linux)
In VIM you can create new "windows"/panes just type
:vnew
For vertical window and
:new
For horizontal window
If you want to know more about windows you can check this or if you want to know more about VIM features you can try this
you can use one of the following
:tabe filename to open a new tab containing filename or nothing for a blank tab.
gt to switch and gT to switch backwards.
:sp to split the current window ^w j to jump down and ^w k to jump up
or :vsp to split vertically (so you can read in the left) ^w h to jump left and ^w l to jump right
all key strokes are in command mode
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.
In vim gf opens the file whose name is under the cursor in the current window. <C-W>f does the same but opens it in a new window. However this new window is created with an horizontal split.
How can I do the same and get a vertical split?
I tried various alternatives that did work (like :vsplit +normal\ gf), but have a slight problem: if the file doesn't exist, a new window is created anyways. This does not happen with gf nor <C-W>f. I'd like to have this behaviour as well from the "open file under cursor on a vertical split" command. How can I do that?
Here is possible mapping:
:nnoremap <F8> :vertical wincmd f<CR>
With a file name under cursor, hit F8 and voila.
Here is a solution involving 5 key strokes:
Ctrl-wv
gf
That is Ctrl-wv followed by gf in the normal mode.
Here is an equivalent solution that involves 7 key strokes:
:vs
gf
That is :vs command in command-line mode followed by gf in normal mode. Assuming we are in the normal mode with the cursor on the filename already, the complete sequence of keystrokes are: Shift:vsEntergf.
When we enter Ctrl-wv in normal mode or :vs in the command-line mode, the current window is split into two with the same file in both and the cursor remains in the same position (i.e., on the filename of the file that we want to go to in a new vertical split). So if we press gf now, the current window is now updated with the file we want to go to.
The end result is two vertical split windows: one with the first file and another with the file we wanted to go to.
If we're playing Vim Golf, I think the winning solution is to do:
Ctrl-w then f
to open the relevant file in a horizontal split.
Then change it to a vertical split, send then active window to the left or right side of the screen by doing either
Ctrl-w then L (active window to the left)
or
Ctrl-w then R (active window to the right)
Note that the final keystroke for left / right must be uppercase. The others should be lowercase
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.
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-?