From 7d3ed01ce8aa2561e49cd5b3b8016c210b8c1ce3 Mon Sep 17 00:00:00 2001 From: Redyf Date: Sun, 11 Feb 2024 22:56:32 -0300 Subject: [PATCH 1/6] feat: Add option to format selected lines With cF only the selected lines in visual mode will be formatted. That if your lsp supports this action... --- config/lsp/conform.nix | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/config/lsp/conform.nix b/config/lsp/conform.nix index c5326eca..f2546981 100644 --- a/config/lsp/conform.nix +++ b/config/lsp/conform.nix @@ -3,18 +3,18 @@ enable = true; notifyOnError = true; formattersByFt = { - html = [ [ "prettierd" "prettier" ] ]; - css = [ [ "prettierd" "prettier" ] ]; - javascript = [ [ "prettierd" "prettier" ] ]; - javascriptreact = [ [ "prettierd" "prettier" ] ]; - typescript = [ [ "prettierd" "prettier" ] ]; - typescriptreact = [ [ "prettierd" "prettier" ] ]; - java = [ "google-java-format" ]; - python = [ "black" ]; - lua = [ "stylua" ]; - nix = [ "alejandra" ]; - markdown = [ [ "prettierd" "prettier" ] ]; - rust = [ "rustfmt" ]; + html = [["prettierd" "prettier"]]; + css = [["prettierd" "prettier"]]; + javascript = [["prettierd" "prettier"]]; + javascriptreact = [["prettierd" "prettier"]]; + typescript = [["prettierd" "prettier"]]; + typescriptreact = [["prettierd" "prettier"]]; + java = ["google-java-format"]; + python = ["black"]; + lua = ["stylua"]; + nix = ["alejandra"]; + markdown = [["prettierd" "prettier"]]; + rust = ["rustfmt"]; }; }; @@ -71,12 +71,21 @@ }; } { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "cf"; action = "lua require('conform').format()"; options = { silent = true; - desc = "Format"; + desc = "Format Buffer"; + }; + } + { + mode = "v"; + key = "cF"; + action = "lua vim.lsp.buf.format()"; + options = { + silent = true; + desc = "Format Lines"; }; } ]; From e5e3c47ff58a468f5865ec1e44d949d845f1bad6 Mon Sep 17 00:00:00 2001 From: Redyf Date: Sun, 11 Feb 2024 23:08:58 -0300 Subject: [PATCH 2/6] feat: Add keymapping for indenting lines without leaving visual mode --- config/keymaps.nix | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/config/keymaps.nix b/config/keymaps.nix index 2318af36..bfa21709 100644 --- a/config/keymaps.nix +++ b/config/keymaps.nix @@ -336,7 +336,27 @@ action = "mzJ`z"; options = { silent = true; - desc = "Allow cursor to stay in the same place after appending to current line "; + desc = "Allow cursor to stay in the same place after appeding to current line"; + }; + } + + { + mode = "v"; + key = "<"; + action = " Date: Sun, 11 Feb 2024 23:09:40 -0300 Subject: [PATCH 3/6] feat: Add option to format buffer with gq More info in the code --- config/sets.nix | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/config/sets.nix b/config/sets.nix index e64ac12e..2da14863 100644 --- a/config/sets.nix +++ b/config/sets.nix @@ -1,7 +1,8 @@ -{ pkgs -, lib -, config -, ... +{ + pkgs, + lib, + config, + ... }: { config = { options = { @@ -9,7 +10,7 @@ number = true; relativenumber = true; - # Set tabs to 2 spaces + # Set tabs to 2 spaces tabstop = 2; softtabstop = 2; showtabline = 2; @@ -46,14 +47,14 @@ updatetime = 50; # faster completion (4000ms default) # Set completeopt to have a better completion experience - completeopt = [ "menuone" "noselect" "noinsert" ]; # mostly just for cmp + completeopt = ["menuone" "noselect" "noinsert"]; # mostly just for cmp # Enable persistent undo history swapfile = false; backup = false; undofile = true; - # Enable 24-bit colors + # Enable 24-bit colors termguicolors = true; # Enable the sign column to prevent the screen from jumping @@ -106,6 +107,8 @@ # Maximum number of items to show in the popup menu (0 means "use available screen space") pumheight = 0; + # Use conform-nvim for gq formatting. ('formatexpr' is set to vim.lsp.formatexpr(), so you can format lines via gq if the language server supports it) + formatexpr = "v:lua.require'conform'.formatexpr()"; }; extraConfigLua = '' From e36d208d41b8d3a65a6be15613484ef79cd96a3e Mon Sep 17 00:00:00 2001 From: Redyf Date: Sun, 11 Feb 2024 23:39:38 -0300 Subject: [PATCH 4/6] feat: Add notifications for wrap, relative line number and number. --- config/keymaps.nix | 74 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/config/keymaps.nix b/config/keymaps.nix index a024b9d4..83203ecc 100644 --- a/config/keymaps.nix +++ b/config/keymaps.nix @@ -6,7 +6,7 @@ keymaps = [ # Disable arrow keys { - mode = [ "n" "i" ]; + mode = ["n" "i"]; key = ""; action = ""; options = { @@ -16,7 +16,7 @@ }; } { - mode = [ "n" "i" ]; + mode = ["n" "i"]; key = ""; action = ""; options = { @@ -26,7 +26,7 @@ }; } { - mode = [ "n" "i" ]; + mode = ["n" "i"]; key = ""; action = ""; options = { @@ -36,7 +36,7 @@ }; } { - mode = [ "n" "i" ]; + mode = ["n" "i"]; key = ""; action = ""; options = { @@ -66,7 +66,7 @@ } { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "g"; action = "+git"; } @@ -90,19 +90,19 @@ } { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "d"; action = "+debug"; } { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "c"; action = "+code"; } { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "t"; action = "+test"; } @@ -379,6 +379,31 @@ }; } + # Remap for dealing with word wrap and adding jumps to the jumplist. + { + mode = "n"; + key = "j"; + action.__raw = " + [[(v:count > 1 ? 'm`' . v:count : 'g') . 'j']] + "; + options = { + expr = true; + desc = "Remap for dealing with word wrap and adding jumps to the jumplist."; + }; + } + + { + mode = "n"; + key = "k"; + action.__raw = " + [[(v:count > 1 ? 'm`' . v:count : 'g') . 'k']] + "; + options = { + expr = true; + desc = "Remap for dealing with word wrap and adding jumps to the jumplist."; + }; + } + { mode = "n"; key = "n"; @@ -409,7 +434,7 @@ # Copy stuff to system clipboard with + y or just y to have it just in vim { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "y"; action = "\"+y"; options = { @@ -418,7 +443,7 @@ } { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "Y"; action = "\"+Y"; options = { @@ -428,7 +453,7 @@ # Delete to void register { - mode = [ "n" "v" ]; + mode = ["n" "v"]; key = "D"; action = "\"_d"; options = { @@ -453,27 +478,44 @@ } ]; extraConfigLua = '' + local notify = require("notify") + + local function show_notification(message, level) + notify(message, level, { title = "conform.nvim" }) + end + function ToggleLineNumber() if vim.wo.number then vim.wo.number = false + show_notification("Line numbers disabled", "info") else vim.wo.number = true vim.wo.relativenumber = false + show_notification("Line numbers enabled", "info") end end function ToggleRelativeLineNumber() if vim.wo.relativenumber then vim.wo.relativenumber = false + show_notification("Relative line numbers disabled", "info") else vim.wo.relativenumber = true vim.wo.number = false - end - end + show_notification("Relative line numbers enabled", "info") + end + end - function ToggleWrap() - vim.wo.wrap = not vim.wo.wrap - end + function ToggleWrap() + if vim.wo.wrap then + vim.wo.wrap = false + show_notification("Wrap disabled", "info") + else + vim.wo.wrap = true + vim.wo.number = false + show_notification("Wrap enabled", "info") + end + end if vim.lsp.inlay_hint then vim.keymap.set( From f21dab8d6f4de61ad6de28626d68b8303923b2b5 Mon Sep 17 00:00:00 2001 From: Redyf Date: Sun, 11 Feb 2024 23:40:23 -0300 Subject: [PATCH 5/6] refactor: Move keymaps on top of extraConfigLua --- config/lsp/conform.nix | 61 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/config/lsp/conform.nix b/config/lsp/conform.nix index f2546981..7b356c5e 100644 --- a/config/lsp/conform.nix +++ b/config/lsp/conform.nix @@ -18,6 +18,36 @@ }; }; + keymaps = [ + { + mode = "n"; + key = "uf"; + action = ":FormatToggle"; + options = { + desc = "Toggle Format"; + silent = true; + }; + } + { + mode = ["n" "v"]; + key = "cf"; + action = "lua require('conform').format()"; + options = { + silent = true; + desc = "Format Buffer"; + }; + } + { + mode = "v"; + key = "cF"; + action = "lua vim.lsp.buf.format()"; + options = { + silent = true; + desc = "Format Lines"; + }; + } + ]; + extraConfigLua = '' local conform = require("conform") local notify = require("notify") @@ -57,36 +87,5 @@ desc = "Toggle autoformat-on-save", bang = true, }) - ''; - - keymaps = [ - { - mode = "n"; - key = "uf"; - action = ":FormatToggle"; - options = { - desc = "Toggle Format"; - silent = true; - }; - } - { - mode = ["n" "v"]; - key = "cf"; - action = "lua require('conform').format()"; - options = { - silent = true; - desc = "Format Buffer"; - }; - } - { - mode = "v"; - key = "cF"; - action = "lua vim.lsp.buf.format()"; - options = { - silent = true; - desc = "Format Lines"; - }; - } - ]; } From d3008136b93778828d54a711278e92a2fd4cc565 Mon Sep 17 00:00:00 2001 From: redyf Date: Mon, 12 Feb 2024 02:56:08 +0000 Subject: [PATCH 6/6] Auto lint/format --- config/keymaps.nix | 22 +++++++++++----------- config/lsp/conform.nix | 26 +++++++++++++------------- config/sets.nix | 11 +++++------ flake.lock | 30 +++++++++++++++--------------- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/config/keymaps.nix b/config/keymaps.nix index 83203ecc..29fec466 100644 --- a/config/keymaps.nix +++ b/config/keymaps.nix @@ -6,7 +6,7 @@ keymaps = [ # Disable arrow keys { - mode = ["n" "i"]; + mode = [ "n" "i" ]; key = ""; action = ""; options = { @@ -16,7 +16,7 @@ }; } { - mode = ["n" "i"]; + mode = [ "n" "i" ]; key = ""; action = ""; options = { @@ -26,7 +26,7 @@ }; } { - mode = ["n" "i"]; + mode = [ "n" "i" ]; key = ""; action = ""; options = { @@ -36,7 +36,7 @@ }; } { - mode = ["n" "i"]; + mode = [ "n" "i" ]; key = ""; action = ""; options = { @@ -66,7 +66,7 @@ } { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "g"; action = "+git"; } @@ -90,19 +90,19 @@ } { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "d"; action = "+debug"; } { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "c"; action = "+code"; } { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "t"; action = "+test"; } @@ -434,7 +434,7 @@ # Copy stuff to system clipboard with + y or just y to have it just in vim { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "y"; action = "\"+y"; options = { @@ -443,7 +443,7 @@ } { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "Y"; action = "\"+Y"; options = { @@ -453,7 +453,7 @@ # Delete to void register { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "D"; action = "\"_d"; options = { diff --git a/config/lsp/conform.nix b/config/lsp/conform.nix index 7b356c5e..37cfd93d 100644 --- a/config/lsp/conform.nix +++ b/config/lsp/conform.nix @@ -3,18 +3,18 @@ enable = true; notifyOnError = true; formattersByFt = { - html = [["prettierd" "prettier"]]; - css = [["prettierd" "prettier"]]; - javascript = [["prettierd" "prettier"]]; - javascriptreact = [["prettierd" "prettier"]]; - typescript = [["prettierd" "prettier"]]; - typescriptreact = [["prettierd" "prettier"]]; - java = ["google-java-format"]; - python = ["black"]; - lua = ["stylua"]; - nix = ["alejandra"]; - markdown = [["prettierd" "prettier"]]; - rust = ["rustfmt"]; + html = [ [ "prettierd" "prettier" ] ]; + css = [ [ "prettierd" "prettier" ] ]; + javascript = [ [ "prettierd" "prettier" ] ]; + javascriptreact = [ [ "prettierd" "prettier" ] ]; + typescript = [ [ "prettierd" "prettier" ] ]; + typescriptreact = [ [ "prettierd" "prettier" ] ]; + java = [ "google-java-format" ]; + python = [ "black" ]; + lua = [ "stylua" ]; + nix = [ "alejandra" ]; + markdown = [ [ "prettierd" "prettier" ] ]; + rust = [ "rustfmt" ]; }; }; @@ -29,7 +29,7 @@ }; } { - mode = ["n" "v"]; + mode = [ "n" "v" ]; key = "cf"; action = "lua require('conform').format()"; options = { diff --git a/config/sets.nix b/config/sets.nix index 2da14863..23777191 100644 --- a/config/sets.nix +++ b/config/sets.nix @@ -1,8 +1,7 @@ -{ - pkgs, - lib, - config, - ... +{ pkgs +, lib +, config +, ... }: { config = { options = { @@ -47,7 +46,7 @@ updatetime = 50; # faster completion (4000ms default) # Set completeopt to have a better completion experience - completeopt = ["menuone" "noselect" "noinsert"]; # mostly just for cmp + completeopt = [ "menuone" "noselect" "noinsert" ]; # mostly just for cmp # Enable persistent undo history swapfile = false; diff --git a/flake.lock b/flake.lock index d4cb3180..c67ff637 100644 --- a/flake.lock +++ b/flake.lock @@ -103,11 +103,11 @@ ] }, "locked": { - "lastModified": 1706955260, - "narHash": "sha256-W3y0j77IDVbmbajudHoUr46RpswujUCl+D5Vru53UsI=", + "lastModified": 1707467182, + "narHash": "sha256-/Bw/xgCXfj4nXDd8Xq+r1kaorfsYkkomMf5w5MpsDyA=", "owner": "nix-community", "repo": "home-manager", - "rev": "880d9bc2110f7cae59698f715b8ca42cdc53670c", + "rev": "5b9156fa9a8b8beba917b8f9adbfd27bf63e16af", "type": "github" }, "original": { @@ -139,11 +139,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1707588924, - "narHash": "sha256-0e1ce6X5ghapv6cAF9rxLZKeNyFHHXsLbGxN2cQQE8U=", + "lastModified": 1707619277, + "narHash": "sha256-vKnYD5GMQbNQyyQm4wRlqi+5n0/F1hnvqSQgaBy4BqY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "10b813040df67c4039086db0f6eaf65c536886c6", + "rev": "f3a93440fbfff8a74350f4791332a19282cc6dc8", "type": "github" }, "original": { @@ -153,11 +153,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1706732774, - "narHash": "sha256-hqJlyJk4MRpcItGYMF+3uHe8HvxNETWvlGtLuVpqLU0=", + "lastModified": 1707268954, + "narHash": "sha256-2en1kvde3cJVc3ZnTy8QeD2oKcseLFjYPLKhIGDanQ0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b8b232ae7b8b144397fdb12d20f592e5e7c1a64d", + "rev": "f8e2ebd66d097614d51a56a755450d4ae1632df1", "type": "github" }, "original": { @@ -176,11 +176,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1707677596, - "narHash": "sha256-+xMTYbWXBu0Sek8rjKuXAL3mBLgTp1Bcwp4i1XRBJwo=", + "lastModified": 1707691286, + "narHash": "sha256-yZ8KzUBAo0xMk683krioF/YPr0StrN32kkDYArfrrOs=", "owner": "nix-community", "repo": "nixvim", - "rev": "30bc345dee03d933af184f63056ab2ee9864d37f", + "rev": "f44d117d59117e55c4ddf1837e5eb65eeda2f135", "type": "github" }, "original": { @@ -204,11 +204,11 @@ ] }, "locked": { - "lastModified": 1706424699, - "narHash": "sha256-Q3RBuOpZNH2eFA1e+IHgZLAOqDD9SKhJ/sszrL8bQD4=", + "lastModified": 1707297608, + "narHash": "sha256-ADjo/5VySGlvtCW3qR+vdFF4xM9kJFlRDqcC9ZGI8EA=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "7c54e08a689b53c8a1e5d70169f2ec9e2a68ffaf", + "rev": "0db2e67ee49910adfa13010e7f012149660af7f0", "type": "github" }, "original": {