1 | | - | local utils = require "user.utils" |
2 | | - | local astro_utils = require "astronvim.utils" |
3 | | - | local mappings = { |
4 | | - | n = { |
5 | | - | -- disable default bindings |
6 | | - | ["<C-Down>"] = false, |
7 | | - | ["<C-Left>"] = false, |
8 | | - | ["<C-Right>"] = false, |
9 | | - | ["<C-Up>"] = false, |
10 | | - | ["<C-q>"] = false, |
11 | | - | ["<C-s>"] = false, |
12 | | - | ["q:"] = ":", |
13 | | - | -- better buffer navigation |
14 | | - | ["]b"] = false, |
15 | | - | ["[b"] = false, |
16 | | - | ["<S-l>"] = { |
17 | | - | function() require("astronvim.utils.buffer").nav(vim.v.count > 0 and vim.v.count or 1) end, |
18 | | - | desc = "Next buffer", |
19 | | - | }, |
20 | | - | ["<S-h>"] = { |
21 | | - | function() require("astronvim.utils.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1)) end, |
22 | | - | desc = "Previous buffer", |
23 | | - | }, |
24 | | - | -- better search |
25 | | - | n = { utils.better_search "n", desc = "Next search" }, |
26 | | - | N = { utils.better_search "N", desc = "Previous search" }, |
27 | | - | -- better increment/decrement |
28 | | - | ["-"] = { "<c-x>", desc = "Descrement number" }, |
29 | | - | ["+"] = { "<c-a>", desc = "Increment number" }, |
30 | | - | -- resize with arrows |
31 | | - | ["<Up>"] = { function() require("smart-splits").resize_up(2) end, desc = "Resize split up" }, |
32 | | - | ["<Down>"] = { function() require("smart-splits").resize_down(2) end, desc = "Resize split down" }, |
33 | | - | ["<Left>"] = { function() require("smart-splits").resize_left(2) end, desc = "Resize split left" }, |
34 | | - | ["<Right>"] = { function() require("smart-splits").resize_right(2) end, desc = "Resize split right" }, |
35 | | - | -- Easy-Align |
36 | | - | ga = { "<Plug>(EasyAlign)", desc = "Easy Align" }, |
37 | | - | -- buffer switching |
38 | | - | ["<Tab>"] = { |
39 | | - | function() |
40 | | - | if #vim.t.bufs > 1 then |
41 | | - | require("telescope.builtin").buffers { sort_mru = true, ignore_current_buffer = true } |
42 | | - | else |
43 | | - | astro_utils.notify "No other buffers open" |
44 | | - | end |
45 | | - | end, |
46 | | - | desc = "Switch Buffers", |
47 | | - | }, |
48 | | - | ["<leader>n"] = { "<cmd>enew<cr>", desc = "New File" }, |
49 | | - | ["<leader>N"] = { "<cmd>tabnew<cr>", desc = "New Tab" }, |
50 | | - | ["<leader><cr>"] = { '<esc>/<++><cr>"_c4l', desc = "Next Template" }, |
51 | | - | ["<leader>."] = { "<cmd>cd %:p:h<cr>", desc = "Set CWD" }, |
52 | | - | -- neogen |
53 | | - | ["<leader>a"] = { desc = " Annotate" }, |
54 | | - | ["<leader>a<cr>"] = { function() require("neogen").generate() end, desc = "Current" }, |
55 | | - | ["<leader>ac"] = { function() require("neogen").generate { type = "class" } end, desc = "Class" }, |
56 | | - | ["<leader>af"] = { function() require("neogen").generate { type = "func" } end, desc = "Function" }, |
57 | | - | ["<leader>at"] = { function() require("neogen").generate { type = "type" } end, desc = "Type" }, |
58 | | - | ["<leader>aF"] = { function() require("neogen").generate { type = "file" } end, desc = "File" }, |
59 | | - | -- telescope plugin mappings |
60 | | - | ["<leader>fx"] = { |
61 | | - | function() require("telescope").extensions.live_grep_args.live_grep_args() end, |
62 | | - | desc = "Find words (args)", |
63 | | - | }, |
64 | | - | ["<leader>fB"] = { "<cmd>Telescope bibtex<cr>", desc = "Find BibTeX" }, |
65 | | - | ["<leader>fe"] = { "<cmd>Telescope file_browser<cr>", desc = "File explorer" }, |
66 | | - | ["<leader>fp"] = { function() require("telescope").extensions.projects.projects {} end, desc = "Find projects" }, |
67 | | - | ["<leader>fT"] = { "<cmd>TodoTelescope<cr>", desc = "Find TODOs" }, |
68 | | - | -- neogit |
69 | | - | ["<leader>gG"] = { function() require("neogit").open() end, desc = "Neogit" }, |
70 | | - | -- compiler |
71 | | - | ["<leader>m"] = { desc = " Compiler" }, |
72 | | - | ["<leader>mk"] = { |
73 | | - | function() |
74 | | - | vim.cmd "silent! write" |
75 | | - | local filename = vim.fn.expand "%:t" |
76 | | - | utils.async_run({ "compiler", vim.fn.expand "%:p" }, function() astro_utils.notify("Compiled " .. filename) end) |
77 | | - | end, |
78 | | - | desc = "Compile", |
79 | | - | }, |
80 | | - | ["<leader>ma"] = { |
81 | | - | function() |
82 | | - | vim.notify "Autocompile Started" |
83 | | - | utils.async_run({ "autocomp", vim.fn.expand "%:p" }, function() astro_utils.notify "Autocompile stopped" end) |
84 | | - | end, |
85 | | - | desc = "Auto Compile", |
86 | | - | }, |
87 | | - | ["<leader>mv"] = { |
88 | | - | function() vim.fn.jobstart { "opout", vim.fn.expand "%:p" } end, |
89 | | - | desc = "View Output", |
90 | | - | }, |
91 | | - | ["<leader>mb"] = { |
92 | | - | function() |
93 | | - | local filename = vim.fn.expand "%:t" |
94 | | - | utils.async_run({ |
95 | | - | "pandoc", |
96 | | - | vim.fn.expand "%", |
97 | | - | "--pdf-engine=xelatex", |
98 | | - | "--variable", |
99 | | - | "urlcolor=blue", |
100 | | - | "-t", |
101 | | - | "beamer", |
102 | | - | "-o", |
103 | | - | vim.fn.expand "%:r" .. ".pdf", |
104 | | - | }, function() astro_utils.notify("Compiled " .. filename) end) |
105 | | - | end, |
106 | | - | desc = "Compile Beamer", |
107 | | - | }, |
108 | | - | ["<leader>mp"] = { |
109 | | - | function() |
110 | | - | local pdf_path = vim.fn.expand "%:r" .. ".pdf" |
111 | | - | if vim.fn.filereadable(pdf_path) == 1 then vim.fn.jobstart { "pdfpc", pdf_path } end |
112 | | - | end, |
113 | | - | desc = "Present Output", |
114 | | - | }, |
115 | | - | ["<leader>ml"] = { function() utils.toggle_qf() end, desc = "Logs" }, |
116 | | - | ["<leader>mt"] = { "<cmd>TexlabBuild<cr>", desc = "LaTeX" }, |
117 | | - | ["<leader>mf"] = { "<cmd>TexlabForward<cr>", desc = "Forward Search" }, |
118 | | - | ["<leader>r"] = { desc = " REPL" }, |
119 | | - | ["<leader>rr"] = { "<Plug>Send", desc = "Send to REPL" }, |
120 | | - | ["<leader>rl"] = { "<Plug>SendLine", desc = "Send line to REPL" }, |
121 | | - | ["<leader>r<cr>"] = { "<cmd>SendHere<cr>", desc = "Set REPL" }, |
122 | | - | ["<leader>z"] = { "<cmd>ZenMode<cr>", desc = "Zen Mode" }, |
123 | | - | ["<leader>s"] = { desc = " Search/Replace" }, |
124 | | - | ["<leader>ss"] = { function() require("spectre").toggle() end, desc = "Toggle Spectre" }, |
125 | | - | ["<leader>sf"] = { function() require("spectre").open_file_search() end, desc = "Spectre (current file)" }, |
126 | | - | ["<leader>sw"] = { |
127 | | - | function() require("spectre").open_visual { select_word = true } end, |
128 | | - | desc = "Spectre (current word)", |
129 | | - | }, |
130 | | - | ["<leader>x"] = { desc = " Trouble" }, |
131 | | - | ["<leader>xx"] = { "<cmd>TroubleToggle document_diagnostics<cr>", desc = "Document Diagnostics (Trouble)" }, |
132 | | - | ["<leader>xX"] = { "<cmd>TroubleToggle workspace_diagnostics<cr>", desc = "Workspace Diagnostics (Trouble)" }, |
133 | | - | ["<leader>xl"] = { "<cmd>TroubleToggle loclist<cr>", desc = "Location List (Trouble)" }, |
134 | | - | ["<leader>xq"] = { "<cmd>TroubleToggle quickfix<cr>", desc = "Quickfix List (Trouble)" }, |
135 | | - | ["<leader>xT"] = { "<cmd>TodoTrouble<cr>", desc = "TODOs (Trouble)" }, |
136 | | - | }, |
137 | | - | v = { |
138 | | - | ["<leader>r"] = { "<Plug>Send", desc = "Send to REPL" }, |
139 | | - | ["<leader>s"] = { function() require("spectre").open_visual() end, desc = "Spectre" }, |
140 | | - | }, |
141 | | - | i = { |
142 | | - | -- signature help, fails silently so attach always |
143 | | - | ["<C-l>"] = { function() vim.lsp.buf.signature_help() end, desc = "Signature help" }, |
144 | | - | ["<S-Tab>"] = { "<C-V><Tab>", desc = "Tab character" }, |
145 | | - | }, |
146 | | - | -- terminal mappings |
147 | | - | t = { |
148 | | - | ["<C-BS>"] = { "<C-\\><C-n>", desc = "Terminal normal mode" }, |
149 | | - | ["<esc><esc>"] = { "<C-\\><C-n>:q<cr>", desc = "Terminal quit" }, |
150 | | - | }, |
151 | | - | x = { |
152 | | - | -- better increment/decrement |
153 | | - | ["+"] = { "g<C-a>", desc = "Increment number" }, |
154 | | - | ["-"] = { "g<C-x>", desc = "Descrement number" }, |
155 | | - | -- Easy-Align |
156 | | - | ga = { "<Plug>(EasyAlign)", desc = "Easy Align" }, |
157 | | - | }, |
158 | | - | o = { |
159 | | - | -- line text-objects |
160 | | - | ["il"] = { ":normal vil<cr>", desc = "Inside line text object" }, |
161 | | - | ["al"] = { ":normal val<cr>", desc = "Around line text object" }, |
162 | | - | }, |
163 | | - | ia = vim.fn.has "nvim-0.10" == 1 and { |
164 | | - | mktemp = { function() return "<++>" end, desc = "Insert <++>", expr = true }, |
165 | | - | ldate = { function() return os.date "%Y/%m/%d %H:%M:%S -" end, desc = "Y/m/d H:M:S -", expr = true }, |
166 | | - | ndate = { function() return os.date "%Y-%m-%d" end, desc = "Y-m-d", expr = true }, |
167 | | - | xdate = { function() return os.date "%m/%d/%y" end, desc = "m/d/y", expr = true }, |
168 | | - | fdate = { function() return os.date "%B %d, %Y" end, desc = "B d, Y", expr = true }, |
169 | | - | Xdate = { function() return os.date "%H:%M" end, desc = "H:M", expr = true }, |
170 | | - | Fdate = { function() return os.date "%H:%M:%S" end, desc = "H:M:S", expr = true }, |
171 | | - | } or nil, |
172 | | - | } |
173 | | - | |
174 | | - | return mappings |
175 | | - | |