Vim: Close 1 file in a split view? - vim

I'm currently learning vim using vimtutor but whenever I try to open vimtutor there's always a split screen view of the previous file like this:
How can I close the bottom window?

You can press 'Ctrl w w' to switch between the window panes. Switch to the second window pane and in normal mode, type :q and enter. This should close the bottom window.

The screenshot looks like an empty file on the bottom; and on the top, the vim help screen describing vimtutor. I think you must have typed vim on the command line (which launched Vim with an empty file), then :help vimtutor (which brings up a Vim help page about vimtutor).
That would be why ctrl-w w and :q closed the whole vim editor. The ctrl-w w put you back in the new blank file; and :q executed a "quit" command.
Instead of launching vim that way, on the command line try typing vimtutor.

The top window has file type of "help" (this is shown in its status line). Help is normally viewed in splits, not as a single window. When other window is closed with :q and "help" becomes the last one, vim closes the whole tab or even the app. So don't do this.
If you seem the window is too small then maximize it vertically by pressing ctrl-w followed by "underscore". But it is really a matter of habit. No one bothers doing tab help vimtutor or such. Split view is just okay. So the best advice for you is "to comply".

You are not "using vimtutor"; you are using Vim and viewing the help for vimtutor.
What you get is absolutely normal and expected: the help is always displayed in a window so that you still have the thing you are working on visible while you check the documentation.
To actually use vimtutor, quit Vim and, when you are back at your shell, run the following command:
$ vimtutor

To keep only the current window press Ctrl+w+o. Mnemonic "only"

Related

How to open a vim terminal in the full area of the vim buffer?

I really like the built-in :terminal in recent vim versions. I have one pain point though: sometimes (often?), I would like the terminal to take the full vim window size. However, usually, using :terminal only uses a partial split on half the vim window size, even if I start from an empty buffer. From an empty buffer, using ctrl-w o maximizes.
Any way to open at once into a "full size split" that takes the full vim buffer, instead of needing the extra ctrl-w o step?
You can do :tab terminal to open a terminal window in a new tab page.
You can do :terminal ++curwin to open a terminal in the current window.

Vim: vsplit and run external command

I'm trying to map a command or function that splits a new window vertically, switches the cursor to the new window, and runs an external command on the <cWORD>.
When I do:
:vsplit|wincmd w|execute '!perldoc <cWORD>'
Vim seems to run the the external command first in the current window and then when the command exits, Vim creates a new window and switches focus to it.
If I break these commands up into separate lines in a function and call the function, the same thing happens. Is there a way to have Vim do what I want it to do?
My coworker Tye showed me how to do it:
let w=expand("<cWORD>") | vnew | execute "read !perldoc " . w|1
Save <cWORD> as variable w
vnew opens a new empty window
execute read !perldoc passing w as the variable. The output is read into the new window
Jump to the first line of the buffer in the new window
If you don't tell Vim otherwise, new vertical windows open on the left by default, leaving the cursor in the new window.
If that's not what you experience you should definitely investigate why.
After :vsplit, further commands are executed before the new window is rendered, in what you can imagine as a "virtual window".
This means that, however unsettling it can be, you won't see the new window before the next command. That's how Vim works and there's nothing you can do about it.
In the example below…
I have two perl files in the same directory,
in perl.pl there's a sample perl script I found online,
in warnings.pl there's a single word, warnings,
perl.pl is open in Vim with the cursor on strict,
I run :vsplit|!perldoc <cWORD>,
I expect to see the documentation on strict in my pager and the same buffer displayed in two vertical windows when I come back to Vim,
I close the left window,
I run :vsplit warnings.pl|!perldoc <cWORD>,
I expect to see the documentation on warnings in my pager and two different buffers displayed in two vertical windows when I come back to Vim.
Let's see:
Looks like everything worked as expected.
I don't see any but you probably have a good reason for opening that new window. I will suggest :help K and :help 'keywordprg anyway:
set keywordprg=perldoc

Vim command for switching window

I am using vim editor in pycharm. This editor is invoked using terminal which is available in pycharm. My problem is that, when i split vim window (:sp or :vsp), I am unable to switch to another window.(ctrl-w ctrl-w). It is obvious as most keyboard shortcuts, are not working in this integrated environment though commands are working fine. What is the command to switch window?
For more details:
I tried 'wincmd R'. It just switching position. But cursor remains in same position i.e. in old window. So its not useful. Is there any argument for 'wincmd' to actual move focus from one window to another?
Did you read :help window-move-cursor and :help :wincmd?
The former has all the commands that allow you to move the cursor from one window to another and the latter is very clear about the relationship between <C-w><char> and :wincmd <char>.
If you already know <C-w>w, what do you think would be the right argument to :wincmd?

Using :Vexplore effectively

So, the :Vexplore command in vim opens a nice little directory browser to the left.
But how do I then open a file from that side-pane into the main window on the right?
One would assume there's a simple mapping for it, but I can't seem to find it.
I think you want o or P
Also, have a look at the documentation, e.g.
:he netrw-p11
It turns out it's just a single line in .vimrc:
let g:netrw_browse_split=4 " Open file in previous buffer
Source: http://vimcasts.org/episodes/the-file-explorer/#comment-45366660
I'm sure what you're looking for is this:
:Vexplore!
This is the same command you would use to navigate to different windows in Vim (like quickfix window, or different split), everything is explained in
:help windows.txt
But to answer to your question directly:
CTRLwCTRLh to move to the left window
CTRLwCTRLl to move to the right window
then Enter to select the file you want to open.
You might want to read :help netrw as well
The latest netrw plugin (up to v153f) now provides the :Lexplore command, which opens an explorer on the right hand side of the vim display. It sets g:netrw_chgwin so edits occur in the window to the right of the netrw window. You can get it from http://www.drchip.org/astronaut/vim/index.html#NETRW .

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