nvim: switch to lazy

This commit is contained in:
2024-12-06 11:36:33 +02:00
parent 65a6a5c334
commit 65c7027985
30 changed files with 1243 additions and 1537 deletions

View File

@@ -0,0 +1,18 @@
-- Disable builtins
vim.g.loaded_gzip = 1
vim.g.loaded_zip = 1
vim.g.loaded_zipPlugin = 1
vim.g.loaded_tar = 1
vim.g.loaded_tarPlugin = 1
vim.g.loaded_getscript = 1
vim.g.loaded_getscriptPlugin = 1
vim.g.loaded_vimball = 1
vim.g.loaded_vimballPlugin = 1
vim.g.loaded_2html_plugin = 1
vim.g.loaded_matchit = 1
vim.g.loaded_matchparen = 1
vim.g.loaded_logiPat = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_shada_plugin = 1

View File

@@ -0,0 +1,16 @@
vim.filetype.add({
extension = {
yml = 'yaml',
docker = 'dockerfile',
},
filename = {
['.gitignore'] = 'conf',
Podfile = 'ruby',
Brewfile = 'ruby',
Vagrantfile = 'ruby',
},
pattern = {
['*.gradle'] = 'groovy',
['*.env.*'] = 'env',
},
})

View File

@@ -0,0 +1,34 @@
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = ' '
-- Setup lazy.nvim
require("lazy").setup({
spec = {
-- import your plugins
{ import = "plugins" },
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "nord" } },
-- automatically check for plugin updates
checker = { enabled = false },
change_detection = {
notify = false,
},
})

View File

@@ -0,0 +1,142 @@
local function map(mode, lhs, rhs, opts)
local options = { noremap = true }
if opts then options = vim.tbl_extend('force', options, opts) end
vim.keymap.set(mode, lhs, rhs, options)
end
local function nmap(lhs, rhs, opts)
map('n', lhs, rhs, opts)
end
--- Mappings
-- Essentials
vim.g.mapleader = ' '
-- TODO: move to keys (lazy telescope)
vim.keymap.set('n', '<leader>ff', function() require('telescope.builtin').find_files({ hidden = true }) end)
vim.keymap.set('n', '<leader>fb', function() require('telescope.builtin').buffers({ hidden = true }) end)
vim.keymap.set('n', '<leader>fo', function() require('telescope.builtin').find_files({ cwd = '~/Syncthing/Obsidian/Personal/', search_file = '*.md' }) end)
vim.keymap.set('n', '<leader>fO', function() require('telescope.builtin').live_grep({ cwd = '~/Syncthing/Obsidian/Personal/', search_file = '*.md' }) end)
vim.keymap.set('n', '<leader>fh', function() require('telescope.builtin').help_tags() end)
vim.keymap.set('n', '<leader>fq', function() require('telescope.builtin').quickfix() end)
nmap(';', ':')
map('v', ';', ':')
nmap(',,', '<C-^>')
-- TODO: stop this madness, :h autowrite
-- doesnt seem to work well in terminal
nmap('<leader>w', ':w<CR>')
nmap('Q', ':q!<CR>')
nmap('<leader><space>', ':nohlsearch<CR>', { silent = true })
-- Convenience
nmap('yy', 'Y')
nmap('Y', 'y$')
nmap('N', 'Nzz')
nmap('n', 'nzz')
nmap('j', 'gj')
nmap('k', 'gk')
nmap('H', '^')
nmap('L', '$')
nmap('J', 'mzJ`z')
-- nmap('K', '<Nop>')
nmap('gQ', '<Nop>')
nmap('vv', ':vs<CR>')
-- Tabs
nmap('<leader>t', ':tabnew<CR>')
nmap('<Tab>', ':tabnext<CR>')
nmap('<S-Tab>', ':tabprevious<CR>')
nmap('<leader>1', '1gt')
nmap('<leader>2', '2gt')
nmap('<leader>3', '3gt')
nmap('<leader>4', '4gt')
nmap('<leader>5', '5gt')
-- Visual mode
map('v', '.', ':normal .<CR>')
map('v', 'J', ':m \'>+1<CR>gv=gv')
map('v', 'K', ':m \'<-2<CR>gv=gv')
map('v', '<', '<gv')
map('v', '>', '>gv')
-- vim-easy-align
map("n", "ga", "<Plug>(EasyAlign)")
map("x", "ga", "<Plug>(EasyAlign)")
-- nvim-tree.lua
-- nmap('<leader>n', ':NvimTreeToggle<CR>')
-- nmap('<leader>N', ':NvimTreeFindFile<CR>')
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
-- glow.vim
nmap('<leader>p', ':Glow<CR>')
-- fugitive.vim
nmap('<leader>ga', ':Gwrite<CR>')
nmap('<leader>gs', ':Git<CR>')
nmap('<leader>gb', ':Git blame<CR>')
-- rails-vim
-- nmap('<leader>a', ':A<CR>')
nmap('<leader>a', function()
local path = vim.fn.expand('%')
vim.print(path)
-- if path.ends('_spec.rb') then
-- vim.print('spec')
-- elseif path.contains('app') then
-- vim.print('app')
-- else
-- vim.print('nothing')
-- end
end)
-- test
nmap('<leader>r', function() os.execute("tmux send-keys -t '{down-of}' './bin/rspec '" .. vim.fn.expand("%") .. " Enter") end)
nmap('<leader>R', function() os.execute("tmux send-keys -t '{down-of}' './bin/rspec .' Enter") end)
-- grep
nmap('<C-f>', ':grep ')
-- trim whitespace
nmap('<leader>W', ':TrimWhitespace<CR>')
-- EXPERIMENTAL:
-- this is bad because of the accidental missclicks
-- nmap('<leader>x', ":call delete(expand('%')) | bdelete!<CR>")
nmap('<leader>q', ':copen<CR>')
-- pick one (comma makes more sense?)
nmap(']q', ':cnext<CR>')
nmap('[q', ':cprev<CR>')
nmap(',w', ':cnext<CR>')
nmap(',q', ':cprev<CR>')
-- command mode
vim.keymap.set('c', '<C-a>', '<Home>')
vim.keymap.set('c', '<C-e>', '<End>')
-- paste in visual mode and keep available
local expr = { expr = true, noremap = false, silent = false }
vim.keymap.set('x', 'p', [['pgv"'.v:register.'y`>']], expr)
vim.keymap.set('x', 'P', [['Pgv"'.v:register.'y`>']], expr)
-- vim.keymap.set('n', 'gQ', 'mzgggqG`z<cmd>delmarks z<cr>zz', { desc = 'Format buffer' })
vim.keymap.set('n', '<C-d>', '<C-d>zz', { desc = 'Scroll downwards' })
vim.keymap.set('n', '<C-u>', '<C-u>zz', { desc = 'Scroll upwards' })
-- TODO: luaify
-- create alternate buffer if not exist
-- vim.api.nvim_exec([[
-- command AC :execute "e " . eval('rails#buffer().alternate()')
-- ]], false)
-- vim.keymap.set('n', '<leader>to', '<cmd>tabonly<cr>', { desc = 'Close other tab pages' })
-- Make U opposite to u.
-- vim.keymap.set('n', 'U', '<C-r>', { desc = 'Redo' })

