merge vim config

This commit is contained in:
Sean Buckley 2024-02-23 00:14:23 -05:00
parent cb1f353e6a
commit c7e0ebea7f
9 changed files with 404 additions and 13 deletions

View file

@ -1,5 +1,10 @@
{ ... }: { pkgs, ... }:
{ {
environment.variables.EDITOR = "nvim";
environment.systemPackages = [
pkgs.bck-nvim
];
users.users.sean = { users.users.sean = {
uid = 2000; uid = 2000;
isNormalUser = true; isNormalUser = true;

View file

@ -1,12 +0,0 @@
{ pkgs, ... }:
let
alias = cmd: pkgs.writeShellScriptBin cmd ''
exec nix run github:buckley310/vim -- "$@"
'';
in
{
environment.systemPackages = [
(alias "vi")
(alias "vim")
];
}

68
pkgs/bck-nvim/default.nix Normal file
View file

@ -0,0 +1,68 @@
{ lib
, neovim-unwrapped
, vimPlugins
, wrapNeovim
# LSP
, black
, efm-langserver
, lua-language-server
, nil
, nodePackages
, pyright
, vscode-langservers-extracted
, yaml-language-server
}:
let
luafiles = lib.concatLines (map
(x: "luafile ${./lua}/${x}")
(builtins.attrNames (builtins.readDir ./lua))
);
extraPath = lib.concatLines (map
(p: "let $PATH .= ':${p}/bin'")
[
black
efm-langserver
lua-language-server
nil
nodePackages.prettier
nodePackages.typescript-language-server
pyright
vscode-langservers-extracted
yaml-language-server
]
);
in
wrapNeovim neovim-unwrapped {
viAlias = true;
vimAlias = true;
configure = {
packages.bck.start = with vimPlugins; [
# cmp
cmp-buffer
cmp-nvim-lsp
cmp-path
cmp_luasnip
luasnip
nvim-cmp
# other
bufferline-nvim
comment-nvim
gitsigns-nvim
indent-blankline-nvim
lualine-nvim
nvim-lspconfig
nvim-tree-lua
nvim-treesitter.withAllGrammars
nvim-web-devicons
project-nvim
telescope-nvim
vim-code-dark
vim-tmux-navigator
];
customRC = extraPath + luafiles;
};
}

View file

@ -0,0 +1,30 @@
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.termguicolors = true
vim.cmd("colorscheme codedark")
vim.keymap.set('n', '<space>e', '<cmd>NvimTreeToggle<cr>')
local function my_on_attach(bufnr)
local api = require('nvim-tree.api')
local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
api.config.mappings.default_on_attach(bufnr)
vim.keymap.set('n', 'l', api.node.open.edit, opts('Open'))
vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts('Close Directory'))
end
require("nvim-tree").setup({
on_attach = my_on_attach,
disable_netrw = true,
hijack_netrw = true,
sync_root_with_cwd = true,
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_root = true
},
})

View file

@ -0,0 +1,25 @@
local sections = require('lualine').get_config().sections
sections.lualine_x = {
function()
local bufnr = vim.api.nvim_get_current_buf()
local clients = vim.lsp.buf_get_clients(bufnr)
if next(clients) == nil then
return ''
end
local c = {}
for _, client in pairs(clients) do
table.insert(c, client.name)
end
return '\u{f013} ' .. table.concat(c, ',')
end,
'filetype',
}
require('lualine').setup({
options = {
disabled_filetypes = { 'NvimTree' },
},
sections = sections,
})
vim.cmd("set noshowmode")

View file

@ -0,0 +1,37 @@
local cmp = require('cmp')
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
['<Tab>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, {
{ name = 'buffer' },
})
})
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'path' }
}
})

141
pkgs/bck-nvim/lua/5-lsp.lua Normal file
View file

@ -0,0 +1,141 @@
local lspconfig = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').default_capabilities()
----------------------------------------------------------------
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
})
----------------------------------------------------------------
lspconfig.pyright.setup({
capabilities = capabilities,
})
----------------------------------------------------------------
lspconfig.tsserver.setup({
capabilities = capabilities,
on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = false
end,
})
----------------------------------------------------------------
lspconfig.html.setup({
capabilities = capabilities,
on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = false
end,
})
----------------------------------------------------------------
lspconfig.cssls.setup({
capabilities = capabilities,
on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = false
end,
})
----------------------------------------------------------------
lspconfig.nil_ls.setup({
capabilities = capabilities,
cmd = { "nil" },
settings = {
['nil'] = {
formatting = {
command = { "nixpkgs-fmt" },
},
},
},
})
----------------------------------------------------------------
lspconfig.yamlls.setup({
capabilities = capabilities,
settings = {
yaml = {
schemas = {
kubernetes = "/*.yaml",
},
customTags = {
-- https://github.com/aws-cloudformation/cfn-lint-visual-studio-code/blob/3ff0b8cc1bbfc34448c865b54deff8c7d030beba/server/src/cfnSettings.ts
"!And sequence",
"!If sequence",
"!Not sequence",
"!Equals sequence",
"!Or sequence",
"!FindInMap sequence",
"!Base64 scalar",
"!Join sequence",
"!Cidr sequence",
"!Ref scalar",
"!Sub scalar",
"!Sub sequence",
"!GetAtt scalar",
"!GetAtt sequence",
"!GetAZs mapping",
"!GetAZs scalar",
"!ImportValue mapping",
"!ImportValue scalar",
"!Select sequence",
"!Split sequence",
},
},
},
on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = true
end,
})
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
local efmprettier = {
{
formatStdin = true,
formatCommand = "prettier --stdin-filepath ${INPUT}",
}
}
lspconfig.efm.setup({
filetypes = {
"css",
"html",
"javascript",
"typescript",
"python",
},
init_options = {
documentFormatting = true
},
settings = {
languages = {
css = efmprettier,
html = efmprettier,
javascript = efmprettier,
typescript = efmprettier,
python = {
{
formatStdin = true,
formatCommand = "black --quiet -",
},
},
},
},
})
----------------------------------------------------------------
vim.api.nvim_create_autocmd("BufWritePre", {
callback = function(e)
for _, client in pairs(vim.lsp.buf_get_clients(e.buf)) do
if client.supports_method("textDocument/formatting") then
return vim.lsp.buf.format()
end
end
end
})

