diff --git a/modules/sean.nix b/modules/sean.nix index c190ce0..566776e 100644 --- a/modules/sean.nix +++ b/modules/sean.nix @@ -1,5 +1,10 @@ -{ ... }: +{ pkgs, ... }: { + environment.variables.EDITOR = "nvim"; + environment.systemPackages = [ + pkgs.bck-nvim + ]; + users.users.sean = { uid = 2000; isNormalUser = true; diff --git a/modules/vim.nix b/modules/vim.nix deleted file mode 100644 index 29e5de9..0000000 --- a/modules/vim.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ pkgs, ... }: -let - alias = cmd: pkgs.writeShellScriptBin cmd '' - exec nix run github:buckley310/vim -- "$@" - ''; -in -{ - environment.systemPackages = [ - (alias "vi") - (alias "vim") - ]; -} diff --git a/pkgs/bck-nvim/default.nix b/pkgs/bck-nvim/default.nix new file mode 100644 index 0000000..7068b90 --- /dev/null +++ b/pkgs/bck-nvim/default.nix @@ -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; + }; +} diff --git a/pkgs/bck-nvim/lua/0-nvimtree.lua b/pkgs/bck-nvim/lua/0-nvimtree.lua new file mode 100644 index 0000000..03f2b75 --- /dev/null +++ b/pkgs/bck-nvim/lua/0-nvimtree.lua @@ -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', 'e', 'NvimTreeToggle') + +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 + }, +}) diff --git a/pkgs/bck-nvim/lua/1-lualine.lua b/pkgs/bck-nvim/lua/1-lualine.lua new file mode 100644 index 0000000..973774b --- /dev/null +++ b/pkgs/bck-nvim/lua/1-lualine.lua @@ -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") diff --git a/pkgs/bck-nvim/lua/4-cmp.lua b/pkgs/bck-nvim/lua/4-cmp.lua new file mode 100644 index 0000000..d802e55 --- /dev/null +++ b/pkgs/bck-nvim/lua/4-cmp.lua @@ -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({ + [''] = cmp.mapping.confirm({ select = false }), + [''] = 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' } + } +}) diff --git a/pkgs/bck-nvim/lua/5-lsp.lua b/pkgs/bck-nvim/lua/5-lsp.lua new file mode 100644 index 0000000..48e6185 --- /dev/null +++ b/pkgs/bck-nvim/lua/5-lsp.lua @@ -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 +}) diff --git a/pkgs/bck-nvim/lua/8-other-plugins.lua b/pkgs/bck-nvim/lua/8-other-plugins.lua new file mode 100644 index 0000000..c6f72c8 --- /dev/null +++ b/pkgs/bck-nvim/lua/8-other-plugins.lua @@ -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', 'gl', 'lua require("gitsigns").blame_line()') +vim.keymap.set('n', 'gp', 'lua require("gitsigns").preview_hunk()') +vim.keymap.set('n', 'gr', 'lua require("gitsigns").reset_hunk()') +vim.keymap.set('n', 'gs', 'lua require("gitsigns").stage_hunk()') +vim.keymap.set('n', 'gu', 'lua require("gitsigns").reset_buffer_index()') diff --git a/pkgs/bck-nvim/lua/9-misc.lua b/pkgs/bck-nvim/lua/9-misc.lua new file mode 100644 index 0000000..824ca40 --- /dev/null +++ b/pkgs/bck-nvim/lua/9-misc.lua @@ -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', 'ff', 'Telescope find_files') +vim.keymap.set('n', 'fr', 'Telescope oldfiles') +vim.keymap.set('n', 'fg', 'Telescope git_files') + +vim.keymap.set('n', '>', '>>^') +vim.keymap.set('n', '<', '<<^') +vim.keymap.set('v', '<', '', '>gv^') + +vim.keymap.set('n', '', '}') +vim.keymap.set('n', '', '{') +vim.keymap.set('v', '', '}') +vim.keymap.set('v', '', '{') + +vim.keymap.set('n', 'w', 'w') +vim.keymap.set('n', 'q', 'q') +vim.keymap.set('n', 'c', ':bdelete') +vim.keymap.set('n', '', 'bprevious') +vim.keymap.set('n', '', 'bnext') + +vim.keymap.set('n', "", "resize -2") +vim.keymap.set('n', "", "resize +2") +vim.keymap.set('n', "", "vertical resize -2") +vim.keymap.set('n', "", "vertical resize +2") + +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 .. '>', + '<' .. 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