View File

@@ -0,0 +1,140 @@
local opt, g = vim.opt, vim.g
opt.smartindent = true -- Autoindenting when starting a new line
opt.completeopt = { 'menu', 'menuone', 'noselect' }
opt.tabstop = 2 -- Tab counts as 2 columns
opt.shiftwidth = 2 -- Numbers of spaces to (auto)indent
opt.expandtab = true -- Tabs to spaces
opt.clipboard = 'unnamedplus' -- Share clipboard with the OS
opt.number = true -- Display line numbers
opt.synmaxcol = 500 -- Do not try to highlight lines longer than 500 characters
opt.lazyredraw = true -- Do not redraw while running macros
opt.showmatch = true -- Show matching braces
opt.matchtime = 2 -- Show matching braces for 2 tenths of second
opt.showmode = true -- Shows when you are in insert mode
opt.title = true -- Show title in console status bar
opt.laststatus = 3 -- Single status line
opt.wrap = false -- Dont wrap lines
opt.scrolloff = 5 -- Keep 5 rows on the screen when scrolling
opt.sidescrolloff = 15 -- Horizontal scrolloff
opt.visualbell = false -- No visual bell
opt.backup = false -- No backups
opt.writebackup = false -- No backups
opt.swapfile = false -- No backups
opt.mouse = 'a' -- Support mouse (for proper mouse highlight)
opt.list = true -- List mode
opt.timeoutlen = 1000 -- Delay for mappings
opt.ttimeoutlen = 0 -- Delay between modes
opt.termguicolors = true -- 24-bit RGB color
opt.listchars = {
nbsp = '', -- CIRCLED REVERSE SOLIDUS (U+29B8, UTF-8: E2 A6 B8)
extends = '»', -- RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (U+00BB, UTF-8: C2 BB)
precedes = '«', -- LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (U+00AB, UTF-8: C2 AB)
trail = '', -- BULLET (U+2022, UTF-8: E2 80 A2)
space = ' ',
tab = ''
}
opt.fillchars = {
diff = '',
eob = ' ', -- NO-BREAK SPACE (U+00A0, UTF-8: C2 A0) to suppress ~ at EndOfBuffer
-- vert = '│', -- window border when window splits vertically ─ ┴ ┬ ┤ ├ ┼
vert = '',
msgsep = '',
fold = '·', -- MIDDLE DOT (U+00B7, UTF-8: C2 B7)
foldopen = '',
foldsep = '',
foldclose = ''
}
-- Use in vertical diff mode, blank lines to keep sides aligned, Ignore whitespace changes
opt.diffopt = vim.opt.diffopt
+ {
'vertical',
'iwhite',
'hiddenoff',
'foldcolumn:0',
'context:4',
'algorithm:histogram',
'indent-heuristic',
}
opt.shortmess = {
t = true, -- truncate file messages at start
A = true, -- ignore annoying swap file messages
o = true, -- file-read message overwrites previous
O = true, -- file-read message overwrites previous
T = true, -- truncate non-file messages in middle
f = true, -- (file x of x) instead of just (x of x
F = true, -- Don't give file info when editing a file, NOTE: this breaks autocommand messages
s = true,
I = true, -- disable welcome message (:intro)
a = true, -- shortmess for everything
c = true,
W = true, -- Don't show [w] or written when writing
}
if vim.fn.executable('rg') > 0 then
vim.o.grepprg = [[rg --glob "!.git" --no-heading --vimgrep --follow $*]]
end
-- ignore when autocompleting
opt.wildignore = {
'*.aux', '*.out', '*.toc', '*.o', '*.obj',
'*.dll', '*.jar', '*.pyc', '*.rbc', '*.class',
'*.gif', '*.ico', '*.jpg', '*.jpeg', '*.png',
'*.avi', '*.wav', '*.*~', '*~ ', '*.swp',
'.lock', '.DS_Store', 'tags.lock'
}
-- CtrlSF
-- g.ctrlsf_ackprg = 'rg'
-- g.ctrlsf_regex_pattern = 1
-- g.ctrlsf_case_sensitive = 'smart'
-- g.ctrlsf_default_root = 'project'
-- g.ctrlsf_context = '-B 1 -A 1'
-- g.ctrlsf_position = 'bottom'
-- g.ctrlsf_winsize = '40%'
-- g.ctrlsf_mapping = {
-- next = 'n',
-- prev = 'N',
-- }
g.ruby_host_prog = 'asdf exec neovim-ruby-host'
-- highlight yanked text briefly
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank {
higroup = 'Search',
timeout = 250,
on_visual = true,
}
end,
})
-- resize splits when Vim is resized
vim.api.nvim_create_autocmd('VimResized', { command = 'horizontal wincmd =' })
vim.api.nvim_create_augroup('cursorline_focus', {})
vim.api.nvim_create_autocmd({ 'InsertLeave', 'WinEnter' }, {
group = 'cursorline_focus',
callback = function()
vim.wo.cursorline = true
end,
})
vim.api.nvim_create_autocmd({ 'InsertEnter', 'WinLeave' }, {
group = 'cursorline_focus',
callback = function()
vim.wo.cursorline = false
end,
})
-- Experimental
opt.iskeyword:prepend { '-' } -- treat dash separated words as a word textobject
opt.updatetime = 100
opt.timeout = true
opt.timeoutlen = 1000
opt.ttimeoutlen = 10