View file

@ -0,0 +1,40 @@
require('nvim-treesitter.configs').setup({
highlight = {
enable = true,
},
})
----------------------------------------------------------------
require('project_nvim').setup({
detection_methods = { "pattern" },
patterns = { ".git", "flake.nix", "package.json" },
})
----------------------------------------------------------------
require('Comment').setup({})
----------------------------------------------------------------
require("bufferline").setup({
options = {
separator_style = "slant"
}
})
----------------------------------------------------------------
vim.cmd("highlight NonText guifg=#404040")
require("ibl").setup({
scope = { enabled = false },
indent = { char = "\u{258f}" },
})
----------------------------------------------------------------
require('gitsigns').setup({})
vim.cmd("set signcolumn=yes") -- signcolumn=number ?
vim.cmd("highlight GitSignsAdd ctermfg=2 guifg=#009900")
vim.cmd("highlight GitSignsChange ctermfg=3 guifg=#bbbb00")
vim.cmd("highlight GitSignsDelete ctermfg=1 guifg=#ff2222")
vim.keymap.set('n', '<space>gl', '<cmd>lua require("gitsigns").blame_line()<cr>')
vim.keymap.set('n', '<space>gp', '<cmd>lua require("gitsigns").preview_hunk()<cr>')
vim.keymap.set('n', '<space>gr', '<cmd>lua require("gitsigns").reset_hunk()<cr>')
vim.keymap.set('n', '<space>gs', '<cmd>lua require("gitsigns").stage_hunk()<cr>')
vim.keymap.set('n', '<space>gu', '<cmd>lua require("gitsigns").reset_buffer_index()<cr>')

View file

@ -0,0 +1,57 @@
vim.cmd("set mouse=")
vim.cmd("set number relativenumber")
vim.cmd("set nowrap")
vim.cmd("set scrolloff=9")
vim.cmd("set tabstop=4")
vim.cmd("set shiftwidth=4")
vim.cmd("set ignorecase smartcase")
vim.keymap.set('n', '<space>ff', '<cmd>Telescope find_files<cr>')
vim.keymap.set('n', '<space>fr', '<cmd>Telescope oldfiles<cr>')
vim.keymap.set('n', '<space>fg', '<cmd>Telescope git_files<cr>')
vim.keymap.set('n', '>', '>>^')
vim.keymap.set('n', '<', '<<^')
vim.keymap.set('v', '<', '<gv^')
vim.keymap.set('v', '>', '>gv^')
vim.keymap.set('n', '<A-j>', '}')
vim.keymap.set('n', '<A-k>', '{')
vim.keymap.set('v', '<A-j>', '}')
vim.keymap.set('v', '<A-k>', '{')
vim.keymap.set('n', '<space>w', '<cmd>w<cr>')
vim.keymap.set('n', '<space>q', '<cmd>q<cr>')
vim.keymap.set('n', '<space>c', '<cmd>:bdelete<cr>')
vim.keymap.set('n', '<A-h>', '<cmd>bprevious<cr>')
vim.keymap.set('n', '<A-l>', '<cmd>bnext<cr>')
vim.keymap.set('n', "<C-Up>", "<cmd>resize -2<cr>")
vim.keymap.set('n', "<C-Down>", "<cmd>resize +2<cr>")
vim.keymap.set('n', "<C-Left>", "<cmd>vertical resize -2<cr>")
vim.keymap.set('n', "<C-Right>", "<cmd>vertical resize +2<cr>")
vim.cmd("autocmd TermOpen * setlocal nonumber norelativenumber")
for _, key in pairs({ 'h', 'j', 'k', 'l' }) do
for _, mod in pairs({ 'C', 'A' }) do
vim.keymap.set(
't',
'<' .. mod .. '-' .. key .. '>',
'<C-\\><C-n><' .. mod .. '-' .. key .. '>',
{ remap = true }
)
end
end
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end
})
local fname = os.getenv("HOME") .. "/.bck-nvim.lua"
local f = io.open(fname, "r")
if f ~= nil then
io.close(f)
vim.cmd('luafile ' .. fname)
end