From 6fe5826a29fe17ed9c80659c825a49d8bf0df09d Mon Sep 17 00:00:00 2001
From: Matei Adriel <rafaeladriel11@gmail.com>
Date: Mon, 4 Apr 2022 10:01:13 +0300
Subject: [PATCH] feat: fixed leader not working

---
 dotfiles/neovim/README.md                     | 41 +++++++++++++++----
 dotfiles/neovim/lua/my/keymaps.lua            |  4 +-
 dotfiles/neovim/lua/my/options.lua            |  2 +-
 dotfiles/neovim/lua/my/plugins/arpeggio.lua   | 16 +++++---
 .../neovim/lua/my/plugins/lh-brackets.lua     | 30 ++++++++++----
 dotfiles/neovim/lua/my/plugins/telescope.lua  | 16 ++++----
 6 files changed, 79 insertions(+), 30 deletions(-)

diff --git a/dotfiles/neovim/README.md b/dotfiles/neovim/README.md
index cb826f2..20d21c1 100644
--- a/dotfiles/neovim/README.md
+++ b/dotfiles/neovim/README.md
@@ -5,14 +5,40 @@
 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
+> (aka all the keys need to be pressed at the same time)
 
-| Keybind          | Description                      | Plugins         |
-| ---------------- | -------------------------------- | --------------- |
-| vv               | Create vertical split            |                 |
-| \<Space>\<Space> | Save                             |                 |
-| jj               | Exit insert mode                 |                 |
-| _vp_             | Run command in another tmux pane | vimux, arpeggio |
-| C-n              | Open tree                        | nvim-tree       |
+| Keybind          | Description                                 | Plugins            |
+| ---------------- | ------------------------------------------- | ------------------ |
+| vv               | Create vertical split                       |                    |
+| \<Space>\<Space> | Save                                        |                    |
+| jj               | Exit insert mode                            |                    |
+| C-n              | Open tree                                   | nvim-tree          |
+| _vp_             | Run command in another tmux pane            | vimux, arpeggio    |
+| _<leader>k_      | Insert digraph                              |                    |
+| _<leader>a_      | Swap last 2 used buffers                    |                    |
+| _sk_             | Move to previous lh-bracket marker          | lh-brackets        |
+| _sj_             | Move to next lh-bracket marker              | lh-brackets        |
+| _mo_             | Move outside the current brackets           | lh-brackets        |
+| _ml_             | Remove all markers and move to the last one | lh-brackets        |
+| C-hjkl           | Navigation between vim & tmux panes         | vim-tmux-navigator |
+
+### Idris
+
+> The idris and arpeggio plugins are implicit here
+
+| Keybind | Description         |
+| ------- | ------------------- |
+| _sc_    | Case split          |
+| _mc_    | Make case           |
+| _ml_    | Make lemma          |
+| _es_    | Expression search   |
+| _gd_    | Generate definition |
+| _rh_    | Refine hole         |
+| _ac_    | Add clause          |
+
+### Lean
+
+- Extra brackets: ⟨⟩
 
 ## Some cool vim keybinds I sometimes forget about
 
@@ -21,6 +47,5 @@ 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/keymaps.lua b/dotfiles/neovim/lua/my/keymaps.lua
index 8fcbe5f..5a0b41c 100644
--- a/dotfiles/neovim/lua/my/keymaps.lua
+++ b/dotfiles/neovim/lua/my/keymaps.lua
@@ -27,8 +27,10 @@ function M.setup()
 
     if arpeggio ~= nil then
         -- Create chords
-        arpeggio.chord("i", "<Leader>k", "C-k") -- Rebind digraph insertion to leader+k
+        arpeggio.chord("i", "<Leader>k", "<C-k><cr>") -- Rebind digraph insertion to leader+k
+        arpeggio.chord("inv", "<Leader>a", "<C-6><cr>") -- Rebind switching to the last pane using leader+a
     end
+
 end
 
 return M
diff --git a/dotfiles/neovim/lua/my/options.lua b/dotfiles/neovim/lua/my/options.lua
index ff25353..7113aad 100644
--- a/dotfiles/neovim/lua/my/options.lua
+++ b/dotfiles/neovim/lua/my/options.lua
@@ -30,7 +30,7 @@ function M.setup()
     opt.completeopt = {"menu", "menuone", "noselect"}
 
     -- Set leader
-    helpers.global("mapleader", "<Space>")
+    helpers.global("mapleader", " ")
 
     -- Import other options
     require("my.options.folding").setup()
diff --git a/dotfiles/neovim/lua/my/plugins/arpeggio.lua b/dotfiles/neovim/lua/my/plugins/arpeggio.lua
index 8e98120..6b5a33e 100644
--- a/dotfiles/neovim/lua/my/plugins/arpeggio.lua
+++ b/dotfiles/neovim/lua/my/plugins/arpeggio.lua
@@ -4,13 +4,19 @@ local arpeggio = vim.fn["arpeggio#map"]
 local M = {}
 
 function M.chord(mode, lhs, rhs, opts)