View File

@@ -0,0 +1,6 @@
local function trim_trailing_whitespace()
local pos = vim.api.nvim_win_get_cursor(0)
vim.cmd [[silent keepjumps keeppatterns %s/\s\+$//e]]
vim.api.nvim_win_set_cursor(0, pos)
end
vim.api.nvim_create_user_command('TrimWhitespace', trim_trailing_whitespace, {})

View File

@@ -0,0 +1 @@
return { 'kevinhwang91/nvim-bqf' }

View File

@@ -0,0 +1,165 @@
return {
{
'hrsh7th/nvim-cmp',
event = 'InsertEnter',
opts = function()
local lsp = {
kinds = {
-- Text = '󰉿',
-- Method = '',
-- Function = '󰊕',
-- Constructor = '',
-- Field = '󰜢',
-- Variable = '󰀫',
-- Class = '󰠱',
-- Interface = '󰒪',
-- Module = '',
-- Property = '󰜣',
-- Unit = '',
-- Value = '󰎠',
-- Enum = '',
-- Keyword = '󰌋',
-- Snippet = '',
-- Color = '󰏘',
-- File = '󰈙',
-- Reference = '󰋺',
-- Folder = '󰉋',
-- EnumMember = '',
-- Constant = '󰏿',
-- Struct = '󰙅',
-- Event = '',
-- Operator = '󰆕',
TypeParameter = '',
},
}
local menu = {
luasnip = '[snip]',
nvim_lsp = '[LSP]',
git = '[git]',
spell = '[spell]',
path = '[path]',
buffer = '[buf]',
}
local cmp = require 'cmp'
-- supertab-like mapping
local mapping = {
['<C-n>'] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Insert,
},
['<C-p>'] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Insert,
},
['<C-y>'] = cmp.mapping(
cmp.mapping.confirm {
behavior = cmp.SelectBehavior.Insert,
select = true,
},
{ 'i', 'c' }
),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-c>'] = cmp.mapping.complete {
config = {
sources = {
{ name = 'nvim_lsp' },
},
},
},
['<Up>'] = cmp.config.disable,
['<Down>'] = cmp.config.disable,
}
return {
completion = {
autocomplete = {
cmp.TriggerEvent.TextChanged,
cmp.TriggerEvent.InsertEnter,
},
},
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
mapping = mapping,
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- {
-- name = 'nvim_lsp',
-- entry_filter = function(entry, ctx)
-- return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()]
-- ~= 'Snippet'
-- end,
-- },
{ name = 'luasnip' },
{ name = 'git' },
}, {
-- { name = 'spell' },
{ name = 'buffer', keyword_length = 4 },
{ name = 'path' },
}),
-- sorting = {
-- comparators = {
-- cmp.config.compare.offset,
-- cmp.config.compare.exact,
-- cmp.config.compare.score,
-- -- function(entry1, entry2)
-- -- local entry1_kind = require('cmp.types').lsp.CompletionItemKind[entry1:get_kind()]
-- -- == 'Snippet'
-- -- local entry2_kind = require('cmp.types').lsp.CompletionItemKind[entry2:get_kind()]
-- -- == 'Snippet'
-- -- print(entry1_kind)
-- -- print(entry2_kind)
-- -- -- if entry1_kind and not entry2_kind then
-- -- -- return false
-- -- -- else
-- -- -- return true
-- -- -- end
-- -- return true
-- -- end,
-- -- cmp.config.compare.kind,
-- cmp.config.compare.sort_text,
-- cmp.config.compare.length,
-- cmp.config.compare.order,
-- },
-- },
-- formatting = {
-- format = function(entry, vim_item)
-- -- source name
-- vim_item.menu = menu[entry.source.name]
-- -- lsp kinds
-- if vim_item.kind ~= nil then
-- vim_item.kind = string.format(
-- '%s [%s]',
-- lsp.kinds[vim_item.kind],
-- vim_item.kind:lower()
-- )
-- end
-- -- shorten long items
-- vim_item.abbr = vim_item.abbr:sub(1, 30)
-- return vim_item
-- end,
-- },
-- experimental = { ghost_text = true },
}
end,
dependencies = {
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'f3fora/cmp-spell',
{
'petertriho/cmp-git',
opts = {
filetypes = {
'gitcommit',
'octo',
'markdown', -- for gh & glab CLI
},
},
},
},
},
}

