nvim: all in on mini.nvim
This commit is contained in:
parent
890ac1e91c
commit
aa228521fe
22 changed files with 450 additions and 741 deletions
|
@ -9,7 +9,7 @@
|
|||
./gnome.nix
|
||||
./k8s.nix
|
||||
./nix.nix
|
||||
./nvim.nix
|
||||
./nvim
|
||||
./scripts.nix
|
||||
./ssh.nix
|
||||
./tmux.nix
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
{ ... }:
|
||||
{
|
||||
programs.neovim = {
|
||||
enable = true;
|
||||
defaultEditor = true;
|
||||
viAlias = true;
|
||||
vimAlias = true;
|
||||
withNodeJs = false;
|
||||
withPython3 = false;
|
||||
withRuby = false;
|
||||
};
|
||||
|
||||
xdg.configFile = {
|
||||
"nvim" = {
|
||||
recursive = true;
|
||||
source = ./../../files/config/nvim;
|
||||
};
|
||||
};
|
||||
}
|
119
home/common/nvim/default.nix
Normal file
119
home/common/nvim/default.nix
Normal file
|
@ -0,0 +1,119 @@
|
|||
{ lib, pkgs, ... }:
|
||||
{
|
||||
programs.neovim = {
|
||||
enable = true;
|
||||
defaultEditor = true;
|
||||
viAlias = true;
|
||||
vimAlias = true;
|
||||
withNodeJs = false;
|
||||
withPython3 = false;
|
||||
withRuby = false;
|
||||
|
||||
extraLuaConfig = lib.fileContents ./init.lua;
|
||||
extraPackages = with pkgs; [
|
||||
black
|
||||
cue
|
||||
go
|
||||
gopls
|
||||
gotools
|
||||
lua-language-server
|
||||
nil
|
||||
nixd
|
||||
nodePackages.prettier
|
||||
nodePackages.typescript
|
||||
nodePackages.typescript-language-server
|
||||
nodePackages.bash-language-server
|
||||
rust-analyzer
|
||||
shellcheck
|
||||
shfmt
|
||||
stylua
|
||||
tree-sitter
|
||||
tree-sitter-grammars.tree-sitter-bash
|
||||
tree-sitter-grammars.tree-sitter-yaml
|
||||
tree-sitter-grammars.tree-sitter-go
|
||||
tree-sitter-grammars.tree-sitter-markdown
|
||||
tree-sitter-grammars.tree-sitter-lua
|
||||
tree-sitter-grammars.tree-sitter-html
|
||||
tree-sitter-grammars.tree-sitter-vim
|
||||
tree-sitter-grammars.tree-sitter-nix
|
||||
vscode-langservers-extracted
|
||||
];
|
||||
|
||||
|
||||
plugins = with pkgs.vimPlugins; [
|
||||
go-nvim
|
||||
rustaceanvim
|
||||
targets-vim
|
||||
|
||||
{
|
||||
plugin = pkgs.vimUtils.buildVimPlugin {
|
||||
name = "dieter-nvim";
|
||||
src = pkgs.fetchgit {
|
||||
url = "https://patagia.dev/Patagia/dieter.nvim.git";
|
||||
rev = "08fae6ffec4ae70ba6b2e1cafa780ff317ef0b61";
|
||||
hash = "sha256-C+Vo2SUVfNMkBwuLWqLoA59Pmy9aFwur7fBpfVkLm6Q=";
|
||||
};
|
||||
};
|
||||
type = "lua";
|
||||
config = ''
|
||||
vim.cmd.colorscheme "dieter"
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
plugin = nvim-treesitter.withAllGrammars; # Treesitter
|
||||
type = "lua";
|
||||
config = ''
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
highlight = { enable = true, },
|
||||
indent = { enable = true },
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
plugin = pkgs.vimUtils.buildVimPlugin {
|
||||
name = "nvim-tree-pairs"; # make % match in TS
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "yorickpeterse";
|
||||
repo = "nvim-tree-pairs";
|
||||
rev = "e7f7b6cc28dda6f3fa271ce63b0d371d5b7641da";
|
||||
hash = "sha256-fb4EsrWAbm8+dWAhiirCPuR44MEg+KYb9hZOIuEuT24=";
|
||||
};
|
||||
};
|
||||
type = "lua";
|
||||
config = "require('tree-pairs').setup()";
|
||||
}
|
||||
|
||||
{
|
||||
plugin = nvim-treesitter-textobjects; # helix-style selection of TS tree
|
||||
type = "lua";
|
||||
config = ''
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
init_selection = "<M-o>",
|
||||
scope_incremental = "<M-O>",
|
||||
node_incremental = "<M-o>",
|
||||
node_decremental = "<M-i>",
|
||||
},
|
||||
},
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
plugin = mini-nvim;
|
||||
type = "lua";
|
||||
config = lib.fileContents ./mini.lua;
|
||||
}
|
||||
|
||||
{
|
||||
plugin = nvim-lspconfig; # Interface for LSPs
|
||||
type = "lua";
|
||||
config = lib.fileContents ./lsp.lua;
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
93
home/common/nvim/init.lua
Normal file
93
home/common/nvim/init.lua
Normal file
|
@ -0,0 +1,93 @@
|
|||
-- vim.g.mapleader = "<space>"
|
||||
vim.g.maplocalleader = ','
|
||||
|
||||
-- UI
|
||||
|
||||
vim.opt.cursorline = true
|
||||
vim.opt.laststatus = 0
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
vim.opt.ruler = true
|
||||
vim.opt.rulerformat = "" -- FIXME: fancify!
|
||||
vim.opt.rulerformat = "%36(%5l,%-6(%c%V%) %t%)%*"
|
||||
vim.opt.syntax = "on"
|
||||
vim.opt.termguicolors = true
|
||||
|
||||
-- Search
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
|
||||
-- Tab completion
|
||||
-- vim.opt.wildmode="list:longest,full"
|
||||
vim.opt.wildignore="*.swp,*.o,*.so,*.exe,*.dll"
|
||||
|
||||
-- Whitespaces
|
||||
vim.opt.breakindent = true
|
||||
vim.opt.copyindent = true
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.softtabstop = 2
|
||||
vim.opt.shiftround = true
|
||||
vim.opt.shiftwidth = 2
|
||||
vim.opt.smartindent = true
|
||||
vim.opt.tabstop = 2
|
||||
vim.opt.wrap = false
|
||||
vim.opt.list = true
|
||||
vim.opt.listchars="tab:»·,trail:·"
|
||||
|
||||
-- Folds
|
||||
vim.opt.foldenable = false
|
||||
vim.opt.foldtext = "v:lua.vim.treesitter.foldtext()"
|
||||
vim.opt.foldmethod = "expr"
|
||||
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
|
||||
|
||||
--
|
||||
|
||||
vim.o.autochdir = true
|
||||
vim.o.fillchars = "stl: ,stlnc: ,eob:░,vert:│"
|
||||
vim.o.list = false
|
||||
vim.o.scrolloff = 7
|
||||
vim.o.splitkeep = "screen"
|
||||
vim.o.updatetime = 50
|
||||
vim.o.timeout = true
|
||||
vim.o.timeoutlen = 10
|
||||
vim.o.icm = "split"
|
||||
-- vim.o.cia = 'kind,abbr,menu' wait for nightly to drop
|
||||
|
||||
vim.o.showmode = false
|
||||
|
||||
|
||||
-- Use rg
|
||||
vim.o.grepprg = [[rg --glob "!.jj" --glob "!.git" --no-heading --vimgrep --follow $*]]
|
||||
vim.opt.grepformat = vim.opt.grepformat ^ { "%f:%l:%c:%m" }
|
||||
|
||||
vim.fn.sign_define(
|
||||
"DiagnosticSignError",
|
||||
{ text = "", hl = "DiagnosticSignError", texthl = "DiagnosticSignError", culhl = "DiagnosticSignErrorLine" }
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"DiagnosticSignWarn",
|
||||
{ text = "", hl = "DiagnosticSignWarn", texthl = "DiagnosticSignWarn", culhl = "DiagnosticSignWarnLine" }
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"DiagnosticSignInfo",
|
||||
{ text = "", hl = "DiagnosticSignInfo", texthl = "DiagnosticSignInfo", culhl = "DiagnosticSignInfoLine" }
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"DiagnosticSignHint",
|
||||
{ text = "", hl = "DiagnosticSignHint", texthl = "DiagnosticSignHint", culhl = "DiagnosticSignHintLine" }
|
||||
)
|
||||
|
||||
-- Make <Tab> work for snippets
|
||||
vim.keymap.set({ "i", "s" }, "<Tab>", function()
|
||||
if vim.snippet.active({ direction = 1 }) then
|
||||
return "<cmd>lua vim.snippet.jump(1)<cr>"
|
||||
else
|
||||
return "<Tab>"
|
||||
end
|
||||
end, { expr = true })
|
||||
|
||||
vim.keymap.set({ "n" }, "<c-/>", "gcc", { remap = true })
|
||||
vim.keymap.set({ "v" }, "<c-/>", "gc", { remap = true })
|
||||
vim.keymap.set({ "n" }, "<c-_>", "gcc", { remap = true })
|
||||
vim.keymap.set({ "v" }, "<c-_>", "gc", { remap = true })
|
||||
vim.keymap.set("n", "zz", "zt", { remap = true })
|
92
home/common/nvim/lsp.lua
Normal file
92
home/common/nvim/lsp.lua
Normal file
|
@ -0,0 +1,92 @@
|
|||
vim.keymap.set("n", "<space>d", vim.diagnostic.setloclist, { desc = "Add buffer diagnostics to the location list." })
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
||||
|
||||
-- Buffer local mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local opts = function(str)
|
||||
return { buffer = ev.buf, desc = str }
|
||||
end
|
||||
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if client.server_capabilities.codeLensProvider then
|
||||
vim.lsp.codelens.refresh({ bufnr = bufnr })
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
|
||||
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, {})
|
||||
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Declaration"))
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Definition"))
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Implementation"))
|
||||
vim.keymap.set("n", "<M-k>", vim.lsp.buf.signature_help, opts("Signature Help"))
|
||||
vim.keymap.set("i", "<M-k>", vim.lsp.buf.signature_help, opts("Signature Help"))
|
||||
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts("Add Workspace Folder"))
|
||||
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts("Remove Workspace Folder"))
|
||||
vim.keymap.set("n", "<space>wl", function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, opts("List Workspace Folders"))
|
||||
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts("Type Definition"))
|
||||
vim.keymap.set("n", "<space>r", vim.lsp.buf.rename, opts("Rename Symbol"))
|
||||
vim.keymap.set({ "n", "v" }, "<space>a", vim.lsp.buf.code_action, opts("Code Action"))
|
||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Buffer References"))
|
||||
vim.keymap.set("n", "<localleader>f", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, opts("Format Buffer"))
|
||||
end,
|
||||
})
|
||||
|
||||
local configs = require('lspconfig.configs')
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
local servers = {
|
||||
'gopls',
|
||||
'nil_ls',
|
||||
'ts_ls',
|
||||
}
|
||||
|
||||
for _, ls in ipairs(servers) do
|
||||
lspconfig[ls].setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = function(_, buf)
|
||||
vim.api.nvim_set_option_value('omnifunc', 'v:lua.MiniCompletion.completefunc_lsp', {buf = buf})
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
lspconfig.nixd.setup({
|
||||
capabilities = capabilities,
|
||||
cmd = { "nixd" },
|
||||
settings = {
|
||||
nixd = {
|
||||
nixpkgs = { expr = "import <nixpkgs> { }" },
|
||||
formatting = { command = { "nixfmt" } },
|
||||
options = {},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
lspconfig.lua_ls.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
version = "LuaJIT",
|
||||
path = vim.split(package.path, ";"),
|
||||
},
|
||||
diagnostics = { globals = { "vim", "hs" } },
|
||||
workspace = {
|
||||
library = {
|
||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
130
home/common/nvim/mini.lua
Normal file
130
home/common/nvim/mini.lua
Normal file
|
@ -0,0 +1,130 @@
|
|||
local opts = function(label)
|
||||
return {noremap = true, silent = true, desc = label}
|
||||
end
|
||||
require('mini.ai').setup()
|
||||
require('mini.align').setup()
|
||||
require('mini.bracketed').setup()
|
||||
require('mini.completion').setup()
|
||||
require('mini.diff').setup()
|
||||
require('mini.extra').setup()
|
||||
require('mini.icons').setup()
|
||||
require('mini.jump').setup()
|
||||
-- require('mini.pairs').setup()
|
||||
-- require('mini.statusline').setup()
|
||||
require('mini.surround').setup()
|
||||
require('mini.splitjoin').setup()
|
||||
|
||||
require('mini.files').setup()
|
||||
local oil_style = function()
|
||||
if not MiniFiles.close() then
|
||||
MiniFiles.open(vim.api.nvim_buf_get_name(0))
|
||||
MiniFiles.reveal_cwd()
|
||||
end
|
||||
end
|
||||
vim.keymap.set('n', '-', oil_style, opts("File Explorer"));
|
||||
|
||||
local hipatterns = require('mini.hipatterns')
|
||||
hipatterns.setup({ -- highlight strings and colors
|
||||
highlighters = {
|
||||
-- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE'
|
||||
fixme = { pattern = '%f[%w]()FIXME()%f[%W]', group = 'MiniHipatternsFixme' },
|
||||
hack = { pattern = '%f[%w]()HACK()%f[%W]', group = 'MiniHipatternsHack' },
|
||||
todo = { pattern = '%f[%w]()TODO()%f[%W]', group = 'MiniHipatternsTodo' },
|
||||
note = { pattern = '%f[%w]()NOTE()%f[%W]', group = 'MiniHipatternsNote' },
|
||||
|
||||
-- Highlight hex color strings (`#rrggbb`) using that color
|
||||
hex_color = hipatterns.gen_highlighter.hex_color(),
|
||||
}
|
||||
})
|
||||
|
||||
require('mini.jump2d').setup({
|
||||
mappings = {
|
||||
start_jumping = 'gw'
|
||||
}
|
||||
})
|
||||
|
||||
require('mini.pick').setup({
|
||||
mappings = {
|
||||
move_down = '<tab>'
|
||||
},
|
||||
options = {
|
||||
use_cache = true
|
||||
}
|
||||
})
|
||||
MiniPick.registry.files_root = function(local_opts)
|
||||
local root_patterns = { ".jj", ".git" }
|
||||
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1])
|
||||
local opts = { source = { cwd = root_dir, tool = "ripgrep"} }
|
||||
local_opts.cwd = root_dir
|
||||
local_opts.tool = "rg"
|
||||
return MiniPick.builtin.files(local_opts, opts)
|
||||
end
|
||||
MiniPick.registry.grep_live_root = function(local_opts)
|
||||
local root_patterns = { ".jj", ".git" }
|
||||
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1])
|
||||
local opts = { source = { cwd = root_dir } }
|
||||
local_opts.cwd = root_dir
|
||||
return MiniPick.builtin.grep_live(local_opts, opts)
|
||||
end
|
||||
vim.keymap.set('n', '<space>/', "<cmd>Pick grep_live_root<cr>", opts("Live Grep"))
|
||||
vim.keymap.set('n', '<space>F', "<cmd>Pick files<cr>", opts("Find Files in CWD"))
|
||||
vim.keymap.set('n', '<space>ff', "<cmd>Pick files_root<cr>", opts("Find Files"))
|
||||
vim.keymap.set('n', '<space>fr', "<cmd>Pick oldfiles<cr>", opts("Recent Files"))
|
||||
vim.keymap.set('n', '<space>b', "<cmd>Pick buffers<cr>", opts("Buffers"))
|
||||
vim.keymap.set('n', '<space>d', "<cmd>Pick diagnostics<cr>", opts("Diagnostics"))
|
||||
vim.keymap.set('n', '<tab>', "<cmd>Pick buffers include_current=false<cr>", opts("Buffers"))
|
||||
vim.keymap.set('n', "<space>'", "<cmd>Pick resume<cr>", opts("Last Picker"))
|
||||
vim.keymap.set('n', "<space>g", "<cmd>Pick git_commits<cr>", opts("Git Commits"))
|
||||
|
||||
|
||||
local miniclue = require('mini.clue')
|
||||
miniclue.setup({ -- cute prompts about bindings
|
||||
triggers = {
|
||||
{ mode = 'n', keys = '<Leader>' },
|
||||
{ mode = 'x', keys = '<Leader>' },
|
||||
{ mode = 'n', keys = '<space>' },
|
||||
{ mode = 'x', keys = '<space>' },
|
||||
|
||||
-- Built-in completion
|
||||
{ mode = 'i', keys = '<C-x>' },
|
||||
|
||||
-- `g` key
|
||||
{ mode = 'n', keys = 'g' },
|
||||
{ mode = 'x', keys = 'g' },
|
||||
|
||||
-- Marks
|
||||
{ mode = 'n', keys = "'" },
|
||||
{ mode = 'n', keys = '`' },
|
||||
{ mode = 'x', keys = "'" },
|
||||
{ mode = 'x', keys = '`' },
|
||||
|
||||
-- Registers
|
||||
{ mode = 'n', keys = '"' },
|
||||
{ mode = 'x', keys = '"' },
|
||||
{ mode = 'i', keys = '<C-r>' },
|
||||
{ mode = 'c', keys = '<C-r>' },
|
||||
|
||||
-- Window commands
|
||||
{ mode = 'n', keys = '<C-w>' },
|
||||
|
||||
-- `z` key
|
||||
{ mode = 'n', keys = 'z' },
|
||||
{ mode = 'x', keys = 'z' },
|
||||
|
||||
-- Bracketed
|
||||
{ mode = 'n', keys = '[' },
|
||||
{ mode = 'n', keys = ']' },
|
||||
},
|
||||
clues = {
|
||||
miniclue.gen_clues.builtin_completion(),
|
||||
miniclue.gen_clues.g(),
|
||||
miniclue.gen_clues.marks(),
|
||||
miniclue.gen_clues.registers(),
|
||||
miniclue.gen_clues.windows(),
|
||||
miniclue.gen_clues.z(),
|
||||
},
|
||||
window = {
|
||||
delay = 15,
|
||||
}
|
||||
})
|
||||
|
|
@ -55,6 +55,8 @@
|
|||
arguments = [
|
||||
"--glob=!.git/*"
|
||||
"--glob=!.jj/*"
|
||||
"--glob=!result/*"
|
||||
"--glob=!target/*"
|
||||
];
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue