feat/pack (#1)
Reviewed-on: #1 Co-authored-by: Tomas Mirchev <contact@tomastm.com> Co-committed-by: Tomas Mirchev <contact@tomastm.com>
This commit was merged in pull request #1.
This commit is contained in:
109
lua/core/events.lua
Normal file
109
lua/core/events.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
local api = vim.api
|
||||
local au = api.nvim_create_autocmd
|
||||
local group = api.nvim_create_augroup('core.events', { clear = true })
|
||||
|
||||
-- Automatically create a scratch buffer if Neovim starts with no files
|
||||
au('VimEnter', {
|
||||
group = group,
|
||||
callback = function()
|
||||
-- Only trigger if no file arguments are passed
|
||||
if vim.fn.argc() == 0 then
|
||||
vim.cmd('enew')
|
||||
vim.bo.buftype = 'nofile'
|
||||
vim.bo.bufhidden = 'wipe'
|
||||
vim.bo.swapfile = false
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Highlight when yanking (copying) text
|
||||
au('TextYankPost', {
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.highlight.on_yank({ timeout = 200 })
|
||||
end,
|
||||
})
|
||||
|
||||
-- Disable comment continuation only when using 'o'/'O', but keep it for <Enter>
|
||||
au('FileType', {
|
||||
group = group,
|
||||
pattern = '*',
|
||||
callback = function()
|
||||
vim.opt_local.formatoptions:remove('o')
|
||||
end,
|
||||
})
|
||||
|
||||
-- Show cursor line only in active window
|
||||
au({ 'WinEnter', 'InsertLeave' }, {
|
||||
group = group,
|
||||
callback = function()
|
||||
if vim.w.auto_cursorline then
|
||||
vim.wo.cursorline = true
|
||||
vim.w.auto_cursorline = nil
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
au({ 'WinLeave', 'InsertEnter' }, {
|
||||
group = group,
|
||||
callback = function()
|
||||
-- Keep it on NvimTree to show current file
|
||||
if vim.bo.filetype == 'NvimTree' then
|
||||
return
|
||||
end
|
||||
if vim.wo.cursorline then
|
||||
vim.w.auto_cursorline = true
|
||||
vim.wo.cursorline = false
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Autocompletion
|
||||
au('LspAttach', {
|
||||
group = group,
|
||||
callback = function(event)
|
||||
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
-- Enable native completion
|
||||
if client:supports_method('textDocument/completion') then
|
||||
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
|
||||
end
|
||||
end,
|
||||
})
|
||||
vim.lsp.handlers['textDocument/completion'] = function(err, result, ctx, config)
|
||||
if err or not result then
|
||||
return
|
||||
end
|
||||
for _, item in ipairs(result.items or result) do
|
||||
if item.kind then
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
|
||||
item.menu = '[' .. kind .. ']'
|
||||
end
|
||||
end
|
||||
return vim.lsp.completion._on_completion_result(err, result, ctx, config)
|
||||
end
|
||||
|
||||
au('InsertEnter', {
|
||||
group = group,
|
||||
once = true,
|
||||
callback = function()
|
||||
require('nvim-ts-autotag').setup()
|
||||
require('nvim-autopairs').setup()
|
||||
end,
|
||||
})
|
||||
|
||||
require('modules.theme')
|
||||
au('UIEnter', {
|
||||
group = group,
|
||||
once = true,
|
||||
callback = function()
|
||||
vim.schedule(function()
|
||||
require('modules.navigation')
|
||||
require('plugins.language-manager').setup()
|
||||
require('modules.diagnostics')
|
||||
end)
|
||||
end,
|
||||
})
|
||||
Reference in New Issue
Block a user