405

I am used to Emacs, but I am trying out Vim to see which one I like better.

One thing that I like about Emacs is the ability to run a terminal inside Emacs. Is this possible inside of Vim? I know that you can execute commands from Vim, but I would like to be able to run a terminal inside of a tab.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Evan
  • 5,925
  • 6
  • 33
  • 35

25 Answers25

234

Outdated from August 2011

Check out Conque Shell (also on GitHub). Lets you run any interactive program inside vim, not just a shell.

Luis Sieira
  • 29,926
  • 3
  • 31
  • 53
Kyle Simek
  • 9,576
  • 4
  • 26
  • 32
  • 24
    `:ConqueTerm bash `, `vim `, `:ConqueTerm bash`.... the recursive horror!! – keflavich Jan 25 '12 at 05:11
  • 2
    psihodelia seems to be right. I've just compiled vim with --enable-pythoninterp (cygwin doesn't distribute vim with +python) and after installing ConqueTerm, I get an error from #set_buffer_settings. I haven't been able to track down where that function lives, or get any idea of what the error means. The message includes a statement about an invalid argument "edit ++enc=utf-8 bash\ -\ 2". Argh. – Nate Kennedy Jul 20 '12 at 04:55
  • 56
    In order to understand recursion, you must first understand recursion. – Stabledog Feb 03 '13 at 14:26
  • 21
    @Łukasz Niemier VIMCEPTION – Sebastián Grignoli Feb 16 '13 at 02:06
  • 1
    Works with zsh, sweet! d-_-b – qmmr Sep 21 '14 at 19:20
  • @psihodelia now it does :D – still_dreaming_1 Mar 10 '15 at 18:10
  • @hauleth Actually, I do have a use case for that. Unfortunately some commands are run by the innermost vim, while other commands are run by the outermost vim, sigh... – still_dreaming_1 Mar 10 '15 at 18:14
  • I love Conque plugin and also Conque-GDB to debug with standard C/C++ inside vim that acta as a full IDE. BUT if you need multiwindows fast scrolling / realtime printout, I find that tmux is a better solution. Please read the answer here below about ViMUX: a tmux/vim integration – Giorgio Robino Sep 15 '15 at 13:35
  • Don't think you need Conque for vimception, though? You can just do !bash, then vim, then !bash, then vim and so on. Or just do !vim then !vim then !vim – miyalys Sep 17 '15 at 09:21
  • any chance you know how to install this from a script instead of manually starting vim and using :so % – serup Aug 22 '16 at 08:18
  • `:ConqueTermVsplit bash `, Then to get out of here. – Tinmarino Apr 08 '18 at 12:10
  • 1
    It would seem that this is no longer supported, anyone have an alternate? – dykeag Apr 10 '18 at 15:14
231

