diff --git a/dotfiles/neovim/README.md b/dotfiles/neovim/README.md new file mode 100644 index 0000000..cb826f2 --- /dev/null +++ b/dotfiles/neovim/README.md @@ -0,0 +1,26 @@ +# Neovim config + +## Keybinds + +Table of my own keybinds. Here as documentation for myself. I am yet to include any of the keybinds for the lspconfig, telescope or cmp here. + +> Things written using italics are chords + +| Keybind | Description | Plugins | +| ---------------- | -------------------------------- | --------------- | +| vv | Create vertical split | | +| \\ | Save | | +| jj | Exit insert mode | | +| _vp_ | Run command in another tmux pane | vimux, arpeggio | +| C-n | Open tree | nvim-tree | + +## Some cool vim keybinds I sometimes forget about + +Documentation for myself + +| Keybind | Description | Plugins | +| ------- | ----------------------- | ------------ | +| zz | Center the current line | | +| C-w C-r | Swap 2 splits | | +| gcc | Comment line | nvim-comment | +| gc | Comment selection | nvim-comment | diff --git a/dotfiles/neovim/lua/my/helpers.lua b/dotfiles/neovim/lua/my/helpers.lua index 1db593d..fbaeb78 100644 --- a/dotfiles/neovim/lua/my/helpers.lua +++ b/dotfiles/neovim/lua/my/helpers.lua @@ -7,8 +7,13 @@ end function M.mergeTables(t1, t2) local t3 = {} - for k, v in pairs(t1) do t3[k] = v end - for k, v in pairs(t2) do t3[k] = v end + if t1 ~= nil then + for k, v in pairs(t1) do t3[k] = v end + end + + if t2 ~= nil then + for k, v in pairs(t2) do t3[k] = v end + end return t3 end diff --git a/dotfiles/neovim/lua/my/plugins/lspconfig.lua b/dotfiles/neovim/lua/my/plugins/lspconfig.lua index 51183fc..a1ea61c 100644 --- a/dotfiles/neovim/lua/my/plugins/lspconfig.lua +++ b/dotfiles/neovim/lua/my/plugins/lspconfig.lua @@ -1,4 +1,3 @@ -local cmd = vim.cmd local M = {} -- Command for formatting lua code @@ -10,10 +9,19 @@ local function map(buf, mode, lhs, rhs, opts) vim.api.nvim_buf_set_keymap(buf, mode, lhs, rhs, options) end -local function on_attach(client, bufnr) +function M.on_attach(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + if client.resolved_capabilities.document_formatting then + vim.cmd([[ + augroup LspFormatting + autocmd! * + autocmd BufWritePre lua vim.lsp.buf.formatting_sync() + augroup END + ]]) + end + -- Go to declaration / definition / implementation map(bufnr, "n", 'gD', 'lua vim.lsp.buf.declaration()') map(bufnr, "n", 'gd', 'lua vim.lsp.buf.definition()') @@ -40,7 +48,7 @@ local function on_attach_typescript(client, bufnr) client.resolved_capabilities.document_formatting = false client.resolved_capabilities.document_range_formatting = false - on_attach(client, bufnr) + M.on_attach(client, bufnr) end -- General server config @@ -80,7 +88,7 @@ function M.setup() for lsp, details in pairs(servers) do if details.on_attach == nil then -- Default setting for on_attach - details.on_attach = on_attach + details.on_attach = M.on_attach end require('lspconfig')[lsp].setup { @@ -94,6 +102,7 @@ function M.setup() } end + -- TODO: replace this with null-ls local efmLanguages = {lua = {{formatCommand = formatLua, formatStdin = true}}} -- Setup auto-formatting @@ -102,14 +111,6 @@ function M.setup() filetypes = {"lua"}, settings = {rootMarkers = {".git/"}, languages = efmLanguages} } - - local autoFormatOn = {lua = 200, purs = 1000, nix = 200, ts = 200, js = 200, json = 200, scss = 200, tsx = 200, jsx = 200} - - -- Auto format - for extension, _ in pairs(autoFormatOn) do - -- I wonder if this could be done in a single glob pattern - cmd("autocmd BufWritePre *." .. extension .. " lua vim.lsp.buf.formatting_sync()") - end end return M diff --git a/dotfiles/neovim/lua/my/plugins/null-ls.lua b/dotfiles/neovim/lua/my/plugins/null-ls.lua index ff41600..1534db1 100644 --- a/dotfiles/neovim/lua/my/plugins/null-ls.lua +++ b/dotfiles/neovim/lua/my/plugins/null-ls.lua @@ -1,13 +1,15 @@ +local lspconfig = require("my.plugins.lspconfig") + local M = {} function M.setup() local null_ls = require("null-ls") local sources = { - null_ls.builtins.formatting.prettierd -- format ts files + null_ls.builtins.formatting.prettierd.with({extra_filetypes = {"markdown"}}) -- format ts files } - null_ls.setup({sources = sources}) + null_ls.setup({sources = sources, on_attach = lspconfig.on_attach}) end return M diff --git a/dotfiles/neovim/lua/my/plugins/vimux.lua b/dotfiles/neovim/lua/my/plugins/vimux.lua index 794ea3a..79942ce 100644 --- a/dotfiles/neovim/lua/my/plugins/vimux.lua +++ b/dotfiles/neovim/lua/my/plugins/vimux.lua @@ -3,7 +3,7 @@ local arpeggio = require("my.plugins.arpeggio") local M = {} function M.setup() - arpeggio.chordSilent("n", "vp", ":VimuxPromptCommand") + arpeggio.chordSilent("n", "vp", ":VimuxPromptCommand") end return M diff --git a/flake.lock b/flake.lock index 637e952..1acb920 100644 --- a/flake.lock +++ b/flake.lock @@ -336,7 +336,8 @@ "nixpkgs-unstable": "nixpkgs-unstable", "oh-my-fish": "oh-my-fish", "telescope-file-browser-nvim": "telescope-file-browser-nvim", - "vim-extra-plugins": "vim-extra-plugins" + "vim-extra-plugins": "vim-extra-plugins", + "vim-plugin-arpeggio": "vim-plugin-arpeggio" } }, "telescope-file-browser-nvim": { @@ -374,6 +375,22 @@ "repo": "nixpkgs-vim-extra-plugins", "type": "github" } + }, + "vim-plugin-arpeggio": { + "flake": false, + "locked": { + "lastModified": 1597883245, + "narHash": "sha256-volgKWr1mNwmvOQQEw7feBztmpDVyPJG1n+OI8L1BRA=", + "owner": "kana", + "repo": "vim-arpeggio", + "rev": "01c8fc1a72ef58e490ee0490c65ee313b1b6e843", + "type": "github" + }, + "original": { + "owner": "kana", + "repo": "vim-arpeggio", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index b19fd3f..b284605 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,12 @@ vim-extra-plugins.url = "github:m15a/nixpkgs-vim-extra-plugins"; + # Plugin which enables me to create chords (aka keybinds where everything must be set at the same time) + vim-plugin-arpeggio = { + url = "github:kana/vim-arpeggio"; + flake = false; + }; + # Create / delete files within telescope telescope-file-browser-nvim = { url = "github:nvim-telescope/telescope-file-browser.nvim"; diff --git a/modules/applications/neovim.nix b/modules/applications/neovim.nix index b457bba..16a22bb 100644 --- a/modules/applications/neovim.nix +++ b/modules/applications/neovim.nix @@ -59,6 +59,7 @@ in # symbols-outline-nvim # tree view for symbols in document vimux # interact with tmux from within vim vim-tmux-navigator # easly switch between tmux and vim panes + arpeggio # allows me to setup chord keybinds (keybinds where all the keys are pressed at the same time) # Cmp related stuff. See https://github.com/hrsh7th/nvim-cmp cmp-nvim-lsp diff --git a/modules/overlays/flakes.nix b/modules/overlays/flakes.nix index 9fdb73a..7b9d98a 100644 --- a/modules/overlays/flakes.nix +++ b/modules/overlays/flakes.nix @@ -12,6 +12,7 @@ , oh-my-fish , githubNvimTheme , vim-extra-plugins +, vim-plugin-arpeggio , telescope-file-browser-nvim , ... }: self: super: @@ -63,5 +64,7 @@ in myVimPlugins = { telescope-file-browser-nvim = plugin "file_browser" telescope-file-browser-nvim; + + arpeggio = plugin "arpeggio" vim-plugin-arpeggio; }; }