View File

@@ -0,0 +1,4 @@
return {
'stevearc/dressing.nvim',
opts = {},
}

View File

@@ -0,0 +1,835 @@
local au = vim.api.nvim_create_augroup('LspAttach', { clear = true })
return {
{
'williamboman/mason.nvim',
cmd = 'Mason',
opts = {
ensure_installed = {},
registries = {
'github:mason-org/mason-registry',
},
},
config = function(_, opts)
require('mason').setup(opts)
local registry = require 'mason-registry'
registry:on('package:install:success', function()
vim.defer_fn(function()
-- trigger FileType event to possibly load this newly installed LSP server
require('lazy.core.handler.event').trigger {
event = 'FileType',
buf = vim.api.nvim_get_current_buf(),
}
end, 100)
end)
local function ensure_installed()
for _, tool in ipairs(opts.ensure_installed) do
local package = registry.get_package(tool)
if not package:is_installed() then
package:install()
end
end
end
if registry.refresh then
registry.refresh(ensure_installed)
else
ensure_installed()
end
end,
},
{
'neovim/nvim-lspconfig',
event = { 'BufReadPost', 'BufNewFile' },
init = function()
-- client log level
vim.lsp.set_log_level(vim.lsp.log_levels.INFO)
vim.api.nvim_create_user_command('LspFormat', function()
vim.lsp.buf.format { async = false }
end, {})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP tagfunc',
callback = function(args)
local bufnr = args.buf
vim.api.nvim_set_option_value(
'tagfunc',
'v:lua.vim.lsp.tagfunc',
{ buf = bufnr }
)
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP keymaps',
callback = function(args)
local bufnr = args.buf
local function map(mode, lhs, rhs)
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr })
end
map('n', 'gD', vim.lsp.buf.declaration)
map('n', 'gd', vim.lsp.buf.definition)
map('n', 'K', vim.lsp.buf.hover)
map('n', 'gi', vim.lsp.buf.implementation)
-- map({ 'n', 'i' }, '<C-s>', vim.lsp.buf.signature_help)
-- map('n', '<leader>wa', vim.lsp.buf.add_workspace_folder)
-- map('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder)
-- map('n', '<leader>wl', function()
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- end)
map('n', '<leader>D', vim.lsp.buf.type_definition)
-- map('n', '<leader>r', function()
-- require('conf.nui_lsp').lsp_rename()
-- end)
map('n', 'gr', function()
require('trouble').open { mode = 'lsp_references' }
end)
map('n', '<leader>li', vim.lsp.buf.incoming_calls)
map('n', '<leader>lo', vim.lsp.buf.outgoing_calls)
vim.opt.shortmess:append 'c'
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP highlight',
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if
client
and client.supports_method 'textDocument/documentHighlight'
then
local augroup_lsp_highlight = 'lsp_highlight'
vim.api.nvim_create_augroup(
augroup_lsp_highlight,
{ clear = false }
)
vim.api.nvim_create_autocmd(
{ 'CursorHold', 'CursorHoldI' },
{
group = augroup_lsp_highlight,
buffer = bufnr,
callback = vim.lsp.buf.document_highlight,
}
)
vim.api.nvim_create_autocmd('CursorMoved', {
group = augroup_lsp_highlight,
buffer = bufnr,
callback = vim.lsp.buf.clear_references,
})
end
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP inlay hints',
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if
client
and client.supports_method 'textDocument/inlayHint'
and pcall(require, 'vim.lsp.inlay_hint') -- NOTE: check that API exists
then
-- vim.notify(
-- 'register inlay hints',
-- vim.lsp.log_levels.DEBUG
-- )
vim.api.nvim_create_autocmd({
'BufWritePost',
'BufEnter',
'InsertLeave',
'FocusGained',
'CursorHold',
}, {
buffer = bufnr,
callback = function()
vim.lsp.inlay_hint.enable(
true,
{ bufnr = bufnr }
)
end,
})
vim.api.nvim_create_autocmd('InsertEnter', {
callback = function()
vim.lsp.inlay_hint.enable(
false,
{ bufnr = bufnr }
)
end,
})
-- initial request
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
end
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP code actions',
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if
client
and client.supports_method 'textDocument/codeAction'
then
vim.keymap.set(
{ 'n', 'v' },
'<leader>ca',
vim.lsp.buf.code_action,
{ buffer = bufnr }
)
end
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP notify',
callback = function(args)
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
-- if client then
-- vim.notify(
-- ('%s attached to buffer %s'):format(
-- client.name,
-- args.buf
-- ),
-- vim.log.levels.DEBUG
-- )
-- end
end,
})
-- local function periodic_refresh_semantic_tokens()
-- -- vim.notify(
-- -- 'periodic refresh semantic tokens',
-- -- vim.log.levels.DEBUG
-- -- )
-- vim.lsp.semantic_tokens.force_refresh()
-- vim.defer_fn(periodic_refresh_semantic_tokens, 30000)
-- end
-- local function debounce(ms, fn)
-- local timer = assert(vim.uv.new_timer())
-- return function(...)
-- local argv = { ... }
-- timer:start(ms, 0, function()
-- timer:stop()
-- vim.schedule_wrap(fn)(unpack(argv))
-- end)
-- end
-- end
-- vim.api.nvim_create_autocmd({ 'TextChanged', 'InsertLeave' }, {
-- callback = debounce(1000, function()
-- -- vim.notify('refresh semantic tokens', vim.log.levels.DEBUG)
-- vim.lsp.semantic_tokens.force_refresh()
-- end),
-- })
end,
dependencies = {
{
'folke/neoconf.nvim',
cmd = 'Neoconf',
config = false,
dependencies = { 'nvim-lspconfig' },
},
{ 'folke/neodev.nvim', opts = {} },
'hrsh7th/cmp-nvim-lsp',
'mason.nvim',
{
'williamboman/mason-lspconfig.nvim',
opts = {
ensure_installed = {
'lua_ls',
-- 'ruby-lsp ',
-- 'pylyzer',
-- 'rust_analyzer',
'dockerls',
'docker_compose_language_service',
'yamlls',
'jsonls',
'html',
'cssls',
'gopls',
'clangd',
'texlab',
'vtsls',
-- 'denols',
-- 'eslint',
-- 'vale_ls',
'terraformls',
'helm_ls',
'bashls'
},
handlers = {
function(server_name)
-- vim.notify(
-- 'Mason LSP setup ' .. server_name,
-- vim.log.levels.DEBUG
-- )
require('lspconfig')[server_name].setup {}
end,
['yamlls'] = function()
require('lspconfig').yamlls.setup {
single_file_support = true,
filetypes = {
'yaml',
'yaml.gha',
},
root_dir = function(filename)
return require('lspconfig.util').find_git_ancestor(
filename
) or vim.uv.cwd()
end,
settings = {
yaml = {
editor = { formatOnType = true },
schemas = {
-- GitHub CI workflows
['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*',
-- Helm charts
['https://json.schemastore.org/chart.json'] = '/templates/*',
},
customTags = {
-- mkdocs
'tag:yaml.org,2002:python/name:material.extensions.emoji.twemoji',
'tag:yaml.org,2002:python/name:material.extensions.emoji.to_svg',
'tag:yaml.org,2002:python/name:pymdownx.superfences.fence_code_format',
},
},
},
}
require('lspconfig').yamlls.setup {
name = 'yamlls GitLab',
filetypes = { 'yaml.gitlab' },
settings = {
yaml = {
customTags = {
'!reference sequence',
'!reference scalar',
},
},
},
}
end,
-- ['pylyzer'] = function() end, -- disable
-- ['vale_ls'] = function() end, -- disable
-- ['rust_analyzer'] = function() end, -- use rustaceanvim instead
['dockerls'] = function()
require('lspconfig').dockerls.setup {
settings = {
docker = {
languageserver = {
formatter = {
ignoreMultilineInstructions = true,
},
},
},
},
}
end,
['jsonls'] = function()
require('lspconfig').jsonls.setup {
filetypes = { 'json', 'jsonc' },
settings = {
json = {
schemas = {
{
fileMatch = { 'package.json' },
url = 'https://json.schemastore.org/package.json',
},
{
fileMatch = { 'tsconfig*.json' },
url = 'https://json.schemastore.org/tsconfig.json',
},
{
fileMatch = {
'.prettierrc',
'.prettierrc.json',
'prettier.config.json',
},
url = 'https://json.schemastore.org/prettierrc.json',
},
{
fileMatch = {
'.eslintrc',
'.eslintrc.json',
},
url = 'https://json.schemastore.org/eslintrc.json',
},
{
fileMatch = {
'.stylelintrc',
'.stylelintrc.json',
'stylelint.config.json',
},
url = 'http://json.schemastore.org/stylelintrc.json',
},
},
},
},
}
end,
['html'] = function()
require('lspconfig').html.setup {
settings = {
html = {
format = {
templating = true,
wrapLineLength = 120,
wrapAttributes = 'auto',
},
hover = {
documentation = true,
references = true,
},
},
},
}
end,
['tsserver'] = function()
require('lspconfig').tsserver.setup {
autostart = false,
root_dir = require('lspconfig.util').root_pattern 'package.json',
commands = {
OrganizeImports = {
function()
local params = {
command = '_typescript.organizeImports',
arguments = {
vim.api.nvim_buf_get_name(
0
),
},
title = '',
}
vim.lsp.buf.execute_command(params)
end,
},
},
}
end,
['lua_ls'] = function()
require('lspconfig').lua_ls.setup {
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
workspace = { checkThirdParty = false },
telemetry = { enable = false },
diagnostics = {
unusedLocalExclude = { '_*' },
},
format = { enable = false },
hint = {
enable = true,
arrayIndex = 'Disable',
},
},
},
}
end,
-- ['denols'] = function()
-- require('lspconfig').denols.setup {
-- autostart = false,
-- root_dir = require('lspconfig.util').root_pattern(
-- 'deno.json',
-- 'deno.jsonc'
-- ),
-- filetypes = {
-- 'javascript',
-- 'javascriptreact',
-- 'javascript.jsx',
-- 'typescript',
-- 'typescriptreact',
-- 'typescript.tsx',
-- 'yaml',
-- 'json',
-- 'markdown',
-- 'html',
-- 'css',
-- },
-- init_options = {
-- enable = true,
-- lint = true,
-- unstable = true,
-- importMap = './import_map.json',
-- },
-- single_file_support = false,
-- }
-- end,
['texlab'] = function()
require('lspconfig').texlab.setup {
settings = {
texlab = {
auxDirectory = '.',
bibtexFormatter = 'texlab',
build = {
args = {
'-pdflua',
'-shell-escape',
'-interaction=nonstopmode',
'-synctex=1',
'-pv',
'%f',
},
executable = 'latexmk',
forwardSearchAfter = false,
onSave = false,
},
chktex = {
onEdit = false,
onOpenAndSave = false,
},
diagnosticsDelay = 300,
formatterLineLength = 80,
forwardSearch = {
args = {},
},
latexFormatter = 'latexindent',
latexindent = {
modifyLineBreaks = false,
},
},
},
}
end,
},
},
},
{
'antosha417/nvim-lsp-file-operations',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-tree/nvim-tree.lua',
},
opts = {},
},
},
},
{
'zbirenbaum/neodim',
event = { 'BufReadPost', 'BufNewFile' },
opts = {
alpha = 0.70,
blend_color = '#000000',
update_in_insert = {
enable = false,
delay = 100,
},
hide = {
virtual_text = false,
signs = false,
underline = true,
},
},
config = function(_, opts)
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP dim unused',
callback = function()
require('neodim').setup(opts)
end,
})
end,
},
{
'stevearc/conform.nvim',
event = { 'BufWritePre' },
dependencies = {
{
'williamboman/mason.nvim',
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, {
'stylua',
'ruff',
-- 'dprint',
'isort',
'black',
'prettierd',
'shfmt',
})
end,
},
},
opts = {
formatters_by_ft = {
lua = { 'stylua' },
python = function(bufnr)
if
require('conform').get_formatter_info(
'ruff_format',
bufnr
).available
then
return { 'ruff_fix', 'ruff_format' }
else
return { 'isort', 'black' }
end
end,
json = { 'dprint' },
jsonc = { 'dprint' },
markdown = { 'dprint', 'injected' },
-- javascript = { 'dprint' },
-- javascriptreact = { 'dprint' },
-- typescript = { 'dprint' },
-- typescriptreact = { 'dprint' },
toml = { 'dprint' },
dockerfile = { 'dprint' },
css = { 'dprint' },
html = { 'dprint' },
htmldjango = { 'dprint' },
yaml = { 'dprint' },
graphql = { { 'prettierd', 'prettier' } },
sh = { 'shfmt' },
http = {
'injected',
-- 'trim_newlines', -- FIXME: breaks injected
'trim_whitespace',
},
['_'] = { 'trim_newlines', 'trim_whitespace' },
},
format_on_save = function(bufnr)
-- Disable with a global or buffer-local variable
if
vim.g.disable_autoformat
or vim.b[bufnr].disable_autoformat
then
return
end
return {
timeout_ms = 5000, -- HACK: high because dprint needs to download WASM plugins on first run
lsp_fallback = true,
}
end,
log_level = vim.log.levels.TRACE,
},
init = function()
vim.api.nvim_create_user_command('Format', function()
require('conform').format()
end, { desc = 'Format buffer using conform' })
vim.api.nvim_create_user_command('FormatDisable', function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
---@diagnostic disable-next-line: inject-field
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end, {
desc = 'Disable autoformat-on-save',
bang = true,
})
vim.api.nvim_create_user_command('FormatEnable', function()
---@diagnostic disable-next-line: inject-field
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = 'Re-enable autoformat-on-save',
})
vim.api.nvim_create_autocmd('LspAttach', {
group = au,
desc = 'LSP formatexpr',
callback = function(args)
local bufnr = args.buf
vim.api.nvim_set_option_value(
'formatexpr',
'v:lua.require\'conform\'.formatexpr()',
{ buf = bufnr }
)
end,
})
end,
config = function(_, opts)
local conform = require 'conform'
conform.setup(opts)
conform.formatters.stylua = {
require_cwd = true,
}
-- conform.formatters.ruff_fix = {
-- prepend_args = { '--respect-gitignore' },
-- }
-- conform.formatters.ruff_format = {
-- prepend_args = { '--silent', '--respect-gitignore' },
-- }
conform.formatters.shfmt = {
prepend_args = { '-i', '4', '-ci' },
}
conform.formatters.dprint = {
prepend_args = function(self, ctx)
if not self:cwd(ctx) then
vim.notify 'falling back to global dprint config'
return {
'--config',
vim.fn.expand '~/.config/dprint.jsonc',
}
end
end,
}
conform.formatters.dprint_injected = vim.tbl_deep_extend(
'force',
require 'conform.formatters.dprint',
conform.formatters.dprint,
{
args = function(self, ctx)
local extension = vim.fn.fnamemodify(ctx.filename, ':e')
local ret = vim.list_extend(
{ 'fmt', '--stdin', extension },
self:prepend_args(ctx)
)
return ret
end,
}
)
conform.formatters.injected = {
options = {
ignore_errors = false,
lang_to_formatters = {
json = { 'dprint_injected' },
python = { 'black' }, -- FIXME: ruff_format deletes content
},
},
}
-- TODO: custom formatters
conform.formatters.blackd = {
command = 'blackd-client',
}
end,
},
{
'joechrisellis/lsp-format-modifications.nvim',
lazy = true,
dependencies = { 'nvim-lua/plenary.nvim' },
init = function()
vim.api.nvim_create_user_command('FormatModified', function()
local bufnr = vim.api.nvim_get_current_buf()
local clients = vim.lsp.get_clients {
bufnr = bufnr,
method = require('vim.lsp.protocol').Methods.textDocument_rangeFormatting,
}
if #clients == 0 then
vim.notify '[LSP] Format request failed, no matching language servers.'
end
for _, client in pairs(clients) do
require('lsp-format-modifications').format_modifications(
client,
bufnr
)
end
end, {})
end,
},
{
'mrcjkb/rustaceanvim',
ft = 'rust',
opts = function()
vim.g.rustaceanvim = {
server = {
cmd = function()
local mason_registry = require 'mason-registry'
local ra_binary = mason_registry.is_installed 'rust-analyzer'
and mason_registry
.get_package('rust-analyzer')
:get_install_path() .. '/rust-analyzer'
or 'rust-analyzer'
return { ra_binary }
end,
},
}
end,
},
{
'folke/trouble.nvim',
cmd = 'Trouble',
keys = {
{
'<leader>xx',
function()
require('trouble').toggle()
end,
},
{
'<leader>xw',
function()
require('trouble').toggle { mode = 'diagnostics' }
end,
},
{
'<leader>xb',
function()
require('trouble').toggle {
mode = 'diagnostics',
filter = { buf = 0 },
}
end,
},
{
'<leader>xq',
function()
require('trouble').toggle { mode = 'quickfix' }
end,
},
},
opts = {
fold_open = '', -- ▾
fold_closed = '', -- ▸
indent_lines = false,
padding = false,
signs = {
error = '',
warning = '',
hint = '',
information = '',
other = '', -- 
},
action_keys = { jump = { '<cr>' }, toggle_fold = { '<tab>' } },
},
config = function(_, opts)
require('trouble').setup(opts)
vim.api.nvim_set_hl(0, 'TroubleText', { link = 'CursorLineNr' })
vim.api.nvim_create_autocmd('QuitPre', {
callback = function()
local invalid_wins = {}
local wins = vim.api.nvim_list_wins()
for _, w in ipairs(wins) do
local bufname = vim.api.nvim_buf_get_name(
vim.api.nvim_win_get_buf(w)
)
if
bufname:match 'Trouble' ~= nil
or vim.api.nvim_win_get_config(w).relative ~= '' -- floating window
then
table.insert(invalid_wins, w)
end
end
if #invalid_wins == #wins - 1 then
-- Should quit, so we close all invalid windows.
for _, w in ipairs(invalid_wins) do
vim.api.nvim_win_close(w, true)
end
end
end,
desc = 'Close Trouble if last window',
})
end,
}
}

