refactor: modularize home-manager config
This commit is contained in:
parent
98750e1a51
commit
e13ed446a1
28 changed files with 323 additions and 271 deletions
1
home-manager/neovim/comment.lua
Normal file
1
home-manager/neovim/comment.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require('Comment').setup({})
|
93
home-manager/neovim/default.nix
Normal file
93
home-manager/neovim/default.nix
Normal file
|
@ -0,0 +1,93 @@
|
|||
{ config, lib, pkgs, user, ... }:
|
||||
|
||||
{
|
||||
home.packages = with pkgs; [
|
||||
# LSP
|
||||
sumneko-lua-language-server
|
||||
rnix-lsp
|
||||
terraform-ls
|
||||
tflint
|
||||
nodePackages.bash-language-server
|
||||
rust-analyzer
|
||||
];
|
||||
|
||||
programs = {
|
||||
neovim = {
|
||||
enable = true;
|
||||
plugins = with pkgs.vimPlugins; [
|
||||
# theme
|
||||
nvim-solarized-lua
|
||||
|
||||
delimitMate
|
||||
vim-bbye
|
||||
ansible-vim
|
||||
|
||||
# session handling
|
||||
vim-obsession
|
||||
vim-prosession
|
||||
|
||||
nvim-web-devicons
|
||||
nvim-treesitter
|
||||
markdown-preview-nvim # use({ "iamcco/markdown-preview.nvim", run = ":call mkdp#util#install()" })
|
||||
toggleterm-nvim
|
||||
nvim-notify
|
||||
comment-nvim
|
||||
lualine-nvim
|
||||
tabline-nvim
|
||||
indent-blankline-nvim
|
||||
plenary-nvim
|
||||
|
||||
# git
|
||||
gitsigns-nvim
|
||||
vim-fugitive
|
||||
gv-vim
|
||||
|
||||
# snippets
|
||||
friendly-snippets
|
||||
luasnip
|
||||
|
||||
# auto-completion
|
||||
nvim-cmp
|
||||
cmp-nvim-lsp
|
||||
cmp-buffer
|
||||
cmp-path
|
||||
cmp-cmdline
|
||||
cmp-nvim-lua
|
||||
cmp_luasnip
|
||||
cmp-calc
|
||||
|
||||
# telescope
|
||||
telescope-nvim
|
||||
telescope-fzf-native-nvim
|
||||
telescope-ui-select-nvim
|
||||
|
||||
# LSP
|
||||
nvim-lspconfig
|
||||
lsp-status-nvim
|
||||
rust-tools-nvim
|
||||
lua-dev-nvim
|
||||
];
|
||||
|
||||
extraConfig = ''
|
||||
lua << EOF
|
||||
${builtins.readFile ./keymaps.lua }
|
||||
${builtins.readFile ./options.lua }
|
||||
${builtins.readFile ./treesitter.lua }
|
||||
${builtins.readFile ./lspconfig.lua }
|
||||
${builtins.readFile ./toggleterm.lua }
|
||||
${builtins.readFile ./notify.lua }
|
||||
${builtins.readFile ./comment.lua }
|
||||
${builtins.readFile ./lualine.lua }
|
||||
${builtins.readFile ./tabline.lua }
|
||||
${builtins.readFile ./indent-blankline.lua }
|
||||
${builtins.readFile ./gitsigns.lua }
|
||||
${builtins.readFile ./luasnip.lua }
|
||||
${builtins.readFile ./nvim-cmp.lua }
|
||||
${builtins.readFile ./telescope.lua }
|
||||
${builtins.readFile ./themes.lua }
|
||||
EOF
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
1
home-manager/neovim/gitsigns.lua
Normal file
1
home-manager/neovim/gitsigns.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require('gitsigns').setup()
|
6
home-manager/neovim/indent-blankline.lua
Normal file
6
home-manager/neovim/indent-blankline.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
require("indent_blankline").setup {
|
||||
char = "┊",
|
||||
buftype_exclude = { "terminal", "help", "nofile" },
|
||||
filetype_exclude = { 'help', 'packer' },
|
||||
show_trailing_blankline_indent = false
|
||||
}
|
47
home-manager/neovim/keymaps.lua
Normal file
47
home-manager/neovim/keymaps.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
local function nnoremap(key, command)
|
||||
vim.api.nvim_set_keymap("n", key, command, { noremap = true })
|
||||
end
|
||||
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = " "
|
||||
|
||||
-- Move around windows
|
||||
nnoremap("<C-h>", "<C-w>h")
|
||||
nnoremap("<C-j>", "<C-w>j")
|
||||
nnoremap("<C-k>", "<C-w>k")
|
||||
nnoremap("<C-l>", "<C-w>l")
|
||||
|
||||
-- Switch buffers
|
||||
nnoremap("<C-PageDown>", ":TablineBufferNext<CR>")
|
||||
nnoremap("<C-PageUp>", ":TablineBufferPrevious<CR>")
|
||||
|
||||
-- fugitive
|
||||
nnoremap("<leader>g", ":0Git<CR>")
|
||||
nnoremap("<leader>G", ":GV --all<CR>")
|
||||
|
||||
-- telescope
|
||||
nnoremap("<leader>ff", "<Cmd>Telescope find_files theme=dropdown<CR>")
|
||||
nnoremap("<leader>fb", "<Cmd>Telescope buffers theme=dropdown<CR>")
|
||||
nnoremap("<leader>fg", "<Cmd>Telescope git_files theme=dropdown<CR>")
|
||||
nnoremap("<C-f>", "<Cmd>Telescope grep_string<CR>")
|
||||
nnoremap("<C-g>", "<Cmd>Telescope live_grep<CR>")
|
||||
|
||||
-- terminal
|
||||
vim.api.nvim_create_autocmd("TermOpen", {
|
||||
pattern = "term://*",
|
||||
callback = function()
|
||||
local opts = { noremap = true }
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<C-h>', [[<C-\><C-n><C-W>h]], opts)
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<C-j>', [[<C-\><C-n><C-W>j]], opts)
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<C-k>', [[<C-\><C-n><C-W>k]], opts)
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<C-l>', [[<C-\><C-n><C-W>l]], opts)
|
||||
end,
|
||||
desc = "Map terminal esc and window switch keys",
|
||||
})
|
||||
|
||||
-- buffer closing
|
||||
nnoremap("<leader>q", ":Bdelete<CR>")
|
||||
|
||||
-- toggle search highlighting
|
||||
vim.cmd('nnoremap <expr> * v:hlsearch ? ":nohlsearch<cr>" : "*"')
|
90
home-manager/neovim/lspconfig.lua
Normal file
90
home-manager/neovim/lspconfig.lua
Normal file
|
@ -0,0 +1,90 @@
|
|||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local function nnoremap(key, command)
|
||||
vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr })
|
||||
end
|
||||
|
||||
local telescope = require("telescope.builtin")
|
||||
|
||||
nnoremap("gD", vim.lsp.buf.declaration)
|
||||
nnoremap("gd", telescope.lsp_definitions)
|
||||
nnoremap("gt", telescope.lsp_type_definitions)
|
||||
nnoremap("gi", telescope.lsp_implementations)
|
||||
nnoremap("gr", telescope.lsp_references)
|
||||
nnoremap("K", vim.lsp.buf.hover)
|
||||
nnoremap("<C-k>", vim.lsp.buf.signature_help)
|
||||
nnoremap("<leader>rn", vim.lsp.buf.rename)
|
||||
nnoremap("<leader>ca", vim.lsp.buf.code_action)
|
||||
nnoremap("<leader>f", vim.lsp.buf.formatting)
|
||||
nnoremap("<leader>d", telescope.diagnostics)
|
||||
nnoremap("<C-p>", vim.diagnostic.goto_prev)
|
||||
nnoremap("<C-n>", vim.diagnostic.goto_next)
|
||||
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.formatting_sync({}, 3000)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local lsp_status = require("lsp-status")
|
||||
lsp_status.config({
|
||||
current_function = false,
|
||||
show_filename = false,
|
||||
diagnostics = true,
|
||||
})
|
||||
lsp_status.register_progress()
|
||||
|
||||
local capabilities = vim.tbl_extend("keep", vim.lsp.protocol.make_client_capabilities(), lsp_status.capabilities)
|
||||
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
|
||||
|
||||
local servers = {
|
||||
["bashls"] = {},
|
||||
["rnix"] = {},
|
||||
["terraformls"] = {},
|
||||
["tflint"] = {},
|
||||
}
|
||||
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
for lsp, settings in pairs(servers) do
|
||||
lspconfig[lsp].setup({
|
||||
settings = settings,
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end
|
||||
|
||||
require("rust-tools").setup({
|
||||
server = {
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
cargo = {
|
||||
loadOutDirsFromCheck = true,
|
||||
},
|
||||
checkOnSave = { command = "clippy" },
|
||||
procMacro = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
capabilities = capabilities,
|
||||
},
|
||||
})
|
||||
|
||||
local luadev = require("lua-dev").setup({
|
||||
lspconfig = {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
},
|
||||
runtime_path = true,
|
||||
})
|
||||
|
||||
lspconfig["sumneko_lua"].setup(luadev)
|
7
home-manager/neovim/lualine.lua
Normal file
7
home-manager/neovim/lualine.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
require('lualine').setup({
|
||||
options = { globalstatus = true },
|
||||
sections = {
|
||||
lualine_c = { { "filename", path = 1 }, "require('lsp-status').status()" }
|
||||
},
|
||||
extensions = { "toggleterm" }
|
||||
})
|
1
home-manager/neovim/luasnip.lua
Normal file
1
home-manager/neovim/luasnip.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require("luasnip.loaders.from_vscode").lazy_load()
|
2
home-manager/neovim/notify.lua
Normal file
2
home-manager/neovim/notify.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
require("notify").setup({ stages = "fade" })
|
||||
vim.notify = require("notify")
|
62
home-manager/neovim/nvim-cmp.lua
Normal file
62
home-manager/neovim/nvim-cmp.lua
Normal file
|
@ -0,0 +1,62 @@
|
|||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and
|
||||
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(
|
||||
col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
local cmp = require('cmp')
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end
|
||||
},
|
||||
sources = require("cmp").config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "path" },
|
||||
{ name = "buffer" },
|
||||
{ name = "nvim-lua" },
|
||||
{ name = "calc" },
|
||||
}),
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
experimental = { ghost_text = true }
|
||||
})
|
||||
|
||||
-- `/` cmdline setup.
|
||||
cmp.setup.cmdline('/', { sources = { { name = 'buffer' } } })
|
||||
|
||||
-- `:` cmdline setup.
|
||||
cmp.setup.cmdline(':', {
|
||||
sources = cmp.config
|
||||
.sources({ { name = 'path' } }, { { name = 'cmdline' } })
|
||||
})
|
54
home-manager/neovim/options.lua
Normal file
54
home-manager/neovim/options.lua
Normal file
|
@ -0,0 +1,54 @@
|
|||
-- termguicolors
|
||||
vim.opt.termguicolors = true
|
||||
|
||||
-- line numbers
|
||||
vim.opt.number = true
|
||||
|
||||
-- tabwidth
|
||||
vim.opt.tabstop = 4
|
||||
vim.opt.shiftwidth = 4
|
||||
|
||||
-- indent with spaces
|
||||
vim.opt.expandtab = true
|
||||
|
||||
-- scroll offset
|
||||
vim.opt.scrolloff = 4
|
||||
|
||||
-- don't warp lines
|
||||
vim.opt.wrap = false
|
||||
|
||||
-- split to right/below
|
||||
vim.opt.splitright = true
|
||||
vim.opt.splitbelow = true
|
||||
|
||||
-- presistent undo
|
||||
vim.opt.undofile = true
|
||||
|
||||
-- searching
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
|
||||
-- preview commands
|
||||
vim.opt.inccommand = "split"
|
||||
|
||||
-- completion
|
||||
vim.opt.completeopt = "menu,menuone,noselect"
|
||||
|
||||
-- set cursorline in active window
|
||||
vim.cmd([[
|
||||
augroup CursorLine
|
||||
autocmd!
|
||||
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
|
||||
autocmd WinLeave * setlocal nocursorline
|
||||
augroup END
|
||||
]])
|
||||
|
||||
-- configure terminal
|
||||
vim.cmd([[
|
||||
augroup terminal_setup
|
||||
autocmd!
|
||||
autocmd TermOpen * startinsert
|
||||
autocmd TermOpen * setlocal nonumber norelativenumber
|
||||
augroup END
|
||||
]])
|
||||
|
1
home-manager/neovim/tabline.lua
Normal file
1
home-manager/neovim/tabline.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require('tabline').setup({ enable = true, options = { show_bufnr = true, show_filename_only = true } })
|
33
home-manager/neovim/telescope.lua
Normal file
33
home-manager/neovim/telescope.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
local telescope = require("telescope")
|
||||
local actions = require("telescope.actions")
|
||||
local themes = require("telescope.themes")
|
||||
|
||||
telescope.setup({
|
||||
defaults = {
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<ESC>"] = actions.close,
|
||||
["<C-c>"] = actions.close
|
||||
},
|
||||
n = {
|
||||
["<ESC>"] = actions.close,
|
||||
["<C-c>"] = actions.close
|
||||
}
|
||||
}
|
||||
},
|
||||
extensions = {
|
||||
fzf = {
|
||||
fuzzy = true,
|
||||
override_generic_sorter = true,
|
||||
override_file_sorter = true
|
||||
},
|
||||
["ui-select"] = {
|
||||
themes.get_dropdown({})
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
telescope.load_extension("fzf")
|
||||
telescope.load_extension("ui-select")
|
2
home-manager/neovim/themes.lua
Normal file
2
home-manager/neovim/themes.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
vim.opt.background = 'light'
|
||||
vim.cmd("colorscheme solarized")
|
1
home-manager/neovim/toggleterm.lua
Normal file
1
home-manager/neovim/toggleterm.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require("toggleterm").setup({ size = 32, open_mapping = [[<F4>]] })
|
9
home-manager/neovim/treesitter.lua
Normal file
9
home-manager/neovim/treesitter.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
require('nvim-treesitter.configs').setup({
|
||||
highlight = {enable = true, additional_vim_regex_highlighting = false},
|
||||
indent = {enable = true},
|
||||
ensure_installed = {
|
||||
"bash", "c", "cpp", "css", "dockerfile", "hcl", "html", "javascript",
|
||||
"json", "latex", "lua", "markdown", "nix", "python", "rust", "svelte",
|
||||
"toml", "tsx", "typescript", "vim", "vue", "yaml"
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue