Move autocmds.lua to plugin directory
This commit is contained in:
67
plugin/autocmds.lua
Normal file
67
plugin/autocmds.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- Create a group to namespace autocmds
|
||||
local group = vim.api.nvim_create_augroup('benie', { clear = true })
|
||||
|
||||
-- Restore cursor position across sessions
|
||||
-- https://github.com/neovim/neovim/issues/16339#issuecomment-1457394370
|
||||
vim.api.nvim_create_autocmd('BufRead', {
|
||||
group = group,
|
||||
callback = function(opts)
|
||||
vim.api.nvim_create_autocmd('BufWinEnter', {
|
||||
once = true,
|
||||
buffer = opts.buf,
|
||||
callback = function()
|
||||
local ft = vim.bo[opts.buf].filetype
|
||||
local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1]
|
||||
if not (ft:match('commit') and ft:match('rebase'))
|
||||
and last_known_line > 1
|
||||
and last_known_line <= vim.api.nvim_buf_line_count(opts.buf)
|
||||
then
|
||||
vim.api.nvim_feedkeys([[g`"]], 'nx', false)
|
||||
end
|
||||
end
|
||||
})
|
||||
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
|
||||
})
|
||||
Reference in New Issue
Block a user