create menus similar to terminal mode mappings, but you have to
use |:tlmenu| instead of |:tmenu|.
Mouse input has the following behavior:
- If the program has enabled mouse events, the corresponding events will be
forwarded to the program.
- If mouse events are disabled (the default), terminal focus will be lost and
the event will be processed as in a normal buffer.
- If another window is clicked, terminal focus will be lost and nvim will jump
to the clicked window
- If the mouse wheel is used while the mouse is positioned in another window,
the terminal won't lose focus and the hovered window will be scrolled.
==============================================================================
Configuration *terminal-config*
Options: 'modified', 'scrollback'
Events: |TermOpen|, |TermEnter|, |TermLeave|, |TermClose|
Highlight groups: |hl-TermCursor|
Terminal sets local defaults for some options, which may differ from your
global configuration.
- 'list' is disabled
- 'wrap' is disabled
- 'number' is disabled
- 'relativenumber' is disabled
- 'signcolumn' is set to "no"
- 'foldcolumn' is set to "0"
You can change the defaults with a TermOpen autocommand: >vim
au TermOpen * setlocal list
TERMINAL COLORS ~
The `{g,b}:terminal_color_x` variables control the terminal color palette,
where `x` is the color index between 0 and 15 inclusive. The variables are
read during |TermOpen|. The value must be a color name or hexadecimal string.
Example: >vim
let g:terminal_color_4 = '#ff0000'
let g:terminal_color_5 = 'green'
Only works for RGB UIs (see 'termguicolors'); for 256-color terminals the
color index is just forwarded.
Editor highlighting (|syntax-highlighting|, |highlight-groups|, etc.) has
higher precedence: it is applied after terminal colors are resolved.
------------------------------------------------------------------------------
EVENTS *terminal-events*
Applications running in a :terminal buffer can send requests, which Nvim
exposes via the |TermRequest| event.
OSC 7: change working directory *terminal-osc7*
To handle OSC 7 emitted from :terminal processes, this code will :cd to the
directory indicated in the request. >lua
vim.api.nvim_create_autocmd({ 'TermRequest' }, {
desc = 'Handles OSC 7 dir change requests',
callback = function(ev)
if string.sub(ev.data.sequence, 1, 4) == '\x1b]7;' then
local dir = string.gsub(ev.data.sequence, '\x1b]7;file://[^/]*', '')
if vim.fn.isdirectory(dir) == 0 then
vim.notify('invalid dir: '..dir)
return
end
vim.api.nvim_buf_set_var(ev.buf, 'osc7_dir', dir)
if vim.o.autochdir and vim.api.nvim_get_current_buf() == ev.buf then
vim.cmd.cd(dir)
end
end
end
})
vim.api.nvim_create_autocmd({ 'BufEnter', 'WinEnter', 'DirChanged' }, {
callback = function(ev)
if vim.b.osc7_dir and vim.fn.isdirectory(vim.b.osc7_dir) == 1 then
vim.cmd.cd(vim.b.osc7_dir)
end
end
})
To try it out, select the above code and source it with `:'<,'>lua` (or
`g==`), then run this command in a :terminal buffer: >
printf "\033]7;file://./foo/bar\033\\"
OSC 52: write to system clipboard *terminal-osc52*
Applications in the :terminal buffer can write to the system clipboard by
emitting an OSC 52 sequence. Example: >
printf '\033]52;;%s\033\\' "$(echo -n 'Hello world' | base64)"
Nvim uses the configured |clipboard| provider to write to the system
clipboard. Reading from the system clipboard with OSC 52 is not supported, as
this would allow any arbitrary program in the :terminal to read the user's
clipboard.
OSC 52 sequences sent from the :terminal buffer do not emit a |TermRequest|
event. The event is handled directly by Nvim and is not forwarded to plugins.
OSC 133: shell integration *terminal-osc133* *shell-prompt*
Shells can emit semantic escape sequences (OSC 133) to mark where each prompt
starts and ends. The start of a prompt is marked