How to split VIM window to show content and enable command - vim

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

Related

Vim: Close 1 file in a split view?

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"

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.

To scroll in gdb window using Termdebug in Vim

I'm using vim since a while to code in c++, and I use the plugin Termdebug to have the gdb window included in vim, with all the commands easily usable etc... my problem is that I can't scroll up or down in the gdb command window and in the output window, because up and down arrows only show precedent and next commands, none of the combo I tried worked (like C-Up or A-Up). I already tried some solutions:
lauching vim with :let g:termdebug_use_prompt = 1, so I can go in normal mode in the termdebug windows. It worked, but the text displayed is ugly and buggy (text which was bold isn't anymore, random line breaks in the middle of lines...).
as How to scroll the gdb window within cgdb? says, using PageUp/PageDown, but my laptop doesn't have these keys. I tried to map new combinations of keys with https://github.com/sezanzeb/key-mapper or by modifying ~/.config/openbox/lxqt-rc.xml, but when I tried them it only wrote "3~" and ";3~" whether in Vim or in Qterminal btw. Edit : tried with another computer with Page Up / Down key, doesn't work.
Using C-w + :C-y, as C-w make it possible to enter vim commands in the gdb window and C-y scroll up in vim. In the vim and the gdb window, it raises an E464 Error, saying the command is ambiguous. Edit : vim commands doesn't seem to work at all in gdb windows, command :go which should move the cursor to the beginning of the file has no effect.
If someone has a solution making it possible to switch between modes in the gdb window, but with a correct display it would be perfect, allowing me to use all my vim maps in the gdb window, however just a solution to scroll would already save me.
Problem solved ! Doing "C-W N" in the gdb and/or in the I/O window switch them to normal mode, making possible the scrolling.

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.

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

Resources