6

Full restore If you want to restore layout with multiple termina buffers, you must restore other windows and buffers too, so it's in fact a full buffer layout restore, it's usage is not limited to terminal buffers. Three things must be done to achive that: Split windows according to saved layout. We can use result of winlayout() to do this. Load buffer in ...


5

First, your function can be simplified into let bufnr = term_start(&shell, {"hidden": 1}) Second, it's not a problem to have buftype ==# 'terminal' and set nobuflisted together, as these are two different options. So if bufnr call setbufvar(bufnr, "buflisted", 0) endif is very much okay. However, the real question is: why you create a terminal at ...


4

You need to use :tnoremap to map keys in the :terminal window. So if you want that to work in both normal mode of a regular buffer and of terminal windows, you need to add another set of mappings for the terminal: tnoremap <C-J> <C-W><C-J> tnoremap <C-K> <C-W><C-K> tnoremap <C-L> <C-W><C-L> tnoremap <...


4

Neovim's terminal has "a specialty": a mouse click automatically switches it to "Terminal-Normal" mode. (BTW. That's not a case for Vim, so it does not suffer from this issue.) So it won't work from <LeftMouse>, but we can map <LeftRelease> instead: if has('nvim') augroup terminal_setup | au! autocmd TermOpen * nnoremap <buffer&...


3

I linked a bunch of Bash stuff here. Sorry if that's off the mark but the points made are almost all *nix and shell flavor agnostic. So you are looking to read an environment variable form a shell running in one of Vim's terminal buffers. Unfortunately, such variables are located in the shell process's memory and the internals of a process, including said ...


3

Make a buffer active by its number You can combine win_gotoid() & win_findbuf() to accomplish this: :call win_gotoid(get(win_findbuf(g:tn), 0)) But we can do better for terminal like things by improving a few things: Automatically set our variable on TerminalOpen autocmd Provide methods to send text to the terminal Provide a command to jump to the ...


3

Use :belowright: :belowright terminal Or, more succinctly: :bel term This command is a modifier and affects the command run right after it. (Another useful modifier here is :vertical, to split vertically instead.)


3

I assume you aren't literally asking for a --start-terminal flag :) ...but you can specify a command for Vim to run after it starts up using the -c flag. So this should be as easy as vim -c ':term ++curwin' When I run it I am indeed in a terminal window on the shell command line and it's the only window open. Hopefully that covers what you're asking for.


3

Terminal buffer is special: When the job has finished and no changes were made to the buffer: closing the window will wipe out the buffer. Change buffer type will stop this. Manual After job finished, clear buffer type: setlocal buftype= This also works: setlocal modifiable " make any change, the 1st change will convert terminal buffer to be a normal ...


2

Thanks to @Matt I now know that if I close the terminal buffer myself instead of having the 'term_finish':'close' argument of term_start() do it, then it doesn't do the weird behavior of sometimes opening a different file. So I've 'term_finish':'close' that with an exit_cb that closes the buffer. Here's what I use in full: function! JW_on_term_exit(a, b) ...


2

As @statox suggested in comments I should have used tnoremap to implement it. The following works fine: execute "tnoremap ".g:toggle_term ." <C-w>:call ToggleTerminal()<CR>" The mistake I initially made was the space right after the N execute "tnoremap ".g:toggle_term ." <C-w>N :call ToggleTerminal()<CR>" and since I rebound ...


2

Sureā€”use <C-w>: in your terminal mappings to get a colon command line instead of "escaping" to normal mode: tnoremap <silent> <C-H> <C-W>:call WinTabSwitch('h')<CR>


2

So the top buffer became "a mirror" of the terminal buffer with the number 2. Your problem is that you confuse "buffer" and "window". Those "rectangles" you see are called "windows", while their contents are called "buffers". So the command :b 2 says "I want a buffer number two to be shown in the current window". And that's not what you really wanted. ...


2

As of patch 8.1.2350, Ctrl-V will emit again the translated key, even if modifyOtherKeys has been set. To get the raw escape sequence, you can instead use now Ctrl-Shift-V


2

NOTE: This answer reflects the first version of the question, before edits that made it more focused on a specific problem. Leaving this answer here in case it's useful to the original poster or others. Resizing the terminal You can give the :terminal command a ++rows=20 or ++cols=100 argument to size it from the start. You can use :vertical to open it ...


2