I'm not sure exactly what you're trying to achieve (I've never used Emacs), but you can run commands in Vim by typing:

:! somecommand [ENTER]

And if you want to type in several commands, or play around in a shell for a while, you can always use:

:! bash (or your favourite shell) [ENTER]

Once the command or shell terminates, you'll be given the option to press Enter to return to your editor window

Vim is intentionally lightweight and lacking in the ability to do non-editorish type things, just as running a full-blown shell inside a Vim pane/tab, but as mentioned above there are third-party addons such as vim-shell that allow you to do that sort of thing.

Typically if I want to switch between Vim and my shell (Bash), I just hit CTRL+Z to pause the Vim process, play around in my shell, then type 'fg' when I want to go back to Vim - keeping my editor and my shell nice and separate.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Claridge
  • 6,159
  • 2
  • 27
  • 25
  • 20
    And if you want to copy the command's output to the current buffer: :r! dir – Cyber Oliveira Aug 12 '09 at 19:03
  • 7
    I use both Emacs and Vim (and have a lot more experience with Vim). But I have found that often it is nicer and easier to work with two views at the same time (one to see what you are editing and another to work within an interactive shell - for example to test the effect of a configuration change that you have just edited). It also helps with my cognition, retention and mental workflows when important things I may need to monitor closely don't disappear off the screen (like what happens when you use Ctrl-Z or :shell in Vim). – mvanle Mar 24 '14 at 22:02
  • Nice answer! To compliment it even further, I would also add the `:r! command [ENTER]` mentioned in the comments. – Jeach Aug 02 '19 at 13:49
217

Updated answer (11 years later...):

  • I would recommend using tmux instead of screen as suggested in the original answer below, if you choose to use that solution.
  • Vim 8.1 now has a built in terminal that can be opened with the :term command. This provides much more complete integration with the rest of the Vim features.

I would definitely recommend screen for something like this. Vim is a text editor, not a shell.

I would use Ctrl+AS to split the current window horizontally, or in Ubuntu's screen and other patched versions, you can use Ctrl+A|(pipe) to split vertically. Then use Ctrl+ATab (or equivalently on some systems, Ctrl+ACtrl+I which may be easier to type) to switch between the windows. There are other commands to change the size and arrangement of the windows.

Or a less advanced use of screen is just to open multiple full-screen windows and toggle between them. This is what I normally do, I only use the split screen feature occasionally.

The GNU Screen Survival Guide question has a number of good tips if you're unfamiliar with its use.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 11
    +1 I only just recently recieved the screen gospel. I wonder how I lived without it. – guns Aug 11 '09 at 03:30
  • You can also use screen with Vim plugin Vicle to send commands edited in vim to a screen session. – skinp Aug 12 '09 at 13:04
  • 1
    I'm not sure if you can do it in the stock screen, but Ubuntu's version lets you do vertical splits with Ctrl+A | (that's a vertical pipe). Much nicer, imo. – Yewge Aug 23 '09 at 01:26
  • If I could I'd vote twice for this. I heard about screen long ago but never used it. This tip will save me a LOT of time. thanks. – yogsototh May 12 '10 at 12:29
  • Unfortunately, using a vertical split slows down STDOUT (at least on my machine). `ls -R` is a lot slower with the split than without, for example. – Benjamin Oakes May 27 '10 at 15:21
  • You can use :! to execute system commands from within vim. It's not a complete terminal but it's still useful for quick stuff. Vim 7 allows you to tab and autocomplete so if you're just looking for a file it's great. Things like logging into mysql/opening an ssh terminal really should be done through Screen or byobu – EricR Nov 19 '10 at 18:00
  • 1
    in this video, http://blogs.jetbrains.com/pycharm/2011/03/python-ides-panel-video-from-pycon-2011/ at 32:30 , it shows how emacs/terminal integration can be nice for debugging... when you step into a function using the debugger in the shell window, the editor window auto-updates to show the location in the code where the debugger is currently at. This shows how emacs seems closer to being like an IDE than vim. It would be nice if VIM had this ability. (I'm a VIM user, not an emacs user) – Eddified Apr 15 '11 at 03:37
  • 131
    i would rather choose tmux instead of screen. – tomaszkubacki Sep 02 '11 at 04:52
  • I like screen as much as the next guy, but -1 as the comment around Conque better answers the question. – Trent Davies Sep 09 '11 at 04:40
  • 90
    Yes, of course one can run screen, or tmux, or terminator, or open another window and alt-tab, or even use a KVM switch activated with a footpedal. But that's not the point -- all those solutions sacrifice *integration* between the terminal and VIM, which is why one would bother looking for solutions in this space. I don't understand how this answer is even an answer, let alone top or accepted answer. Think I'll go try Conque. – Stabledog Feb 03 '13 at 13:53
  • 41
    how is this the top answer??? you need to unvote it and vote up the next answer down, which actually answers your question. Using screen does not run a shell within vim. That's like telling someone to start another shell. And for those who keep throwing out ":!" he ALREADY SAID he knew how to execute commands, which is NOT what he asked for... sheesh. The arrogance is so thick in here you can cut it with a knife. – osirisgothra Aug 15 '14 at 20:19
  • 2
    My opinion is same. This is a good option, but it doesn't answer the question – Konzulic Nov 30 '15 at 10:30
  • 9
    This answer should be updated due to new vim 8.1 feature [Terminal Window](https://www.vim.org/vim-8.1-released.php) – Alan Garrido Jul 19 '18 at 19:01
  • Doesn't answer the question as far as I understand it. Running vim in screen or tmux isn't the same as running a terminal inside of vim and all. – Alexandre Jul 22 '19 at 23:52
  • Unfortunately if you're using screen or tmux instead of a GUI vim (like MacVim), then you're not going to have sane text selection (e.g., turn on line numbers or use a split and try to copy/paste multiple lines with mouse) and you're going to need to connect the vim clipboard with the system clipboard. – weberc2 Oct 28 '19 at 18:55
  • flagged as not an answer because I've always felt this answer was inappropriate on the question. There was a real answer even at the time of this answer, and now there's an even better one since vim comes with the feature. I think this answer should at least have its acceptance revoked. – lahwran Aug 26 '20 at 08:16
190

The way that I get around this is:

  • pause Vim with Ctrl + Z,
  • play in the terminal,
  • then return to exactly where you left with Vim by just typing the command fg.
Can
  • 4,516
  • 6
  • 28
  • 50
ptrin
  • 2,116
  • 1
  • 11
  • 5
  • 16
    ``:!bash`` is a nicer way of doing that – 0atman Mar 16 '12 at 11:14
  • I think he wants a kind of dreampie like functionality – Adam Miller Jan 12 '13 at 22:04
  • 16
    @Oatman Why is `:!bash` nicer than `Ctrl+z`? (Just wondering) – Sebastián Grignoli Feb 16 '13 at 02:07
  • 3
    @SebastiánGrignoli because with `Ctrl+Z`, for example, you can move to another folder, then `ls` then `git status`, etc. `Ctrl+Z` is a "pause", you can "resume" with `fg`. But with :!bash, as I know so far, you only can run a single command at once, or even if you can run more than a command at once, it's still not convenient. So overall, 'Ctrl+Z' is much better – Leo Jun 06 '13 at 04:17
  • +1 because this works in pretty much any environment. Working on a foreign system that I can't customize, and through a cheap PuTTY shell, this works great. – t3sture Dec 17 '17 at 02:45
  • @Leo in my experience, i using `:! /bin/bash` and doing everything in a bash including change directory, pulling from git, compiling, run test, run apps. after that, i just type `exit` to exit from bash and get back to vim. CMIIW – septianw Feb 22 '18 at 03:31
  • You can also make a "magic ctrl-z" in zsh that allows you to ctrl-z again to return to vim (see VII): https://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/a – jchook Jun 16 '20 at 18:09
163

If enabled in your version of Vim, a terminal can be started with the :term command.

Terminal window support was added to Vim 8. It is an optional feature that can be enabled when compiling Vim with the +terminal feature. If your version of Vim has terminal support, :echo has('terminal') will output "1".

Entering :term will place you in Terminal-Job mode, where you can use the terminal as expected.

Within Terminal-Job mode, pressing Ctrl-W N or Ctrl-\ Ctrl-N switches the mode to Terminal-Normal, which allows the cursor to be moved and commands to be ran similarly to Vim's Normal mode. To switch back to Terminal-Job mode, press i.

Other answers mention similar functionality in Neovim.

dannyadam
  • 3,950
  • 2
  • 22
  • 19
  • 11
    +1 for how to switch back into Terminal cmd mode with `i` after switching from ctrl-w-N browse mode. This is a killer feature even over tmux and works on Windows too. – radke Oct 24 '17 at 13:36
  • 3
    Is it possible to vertical split using `:term`? – Vitaly Zdanevich Nov 08 '17 at 10:03
  • 2
    super! Great that the terminal is built in so we do not have mess with more plugins. Upgraded to vim 8 via `brew install vim --override-system-vi` and `:term` works perfectly. Thanks for sharing! – LeOn - Han Li Feb 20 '18 at 05:25
  • 23
    @VitalyZdanevich, `:vertical :term` will vertically split with the terminal in the left window. `:vertical :botright :term` will vertically split with the terminal in the right window. Alternatively, you can manually layout windows, and then use `:term ++curwin` to open a terminal in the active window. – dannyadam May 25 '18 at 16:08
  • 2
    esc ctrl-w w allows you to switch between windows – user1869582 Apr 09 '20 at 00:02
  • @user1869582, On my `vim` installation, `Ctrl-w w` alone switches windows (i.e., without an initial ``). – dannyadam Apr 10 '20 at 17:09
96

:sh then Ctrl+D to get back in (bash)

Update:

You could map Ctrl+D in vim to run :sh, which allows you to toggle between bash and vim quickly.

noremap <C-d> :sh<cr>

AEM
  • 1,354
  • 8
  • 20
  • 30
tester
  • 22,441
  • 25
  • 88
  • 128
  • 2
    I think `ctrl+z` and `fg` are slightly faster, given you don't have to type `:sh` in that case. – Alex Dec 06 '16 at 17:51
  • 2
    @Alex no you don't have to type `:sh` if you do the map. After `noremap`, you can just `Ctrl+D` from vim to `sh`, and since `^D` is EOF, which terminates the `sh`, so you would return back to vim. The one key can toggle between `sh` and vim. – InQβ Oct 10 '19 at 01:20
53

The main new feature of Vim 8.1 is support for running a terminal in a Vim window.

:term will open the terminal in another window inside Vim.

Yossarian42
  • 1,950
  • 17
  • 14
45

Eventually a native :terminal command was added to vim in 2017.

Here is an excerpt from the :terminal readme:

This feature is for running a terminal emulator in a Vim window. A job can be started connected to the terminal emulator. For example, to run a shell:

 :term bash

Or to run build command:

 :term make myprogram

The job runs asynchronously from Vim, the window will be updated to show output from the job, also while editing in another window.

fjardon
  • 7,921
  • 22
  • 31
  • The terminal runs in a buffer in the same tab. so if you are used to using multiple files in vim, you may face some difficulty. switching buffers will eventually come to the terminal from where it is a point of no return, you have to kill the terminal. as long as you are aware of this, it should be fine. hope the developers come with a workaround for this. – ArunMKumar Jul 06 '18 at 04:54
  • 2
    @ArunMKumar Use [Ctrl+W] to "escape" from the terminal, and then do `:bn` as usual. No need to kill the terminal and it is not a point of no return :) – fjardon Jul 06 '18 at 09:09
  • Thanks, buddy, totally missed it. I have keymapped **:bn** to a key and it stopped working, it is working back again. It was my bad. – ArunMKumar Jul 10 '18 at 08:17
  • 2017? You mean 2018? – flarn2006 Nov 03 '18 at 02:16
  • 1
    @flarn2006, regarding 2017 versus 2018, Vim 8.1 was announced on vim.org on May 18, 2018, with "support for running a terminal in a Vim window" listed as its "main new feature". The feature was first available earlier, on July 7, 2017, in patch 8.0.0693. https://github.com/vim/vim/commit/e4f25e4a8db2c8a8a71a4ba2a68540b3ab341e42 – dannyadam Apr 24 '20 at 22:03
45

:term

Added in Vim 8.1.

Keep in mind that whenever a terminal window is active, most keystrokes will simply be passed to the terminal instead of having their usual functions. Ctrl-W and its subcommands are the main exception. To send a literal ^W input to the terminal, press Ctrl-W .. You can also open the Vim : command line by pressing Ctrl-W :. The other Ctrl-W commands work as normal, so managing windows works the same no matter what type of window is currently selected.

flarn2006
  • 1,787
  • 15
  • 37
  • It was added before vim 8.1. It's just the main big feature that vim 8.0.001 didn't have. That's why it's advertised as a vim 8.1 novelty. See Daniel's answer from oct 2017, and fjardon's one in apr 2018. -> https://github.com/vim/vim/blob/master/runtime/doc/version8.txt#L18814 – Luc Hermitte May 23 '18 at 06:39
  • don't get what you mean by "To send a literal ^W input to the terminal, press Ctrl-W ." can you explain? thx – abernier Mar 12 '21 at 07:28
  • 1
    @abernier: Sure. What I mean is, say you're running a program in the Vim-terminal that does something when you press Ctrl-W. If you just press Ctrl-W, the program won't see it, because Vim will pick it up instead. So what you do is, you press Ctrl-W, and then you press the period (`.`) key, and that will make the program in the terminal see the Ctrl-W. – flarn2006 Mar 14 '21 at 04:52
  • @flarn2006 Is there any way to see the output of long commands? For example, if I cat a long file (in the tab where `:term` is active), then I can't scroll up or down to see all the output. One way is to use `Ctrl-W N` and then go back with `i`, but is there another alternative? – ado sar Sep 05 '22 at 14:16
37

This question is rather old, but for those finding it, there's a new possible solution: Neovim contains a full-fledged, first-class terminal emulator, which does exactly what ConqueTerm tried to. Simply run :term <your command here>.

<C-\><C-n> will exit term mode back to normal-mode. If you're like me and prefer that escape still exit term mode, you can add this to your nvimrc:

tnoremap <ESC><ESC> <C-\><C-N>

And then hitting ESC twice will exit terminal mode back to normal-mode, so you can manipulate the buffer that the still-running command is writing to.

Though keep in mind, as nvim is under heavy development at the time I'm posting this answer, another way to exit terminal mode may be added. As Ctrl+\Ctrl+n switches to normal mode from almost any mode, I don't expect that this answer will become wrong, but be aware that if it doesn't work, this answer might be out of date.

https://github.com/neovim/neovim

Justin M. Keyes
  • 6,679
  • 3
  • 33
  • 60
lahwran
  • 601
  • 7
  • 22
20

I know that I'm not directly answering the question, but I think it's a good approach. Nobody has mentioned tmux (or at least not as a standalone answer). Tmux is a terminal multiplexor like screen. Most stuff can be made in both multiplexors, but afaik tmux it's more easily to configure. Also tmux right now is being more actively developed than screen and there's quite a big ecosystem around it, like tools that help the configuration, ecc.

Also for vim, there's another plugin: ViMUX, that helps a lot in the interaction between both tools. You can call commands with:

:call VimuxRunCommand("ls")

That command creates a small horizontal split below the current pane vim is in.

It can also let you run from a prompt in case you don't want to run the whole command:

<Leader>vp :VimuxPromptCommand<CR>

As it weren't enought, there are at least 6 'platform specific plugins':

Here is a nice "use case": Tests on demand using Vimux and Turbux with Spork and Guard

ciastek
  • 1,343
  • 12
  • 15
15

It's possible to open a new tab with a terminal in vim since 2017 as @fjardon said:

Just type: :terminal. It will open a tab by default above your current tab.

If you want it to open in another place you can try the following options:

  • :below terminal : open the terminal below current tab.
  • :below vertical terminal : open the terminal always vertically to the right.

You can play with these until you find what you like. After this you can set a map in your .vimrc configuration file, for me, I use:

nmap <leader>tt :below vertical terminal<CR>

This way I can type <space>tt (space my leader key) to open it quickly.

As a side note:

  • You can switch between your tabs (terminal and other buffers) with Ctrl+W Ctrl+W.
  • You can enter an editable mode in your terminal if you want to copy your commands with Ctrl+W N and go to normal terminal mode with i or a.

Cheers!

AEM
  • 1,354
  • 8
  • 20
  • 30
Sam
  • 514
  • 1
  • 7
  • 15
14

Someone already suggested https://github.com/Shougo/vimshell.vim, but they didn't mention why. Consequently, when I came away from this question I wasted a lot of other time trying the other (much higher ranked) options.

Shougo/vimshell is the answer. Here's why:

In addition to being a terminal emulator, VimShell allows you to navigate through terminal output in normal and visual mode. Thus, if a command you run results in output that you'd like to copy and paste using the keyboard only...VimShell covers this.

None of the other options mentioned, including the :terminal command in NeoVim do this. Neovim's :terminal comes close, but falls short in at least the following ways as of 2/18/2017:

  • Moves the cursor to the end of the buffer, instead of at the last keeping it in the same spot like VimShell does. Huge waste of time.

  • Doesn't support modifiable = 1 see a discussion on this at Github, so helpful plugins like vim-easymotion can't be used.

  • Doesn't support the display of line numbers like Vimshell does.

Don't waste time on the other options, including Neovim's :terminal. Go with VimShell.

user3751385
  • 3,752
  • 2
  • 24
  • 24
  • 1
    NeoVim does allow you to navigate and copy from the terminal output in normal/visual mode. I do this all the time. Using NVIM 0.1.6-dev – Alice Heaton Oct 27 '16 at 09:17
  • Thanks, I’ll try VimShell. I’ve taken the liberty of removing an incorrect statement from the answer, however. As @Alice pointed out, NeoVim’s `:terminal` can absolutely do the same. – Konrad Rudolph Feb 09 '17 at 11:10
  • ```:terminal``` cannot do the same as ```:VimShell``` in terms of navigation and editing, and in fundamental ways. See explanation edit above. – user3751385 Feb 18 '17 at 17:24
9

You might want to take a look at the :sh command (see :help sh in Vim).

Various commands

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
7

No, you cannot:

http://vimdoc.sourceforge.net/htmldoc/tips.html#shell-window

Carlos Lima
  • 4,162
  • 29
  • 32
Amber
  • 507,862
  • 82
  • 626
  • 550
  • 2
    DO NOT TAKE THE ADVICE OF `splitvt` - it mangles the color control codes and makes `vim` utterly unusable. – new123456 Jun 24 '11 at 23:22
  • 17
    "No" is a bad answer. A better answer is "By default, no." Technically, it can be done, and perhaps you need to write new source code and compile it yourself, or write a plugin. Is it easy? Maybe not, but it can be done. Simply saying No is more like saying "no, I won't do it." – trusktr Apr 06 '13 at 01:53
  • Perhaps you want to delete this answer now? Since it is clearly possible. – Anish Ramaswamy Feb 26 '14 at 22:38
  • 2
    @AnishRamaswamy It is still not possible to run a shell within a vim buffer using stock vim (unlike emacs). That is what the OP's question was. – Amber Feb 26 '14 at 22:47
  • 1
    @Amber, Yeah that would be fine except the OP made no mention of using the stock vim. – Anish Ramaswamy Feb 26 '14 at 22:50
  • 1
    @AnishRamaswamy I think we'll just have to agree to disagree here. – Amber Feb 27 '14 at 04:11
  • 3
    Someone should just edit this answer to say you cannot do it with stock vim. – still_dreaming_1 Apr 07 '14 at 14:25
5

By far, I have tried a lot of solutions mentioned here, what I really wanted is to keep the terminal open while coding a similar experience in VsCode. Then I came across this solution which is working perfectly for me.

Before Installing:

  • I am using Nvim 0.5 but I think it can work for any version and checked also on vim
  • I am using macOS Catalina Version 10.15.7

Setup your integrated terminal

Step -1-

  • Create a script with the name myQuickTerminal.vim or whatever name you want.
  • Put the following script
"==============================================================================
"
" ▒█▀▀█ █░░█ ░▀░ █▀▀ █░█   ▀▀█▀▀ █▀▀ █▀▀█ █▀▄▀█ ░▀░ █▀▀▄ █▀▀█ █░░
" ▒█░▒█ █░░█ ▀█▀ █░░ █▀▄   ░▒█░░ █▀▀ █▄▄▀ █░▀░█ ▀█▀ █░░█ █▄▄█ █░░
" ░▀▀█▄ ░▀▀▀ ▀▀▀ ▀▀▀ ▀░▀   ░▒█░░ ▀▀▀ ▀░▀▀ ▀░░░▀ ▀▀▀ ▀░░▀ ▀░░▀ ▀▀▀
"
"==============================================================================
" " This is a script that will trigger a terminal quickly than the FloatTerminal
" open new split panes to right and below
"link: https://betterprogramming.pub/setting-up-neovim-for-web-development-in-2020-d800de3efacd
"==============================================================================
set splitright
set splitbelow
" turn terminal to normal mode with escape
tnoremap <Esc> <C-\><C-n>
" start terminal in insert mode
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
" open terminal on ctrl+n
function! OpenTerminal()
  split term://zsh
  resize 10
endfunction
nnoremap <leader> n :call OpenTerminal()<CR>

NOTE: if you want to run bash instead of zsh for a particular reason then replace zsh with bash.

Step -2-

Lets source it, put this in init.vim for neovim or `.vimrc' for vim

source $HOME/.config/nvim/modules/mySpecialScripts/myQuickTerminal.vim

This will be preloaded ahead as you save and resource it, you can use source $MYVIMRC for quick reloading the init.vim file.

Step -3-

I mapped as you can see in the script n to open a terminal in a new pane, my is the (Space bar) and once I click (space + n) a terminal will be triggered and I will enjoy writing my code while the terminal is opened.

  • To quit insert mode in the terminal, press Esc. Now, to switch to the code editor pane, use CTRL+w w. This shortcut can get annoying once you have more than two panels open, so I added the following shortcuts too. I mapped these too for quick jumping among opened panes, use these
" Better window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

Optional

If you want your terminal to exit the current buffer with key. you can use

tnoremap <Esc> <C-\><C-n>:q!<CR>

But since I want to switch in between several buffers I use without close the terminal I use instead:

tnoremap <Leader><Esc> <C-\><C-n>:q!<CR>

Final results


enter image description here

Reference:

Dr Neo
  • 724
  • 6
  • 11
3

Only way I know of is by using vim-shell, a third-party patch.

romandas
  • 4,086
  • 7
  • 29
  • 33
  • To be pedantic, vim-shell is a patch, not an 'add-on' (which to me, at least, implies that it's a script). I haven't tried it personally, but the vim-shell page on the Vim wiki unfortunately suggests that it won't compile with Vim 7.1+. – Yewge Aug 06 '09 at 14:38
  • Changed to appease the pedant. :) (Had to type something longer than 15 characters. 'Fixed' wasn't long enough) – romandas Aug 06 '09 at 16:52
  • Shougo/vimshell (https://github.com/Shougo/vimshell.vim) seems to work rather well. It does require building a dynamic library, but it is quite simple (cd /vimproc; make) – Wayne Walker Oct 27 '15 at 18:53
3

I use this now, you may can try. VimShell

Gatspy
  • 1,642
  • 3
  • 13
  • 13
3

Split the screen and run command term ++curwin to run the terminal inside the Vim buffer. Following command does both and worked for me:

:bo 10sp | term ++curwin
Subrat Prasad
  • 133
  • 1
  • 9
3

If you are interested in quick answer, here is it: :vert term. It will split your screen vertically and open up terminal.

2

Try vterm, which is a pretty much full feature shell inside vim. It is slightly buggy with its history and clear functions, and still in development, but it still is pretty good

Alexis Dumas
  • 1,299
  • 11
  • 30
2

Assuming your version of vim supports +term command first, set shell for vim to use in one command (e.g. set=/usr/bin/zsh), and then run the command +term (i.e. bo 15vs +term). you may have to do some additional maneuvering of your windows (i.e. deleting one and rotating), but you'll have your terminal.

gehbiszumeis
  • 3,525
  • 4
  • 24
  • 41
ClxKs
  • 21
  • 2
2

With vim 8.1.3741, just type :terminal to start a terminal inside of vim.

Try map :nnoremap ]t :terminal<CR> to do that quicker!

guo-sj
  • 43
  • 7
0

I acknowledge that I am not strictly answering your question, but what has worked better for me when using Vim and Terminals in the same window is Tmux (which is kind of a "run in the background software" like, similar to screen, although this one works better with splits and tabs).

This post will help you to understand how they work together: 'Tmux and Vim — even better together'.

This way we can convert Vim into a powerful IDE

Javi
  • 913
  • 2
  • 13
  • 15
0

You could also try Floaterm plug-in. It's quite easy to use. Just type :FloatermToggle() and a floating terminal tab appears in the middle of your vim tab.