View File

@@ -0,0 +1,16 @@
return {
'gbprod/nord.nvim', name = 'nord',
lazy = false,
priority = 1000,
config = function()
vim.g.nord_contrast = true
vim.g.nord_borders = true
vim.g.nord_disable_background = false
vim.g.nord_cursorline_transparent = false
vim.g.nord_enable_sidebar_background = false
vim.g.nord_italic = true
vim.g.nord_uniform_diff_background = true
vim.g.nord_bold = false
vim.cmd [[colorscheme nord]]
end
}

View File

@@ -0,0 +1,33 @@
return {
"stevearc/oil.nvim",
config = function()
require("oil").setup({
-- prompt_save_on_select_new_entry = true,
skip_confirm_for_simple_edits = true,
default_file_explorer = false, -- so `gx` and `:GBrowse` works
use_default_keymap = false,
keymaps = {
["g?"] = "actions.show_help",
["<CR>"] = "actions.select",
["<C-s>"] = "actions.select_vsplit",
["<C-h>"] = false,
["<C-t>"] = "actions.select_tab",
["<C-p>"] = "actions.preview",
["<C-c>"] = "actions.close",
["<C-l>"] = false,
["-"] = "actions.parent",
["_"] = "actions.open_cwd",
["`"] = "actions.cd",
["~"] = "actions.tcd",
["gs"] = "actions.change_sort",
["gx"] = false,
["g."] = "actions.toggle_hidden",
["g\\"] = "actions.toggle_trash",
},
view_options = {
-- Show files and directories that start with "."
show_hidden = false,
}
})
end
}