This is expected. Vim implements a terminal emulator for :terminal (since it needs to keep it inside its window) and it implements one that's compatible with "xterm" (since it needs to pick a specific terminal to implement and "xterm" is a very popular one.) You can still enable 256-color support by setting TERM=xterm-256color in your Vim terminal. See :...


2

Not all Ex commands allow | to be used as a command separator, some Ex commands want to take | as an argument. The common workaround is to use :execute to wrap those commands that do not allow | as a command separator. See :help :bar or :help :| for more details and a list of commands that take | as an argument: These commands see the '|' as their ...


2

In modern vim/neovim there is :h g:terminal_ansi_colors (vim) or 16 of g:terminal_color_0 .. g:terminal_color_15 (neovim). If you open gruvbox colorscheme you use, you will find those definitions there (most probably). Basically: your whatever terminal can have palette of base 16 colors defined (there are defaults for each type of terminal, but you can ...


2

In GVim, you can control the 16 ANSI colors used by your terminal with the g:terminal_ansi_colors variable. See :help g:terminal_ansi_colors: In GUI mode or with 'termguicolors', the 16 ANSI colors used by default in new terminal windows may be configured using the variable g:terminal_ansi_colors, which should be a list of 16 color names or ...


1

gdb argument support is added at patch 8.0.1713: Termdebug [gdb-args] command command argument support is added at patch 8.0.1725: TermdebugCommand command [command-args]


1

I came up with a solution using channels, an idea based on Bram's presentation in this video. command! -complete=shellcmd -nargs=+ Shell call s:TmpShellOutput(<q-args>) function! s:TmpShellOutput(cmdline) abort if bufexists('tmplog') " clear buffer content call deletebufline('tmplog', 1, '$') else " create new ...


1

Fixed by removing botright new and then calling botright call term_start($SHELL) (to start a Terminal buffer if one doesn't exist) or execute 'botright sbuffer' . g:terminal_drawer.buffer_id (to show the buffer) fixed it. Here is the full function now: let g:terminal_drawer = { 'win_id': v:null, 'buffer_id': v:null } function! ToggleTerminalDrawer() abort ...


1

So :help terminal-communication lists term_sendkeys(), then the JSON API you can access with the escape sequence, then finally: Use the client-server mechanism. This works on machines with an X server and on MS-Windows. I'm not sure if that's meant to say that the other mechanisms will not work on MS-Windows, but at least they're saying this one should ...


1

From :h terminal-start: When the terminal starts, the buffer contents are updated and the buffer is named in the form of term://{cwd}//{pid}:{cmd}. This naming scheme is used by |:mksession| to restore a terminal buffer (by restarting the {cmd}). Therefore you can not do this, unless you manually "swap" buffer names before :mksession and on autocmd ...


1

The solution is using job-exit_cb handler, (see :help job-exit_cb) A working example is func! g:Exit_cb(job, exit_code) echo term_getjob(2) let pid = matchstr(a:job, '^\%(process \)\zs\d\+') echom "job " . pid . " finished with exit_code " . a:exit_code endfunc call term_start('bash', {'exit_cb': function('g:Exit_cb')}) Run above code, then ...


1

set t_TE= t_TI= This in vimrc disables modifyOtherKeys (:h modifyOtherKeys), which was causing the problems


1

I slightly refactored your function and made it more robust. After quitting the terminal, with for example exit command in Windows, you will get an error when trying to invoke your ToggleTerminal() function. let s:term_buf_nr = -1 function! s:ToggleTerminal() abort if s:term_buf_nr == -1 execute "botright terminal" let s:term_buf_nr = ...


1

The help for the function term_setansicolors provides some more details. The short story is these 16 colors form a conventional palette which terminal programs use when outputting text. You can set them to anything you want, but it's best to stick to the vague color descriptions below. term_setansicolors({buf}, {colors}) *term_setansicolors()* ...


1

You can create a mapping which will close the terminal buffer directly. Then Vim will not open an additional empty buffer and will exit. For simplicity I assume that the terminal is running shell, so Ctrl-D exits it normally. tnoremap <silent><C-D> <C-D><C-\><C-N>ZQ


1

EDIT The problem was actually a bug in neovim fixed by the commit 47b7b471fa which is now merged in master. So after asking the Neovim issue tracker it turns out this is the current "expected" behavior of the code: In terminal.c the function adjust_topline() iterates over FOR_ALL_WINDOWS_IN_TAB, changing that to iterate over FOR_ALL_TAB_WINDOWS fixes my ...


Only top voted, non community-wiki answers of a minimum length are eligible