1
0

terminal.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. -- apply default terminal settings
  2. vim.api.nvim_create_autocmd('TermOpen', {
  3. callback = function()
  4. vim.bo.scrollback = 10000
  5. vim.opt_local.number = false
  6. vim.opt_local.relativenumber = false
  7. vim.b.miniindentscope_disable = true
  8. end
  9. })
  10. -- preserve window structure when exiting terminal via C-d
  11. vim.api.nvim_create_autocmd('TermClose', {
  12. callback = function(opts)
  13. -- don't trigger when force deleting
  14. if vim.api.nvim_buf_get_option(opts.buf, 'modified') then
  15. return
  16. end
  17. MiniBufremove.delete(opts.buf)
  18. end,
  19. -- needed so statusline properly updates
  20. nested = true,
  21. })
  22. -- automatically enter/leave terminal mode
  23. vim.api.nvim_create_autocmd('TermOpen', { command = 'startinsert' })
  24. vim.api.nvim_create_autocmd({ 'WinEnter', 'BufWinEnter' }, {
  25. pattern = 'term://*',
  26. command = 'startinsert',
  27. })
  28. vim.api.nvim_create_autocmd('BufLeave', {
  29. pattern = 'term://*',
  30. command = 'stopinsert',
  31. })
  32. -- leave insert mode with <ESC><ESC>
  33. vim.keymap.set('t', '<ESC><ESC>', '<C-\\><C-N>')
  34. vim.keymap.set('t', '<C-[><C-[>', '<C-\\><C-N>')
  35. -- opening terminals
  36. vim.keymap.set('n', '<Leader>tv', '<cmd>vertical term $SHELL<CR>')
  37. vim.keymap.set('n', '<Leader>to', '<cmd>term $SHELL<CR>')