| 1 | + | ---@type AstroCoreOpts |
| 2 | + | local opts = { |
| 3 | + | autocmds = { |
| 4 | + | auto_spell = { |
| 5 | + | { |
| 6 | + | event = "FileType", |
| 7 | + | desc = "Enable wrap and spell for text like documents", |
| 8 | + | pattern = { "gitcommit", "markdown", "text", "plaintex" }, |
| 9 | + | callback = function() |
| 10 | + | vim.opt_local.wrap = true |
| 11 | + | vim.opt_local.spell = true |
| 12 | + | end, |
| 13 | + | }, |
| 14 | + | }, |
| 15 | + | autohide_tabline = { |
| 16 | + | { |
| 17 | + | event = "User", |
| 18 | + | desc = "Auto hide tabline", |
| 19 | + | pattern = "AstroBufsUpdated", |
| 20 | + | callback = function() |
| 21 | + | local new_showtabline = #vim.t.bufs > 1 and 2 or 1 |
| 22 | + | if new_showtabline ~= vim.opt.showtabline:get() then vim.opt.showtabline = new_showtabline end |
| 23 | + | end, |
| 24 | + | }, |
| 25 | + | }, |
| 26 | + | }, |
| 27 | + | mappings = { |
| 28 | + | n = { |
| 29 | + | -- disable default bindings |
| 30 | + | ["<C-q>"] = false, |
| 31 | + | ["<C-s>"] = false, |
| 32 | + | ["q:"] = ":", |
| 33 | + | -- better buffer navigation |
| 34 | + | ["]b"] = false, |
| 35 | + | ["[b"] = false, |
| 36 | + | ["<S-l>"] = { |
| 37 | + | function() require("astrocore.buffer").nav(vim.v.count > 0 and vim.v.count or 1) end, |
| 38 | + | desc = "Next buffer", |
| 39 | + | }, |
| 40 | + | ["<S-h>"] = { |
| 41 | + | function() require("astrocore.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1)) end, |
| 42 | + | desc = "Previous buffer", |
| 43 | + | }, |
| 44 | + | -- better search |
| 45 | + | -- better increment/decrement |
| 46 | + | ["-"] = { "<C-x>", desc = "Descrement number" }, |
| 47 | + | ["+"] = { "<C-a>", desc = "Increment number" }, |
| 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 | + | }, |
| 53 | + | i = { |
| 54 | + | ["<S-Tab>"] = { "<C-V><Tab>", desc = "Tab character" }, |
| 55 | + | }, |
| 56 | + | -- terminal mappings |
| 57 | + | t = { |
| 58 | + | ["<C-BS>"] = { "<C-\\><C-n>", desc = "Terminal normal mode" }, |
| 59 | + | ["<Esc><Esc>"] = { "<C-\\><C-n>:q<CR>", desc = "Terminal quit" }, |
| 60 | + | }, |
| 61 | + | x = { |
| 62 | + | -- better increment/decrement |
| 63 | + | ["+"] = { "g<C-a>", desc = "Increment number" }, |
| 64 | + | ["-"] = { "g<C-x>", desc = "Descrement number" }, |
| 65 | + | -- line text-objects |
| 66 | + | ["iL"] = { ":<C-u>normal! $v^<CR>", desc = "Inside line text object" }, |
| 67 | + | ["aL"] = { ":<C-u>normal! $v0<CR>", desc = "Around line text object" }, |
| 68 | + | }, |
| 69 | + | o = { |
| 70 | + | -- line text-objects |
| 71 | + | ["iL"] = { ":<C-u>normal! $v^<CR>", desc = "Inside line text object" }, |
| 72 | + | ["aL"] = { ":<C-u>normal! $v0<CR>", desc = "Around line text object" }, |
| 73 | + | }, |
| 74 | + | ia = vim.fn.has "nvim-0.10" == 1 and { |
| 75 | + | mktemp = { function() return "<++>" end, desc = "Insert <++>", expr = true }, |
| 76 | + | ldate = { function() return os.date "%Y/%m/%d %H:%M:%S -" end, desc = "Y/m/d H:M:S -", expr = true }, |
| 77 | + | ndate = { function() return os.date "%Y-%m-%d" end, desc = "Y-m-d", expr = true }, |
| 78 | + | xdate = { function() return os.date "%m/%d/%y" end, desc = "m/d/y", expr = true }, |
| 79 | + | fdate = { function() return os.date "%B %d, %Y" end, desc = "B d, Y", expr = true }, |
| 80 | + | Xdate = { function() return os.date "%H:%M" end, desc = "H:M", expr = true }, |
| 81 | + | Fdate = { function() return os.date "%H:%M:%S" end, desc = "H:M:S", expr = true }, |
| 82 | + | } or nil, |
| 83 | + | }, |
| 84 | + | } |
| 85 | + | |
1 | 86 | | local function better_search(key) |
2 | 87 | | return function() |
3 | 88 | | local searched, error = |
| skipped 1 lines |
5 | 90 | | if not searched and type(error) == "string" then require("astrocore").notify(error, vim.log.levels.ERROR) end |
6 | 91 | | end |
7 | 92 | | end |
| 93 | + | opts.mappings.n.n = { better_search "n", desc = "Next search" } |
| 94 | + | opts.mappings.n.N = { better_search "N", desc = "Previous search" } |
8 | 95 | | |
9 | | - | return { |
10 | | - | "AstroNvim/astrocore", |
11 | | - | ---@type AstroCoreOpts |
12 | | - | opts = { |
13 | | - | autocmds = { |
14 | | - | auto_spell = { |
15 | | - | { |
16 | | - | event = "FileType", |
17 | | - | desc = "Enable wrap and spell for text like documents", |
18 | | - | pattern = { "gitcommit", "markdown", "text", "plaintex" }, |
19 | | - | callback = function() |
20 | | - | vim.opt_local.wrap = true |
21 | | - | vim.opt_local.spell = true |
22 | | - | end, |
23 | | - | }, |
24 | | - | }, |
25 | | - | autohide_tabline = { |
26 | | - | { |
27 | | - | event = "User", |
28 | | - | desc = "Auto hide tabline", |
29 | | - | pattern = "AstroBufsUpdated", |
30 | | - | callback = function() |
31 | | - | local new_showtabline = #vim.t.bufs > 1 and 2 or 1 |
32 | | - | if new_showtabline ~= vim.opt.showtabline:get() then vim.opt.showtabline = new_showtabline end |
33 | | - | end, |
34 | | - | }, |
35 | | - | }, |
| 96 | + | -- add missing in between and arround two character pairs |
| 97 | + | for _, char in ipairs { "_", ".", ":", ",", ";", "|", "/", "\\", "*", "+", "%", "`", "?" } do |
| 98 | + | local char_map = { |
| 99 | + | i = { |
| 100 | + | lhs = "i" .. char, |
| 101 | + | rhs = { (":<C-u>silent! normal! f%sF%slvt%s<CR>"):format(char, char, char), desc = "inside " .. char }, |
36 | 102 | | }, |
37 | | - | mappings = { |
38 | | - | n = { |
39 | | - | -- disable default bindings |
40 | | - | ["<C-q>"] = false, |
41 | | - | ["<C-s>"] = false, |
42 | | - | ["q:"] = ":", |
43 | | - | -- better buffer navigation |
44 | | - | ["]b"] = false, |
45 | | - | ["[b"] = false, |
46 | | - | ["<S-l>"] = { |
47 | | - | function() require("astrocore.buffer").nav(vim.v.count > 0 and vim.v.count or 1) end, |
48 | | - | desc = "Next buffer", |
49 | | - | }, |
50 | | - | ["<S-h>"] = { |
51 | | - | function() require("astrocore.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1)) end, |
52 | | - | desc = "Previous buffer", |
53 | | - | }, |
54 | | - | -- better search |
55 | | - | n = { better_search "n", desc = "Next search" }, |
56 | | - | N = { better_search "N", desc = "Previous search" }, |
57 | | - | -- better increment/decrement |
58 | | - | ["-"] = { "<C-x>", desc = "Descrement number" }, |
59 | | - | ["+"] = { "<C-a>", desc = "Increment number" }, |
60 | | - | ["<Leader>n"] = { "<Cmd>enew<CR>", desc = "New File" }, |
61 | | - | ["<Leader>N"] = { "<Cmd>tabnew<CR>", desc = "New Tab" }, |
62 | | - | ["<Leader><CR>"] = { '<Esc>/<++><CR>"_c4l', desc = "Next Template" }, |
63 | | - | ["<Leader>."] = { "<Cmd>cd %:p:h<CR>", desc = "Set CWD" }, |
64 | | - | }, |
65 | | - | i = { |
66 | | - | ["<S-Tab>"] = { "<C-V><Tab>", desc = "Tab character" }, |
67 | | - | }, |
68 | | - | -- terminal mappings |
69 | | - | t = { |
70 | | - | ["<C-BS>"] = { "<C-\\><C-n>", desc = "Terminal normal mode" }, |
71 | | - | ["<Esc><Esc>"] = { "<C-\\><C-n>:q<CR>", desc = "Terminal quit" }, |
72 | | - | }, |
73 | | - | x = { |
74 | | - | -- better increment/decrement |
75 | | - | ["+"] = { "g<C-a>", desc = "Increment number" }, |
76 | | - | ["-"] = { "g<C-x>", desc = "Descrement number" }, |
77 | | - | }, |
78 | | - | o = { |
79 | | - | -- line text-objects |
80 | | - | ["il"] = { ":normal vil<CR>", desc = "Inside line text object" }, |
81 | | - | ["al"] = { ":normal val<CR>", desc = "Around line text object" }, |
82 | | - | }, |
83 | | - | ia = vim.fn.has "nvim-0.10" == 1 and { |
84 | | - | mktemp = { function() return "<++>" end, desc = "Insert <++>", expr = true }, |
85 | | - | ldate = { function() return os.date "%Y/%m/%d %H:%M:%S -" end, desc = "Y/m/d H:M:S -", expr = true }, |
86 | | - | ndate = { function() return os.date "%Y-%m-%d" end, desc = "Y-m-d", expr = true }, |
87 | | - | xdate = { function() return os.date "%m/%d/%y" end, desc = "m/d/y", expr = true }, |
88 | | - | fdate = { function() return os.date "%B %d, %Y" end, desc = "B d, Y", expr = true }, |
89 | | - | Xdate = { function() return os.date "%H:%M" end, desc = "H:M", expr = true }, |
90 | | - | Fdate = { function() return os.date "%H:%M:%S" end, desc = "H:M:S", expr = true }, |
91 | | - | } or nil, |
| 103 | + | a = { |
| 104 | + | lhs = "a" .. char, |
| 105 | + | rhs = { (":<C-u>silent! normal! f%sF%svf%s<CR>"):format(char, char, char), desc = "around " .. char }, |
92 | 106 | | }, |
93 | | - | }, |
94 | | - | } |
| 107 | + | } |
| 108 | + | for _, mode in ipairs { "x", "o" } do |
| 109 | + | opts.mappings[mode][char_map.i.lhs] = char_map.i.rhs |
| 110 | + | opts.mappings[mode][char_map.a.lhs] = char_map.a.rhs |
| 111 | + | end |
| 112 | + | end |
| 113 | + | |
| 114 | + | return { "AstroNvim/astrocore", opts = opts } |
95 | 115 | | |