Add autocmds to improve :terminal usability
This commit is contained in:
parent
51c3bf1b9e
commit
50cc8ae3ab
@ -22,3 +22,46 @@ vim.api.nvim_create_autocmd('BufRead', {
|
||||
})
|
||||
end
|
||||
})
|
||||
|
||||
-- Start terminals in insert mode
|
||||
vim.api.nvim_create_autocmd('TermOpen', {
|
||||
group = group, pattern = 'term://*',
|
||||
callback = function()
|
||||
vim.cmd [[ startinsert ]]
|
||||
end
|
||||
})
|
||||
|
||||
-- Don't show the line number column in terminal-insert mode
|
||||
vim.api.nvim_create_autocmd('TermEnter', {
|
||||
group = group, pattern = 'term://*',
|
||||
callback = function()
|
||||
vim.opt.number = false
|
||||
vim.opt.relativenumber = false
|
||||
vim.opt.signcolumn = 'no'
|
||||
end
|
||||
})
|
||||
|
||||
-- But do show the line number column in terminal-normal mode
|
||||
vim.api.nvim_create_autocmd('TermLeave', {
|
||||
group = group, pattern = 'term://*',
|
||||
callback = function()
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
vim.opt.signcolumn = 'yes'
|
||||
end
|
||||
})
|
||||
|
||||
-- Automatically press enter when the terminal process exit successfully
|
||||
vim.api.nvim_create_autocmd('TermClose', {
|
||||
group = group,
|
||||
pattern = 'term://*',
|
||||
callback = function()
|
||||
if vim.v.event.status == 0 then
|
||||
-- Exit success, send enter to close the buffer
|
||||
vim.api.nvim_input('<CR>')
|
||||
else
|
||||
-- Exit failure, enter normal mode for inspection
|
||||
vim.api.nvim_input('<C-\\><C-n>')
|
||||
end
|
||||
end
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user