78 lines
2.0 KiB
Lua
78 lines
2.0 KiB
Lua
-- Automatically create a scratch buffer if Neovim starts with no files
|
|
vim.api.nvim_create_autocmd('VimEnter', {
|
|
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
|
|
vim.api.nvim_create_autocmd('TextYankPost', {
|
|
callback = function()
|
|
vim.highlight.on_yank()
|
|
end,
|
|
})
|
|
|
|
-- Disable comment continuation only when using 'o'/'O', but keep it for <Enter>
|
|
vim.api.nvim_create_autocmd('FileType', {
|
|
pattern = '*',
|
|
callback = function()
|
|
vim.opt_local.formatoptions:remove('o')
|
|
end,
|
|
})
|
|
|
|
-- Show cursor line only in active window
|
|
vim.api.nvim_create_autocmd({ 'WinEnter', 'InsertLeave' }, {
|
|
callback = function()
|
|
if vim.w.auto_cursorline then
|
|
vim.wo.cursorline = true
|
|
vim.w.auto_cursorline = nil
|
|
end
|
|
end,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd({ 'WinLeave', 'InsertEnter' }, {
|
|
callback = function()
|
|
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
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('minimal_lsp', { clear = true }),
|
|
callback = function(ev)
|
|
local client = vim.lsp.get_client_by_id(ev.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, ev.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
|