Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to split a window in Vim/Vi with a terminal?

Tags:

vim

vi

Is there a way to split a window inside Vi/Vim so that one window will be a terminal?

P.S. Solutions like installing new text editors and such will not help me.

like image 952
nadavgam Avatar asked Jul 12 '16 13:07

nadavgam


People also ask

How do I split a terminal window in Vim?

To split the vim screen horizontally, or open a new workspace at the bottom of the active selection, press Ctrl + w , followed by the letter 's' . In the example below, the left section has been split into two workspaces. To navigate to the bottom section hit Ctrl + w , followed by the letter 'j' .

How do you split a terminal window in Linux?

CTRL + SHIFT + O : Split Terminal Horizontally. CTRL + SHIFT + E : Split Terminal Vertically. CTRL + SHIFT + W : Close Current Panel.

How do I open another window in Vim?

To open a new VIM window next to the existing one, press <Ctrl>+<w> then press <v>. You can move to the left window again by pressing <Crtl>+<w> and then pressing <h>. To open a new VIM window on the bottom of the currently selected window, press <Ctrl>+<w> then press <s>.

How do I split a terminal window in Ubuntu?

Ctrl-A | for a vertical split (one shell on the left, one shell on the right) Ctrl-A S for a horizontal split (one shell at the top, one shell at the bottom) Ctrl-A Tab to make the other shell active.


2 Answers

In Vim 8, if it is compiled with the +terminal option, you can split the current window horizontally and add a terminal with the command :terminal or :term for short-hand.

enter image description here

If you want to split the window vertically, the best way I know is to do a regular vertical split with :vsp or <c-w>v. Then, split one of the windows to have a terminal window (:term), then finally move to the smaller, non-terminal window and close it.

enter image description here

Edit: ...and literally right after I wrote this I found how to easily vertically split the terminal window...

:vertical terminal  " OR  :vert term 

The terminal will open in something similar to insert mode, and pressing <c-w>N will put you in the "normal" mode where you can have regular Vim motions and can run Vim commands. Note that in many shells (I know for sure in Bash and Zsh), you can run set -o vi to be able to hit <c-[> or <esc> and use Vim motions anyways. The best part about that is hitting v when in "normal" mode where the current command is opened in a new Vim instance and is run upon exiting Vim.

like image 131
JakeD Avatar answered Sep 19 '22 08:09

JakeD


Maybe adding the string

rightb vert term 

or

bel vert term 

to your .vimrc (hidden file with editor settings; it is in the user home directory by default: ~/.vimrc) will solve your problem. Thus, if you type vim file_name.txt in terminal emulator, you will get two split windows: on the left side - txt-file, on the right - terminal emulator window.

ps: you can move between split windows with ctrl + double "w" (press "w" two times).

also, from my experience, the "term"-command is not supported in 8.0 vim version, unlike 8.2 version.

like image 22
uch Avatar answered Sep 19 '22 08:09

uch