View File

@@ -0,0 +1,7 @@
return {
'nvim-telescope/telescope.nvim', tag = '0.1.8',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
require('telescope').setup()
end
}

View File

@@ -0,0 +1 @@
return { 'christoomey/vim-tmux-navigator' }

View File

@@ -0,0 +1,60 @@
return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
require('nvim-treesitter.configs').setup {
-- one of "all", "maintained" (parsers with maintainers), or a list of languages
ensure_installed = { 'bash', 'c', 'cpp', 'c_sharp', 'clojure', 'cmake', 'comment', 'commonlisp',
'css', 'dockerfile', 'elixir', 'erlang', 'fish', 'go', 'html', 'http', 'java',
'javascript', 'json', 'kotlin', 'latex', 'lua', 'make', 'markdown', 'perl', 'php',
'python', 'ruby', 'rust', 'scss', 'swift', 'toml', 'tsx', 'vim', 'vue', 'yaml' },
-- ignore_install = { 'norg' },
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
context_commentstring = {
enable = true,
enable_autocmd = false,
},
rainbow = {
enable = true,
disable = { "html" },
extended_mode = false,
max_file_lines = nil,
},
indent = { enable = false },
autopairs = { enable = true },
autotag = { enable = true },
incremental_selection = { enable = true },
textobjects = { -- syntax-aware textobjects
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
disable = {},
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['af'] = '@function.outer',
['if'] = '@function.inner',
['aC'] = '@class.outer',
['iC'] = '@class.inner',
['ac'] = '@conditional.outer',
['ic'] = '@conditional.inner',
['ab'] = '@block.outer',
['ib'] = '@block.inner',
['al'] = '@loop.outer',
['il'] = '@loop.inner',
['is'] = '@statement.inner',
['as'] = '@statement.outer',
['am'] = '@call.outer',
['im'] = '@call.inner',
['ad'] = '@comment.outer',
['id'] = '@comment.inner',
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
},
},
}
}
end
}