-    local options = helpers.mergeTables(opts, {noremap = true})
+    if string.len(mode) > 1 then
+        for i = 1, #mode do
+            local c = mode:sub(i, i)
+            M.chord(c, lhs, rhs, opts)
+        end
+    else
+        local options = helpers.mergeTables(opts, {noremap = true})
+        local settings = ""
 
-    local settings = ""
+        if options.silent then settings = settings .. "s" end
 
-    if options.silent then settings = settings .. "s" end
-
-    arpeggio(mode, settings, options.noremap, lhs, rhs)
+        arpeggio(mode, settings, options.noremap, lhs, rhs)
+    end
 end
 
 function M.chordSilent(mode, lhs, rhs, opts)
diff --git a/dotfiles/neovim/lua/my/plugins/lh-brackets.lua b/dotfiles/neovim/lua/my/plugins/lh-brackets.lua
index 9580c9d..4deaa3e 100644
--- a/dotfiles/neovim/lua/my/plugins/lh-brackets.lua
+++ b/dotfiles/neovim/lua/my/plugins/lh-brackets.lua
@@ -1,8 +1,14 @@
 local A = require("my.helpers.augroup")
 local map = require("my.keymaps").mapSilent
+local arpeggio = require("my.plugins.arpeggio")
 local M = {}
 
-local extraBrackets = {lean = {{"⟨", "⟩"}}}
+local extraBrackets = {
+    lean = {{"⟨", "⟩"}}, -- lean
+    all = {
+        {"(", ")"}, {"[", "]"}, {"'", "'"}, {'"', '"'}, {"{", "}"}, {"`", "`"}
+    } -- more general stuff
+}
 
 function M.createBracketCommand(lhs, rhs, isGlobal, opts)
     local suffix = ""
@@ -17,19 +23,29 @@ function M.createBracket(lhs, rhs, isGlobal, opts)
 end
 
 function M.setup()
+
+    if arpeggio == nil then return end
+
     vim.g.marker_define_jump_mappings = 0 -- disable automatic binding of marker jumping (conflicts with tmux-vim-navigator)
 
-    map("inv", "sf", '<Plug>MarkersJumpF')
-    map("inv", "fs", '<Plug>MarkersJumpB')
-    map("inv", "mi", '<Plug>MarkersMark')
-    map("inv", "ml", '<Plug>MarkersCloseAllAndJumpToLast')
-    map("inv", "mo", '<Plug>MarkersJumpOutside')
+    arpeggio.chord("inv", "sj", '<Plug>MarkersJumpF')
+    arpeggio.chord("inv", "sk", '<Plug>MarkersJumpB')
+    arpeggio.chord("inv", "mi", '<Plug>MarkersMark')
+    arpeggio.chord("inv", "ml", '<Plug>MarkersCloseAllAndJumpToLast')
+    arpeggio.chord("inv", "mo", '<Plug>MarkersJumpOutside')
 
     for key, brackets in pairs(extraBrackets) do
         for _, v in ipairs(brackets) do
             A.augroup('custom-brackets' .. key, function()
                 local action = M.createBracketCommand(v[1], v[2], 0, v[3] or "")
-                A.autocmd('BufEnter', '*.' .. key, action)
+                local glob = '*.' .. key
+
+                if key == "all" then
+                    -- The all key just matches everything
+                    glob = "*"
+                end
+
+                A.autocmd('BufEnter', glob, action)
             end)
         end
     end
diff --git a/dotfiles/neovim/lua/my/plugins/telescope.lua b/dotfiles/neovim/lua/my/plugins/telescope.lua
index c31326d..155bdaf 100644
--- a/dotfiles/neovim/lua/my/plugins/telescope.lua
+++ b/dotfiles/neovim/lua/my/plugins/telescope.lua
@@ -12,21 +12,21 @@ local bindings = {
         live_grep = "<c-F>",
 
         -- See diagnostics with space + d
-        lsp_document_diagnostics = "<space>d",
-        lsp_workspace_diagnostics = "<space>wd",
-        lsp_code_actions = "<space>ca",
+        lsp_document_diagnostics = "<Leader>d",
+        lsp_workspace_diagnostics = "<Leader>wd",
+        lsp_code_actions = "<Leader>ca",
 
         -- Open a list with all the pickers
-        builtin = "<space>t",
+        builtin = "<Leader>t",
 
         -- List function, var names etc
-        treesitter = "<space>s",
+        treesitter = "<Leader>s",
 
         -- Git stuff
-        git_commits = "<space>gj",
-        git_branches = "<space>gk"
+        git_commits = "<Leader>gj",
+        git_branches = "<Leader>gk"
     },
-    ["extensions.file_browser.file_browser"] = "<space>p",
+    ["extensions.file_browser.file_browser"] = "<Leader>p",
     extensions = {
         unicode = {picker = {mode = "i", kind = "dropdown", key = "uu"}}
     }