2022-03-09 19:03:04 +01:00
|
|
|
local helpers = require("my.helpers")
|
2022-04-04 01:10:26 +02:00
|
|
|
local arpeggio = require("my.plugins.arpeggio")
|
2022-03-09 19:03:04 +01:00
|
|
|
|
2022-01-30 19:10:57 +01:00
|
|
|
local M = {}
|
|
|
|
|
2022-08-24 13:29:04 +02:00
|
|
|
local function map(mode, lhs, rhs, opts)
|
2022-07-19 20:19:36 +02:00
|
|
|
if string.len(mode) > 1 then
|
|
|
|
for i = 1, #mode do
|
|
|
|
local c = mode:sub(i, i)
|
2022-08-24 13:29:04 +02:00
|
|
|
map(c, lhs, rhs, opts)
|
2022-04-04 01:10:26 +02:00
|
|
|
end
|
2022-07-19 20:19:36 +02:00
|
|
|
else
|
|
|
|
local options = helpers.mergeTables(opts, { noremap = true })
|
|
|
|
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
|
|
|
|
end
|
2022-01-30 19:10:57 +01:00
|
|
|
end
|
|
|
|
|
2022-01-31 21:54:22 +01:00
|
|
|
function M.mapSilent(mode, lhs, rhs, opts)
|
2022-07-19 20:19:36 +02:00
|
|
|
local options = helpers.mergeTables(opts, { silent = true })
|
2022-08-24 13:29:04 +02:00
|
|
|
map(mode, lhs, rhs, options)
|
2022-01-31 21:54:22 +01:00
|
|
|
end
|
|
|
|
|
2022-09-12 13:50:02 +02:00
|
|
|
-- Performs a basic move operation
|
2022-10-09 03:28:51 +02:00
|
|
|
function M.move(from, to, opts)
|
|
|
|
vim.keymap.set("n", to, from, opts)
|
2022-09-12 13:50:02 +02:00
|
|
|
vim.keymap.set("n", from, "<Nop>")
|
|
|
|
end
|
|
|
|
|
2022-10-13 01:05:38 +02:00
|
|
|
function M.delimitedTextobject(from, to, name, perhapsOpts)
|
|
|
|
local opts = helpers.mergeTables(perhapsOpts or {}, { desc = name })
|
|
|
|
|
|
|
|
vim.keymap.set({ "v", "o" }, "i" .. from, "i" .. to, opts)
|
|
|
|
vim.keymap.set({ "v", "o" }, "a" .. from, "a" .. to, opts)
|
|
|
|
end
|
|
|
|
|
2022-01-30 19:10:57 +01:00
|
|
|
function M.setup()
|
2022-12-09 02:32:25 +01:00
|
|
|
-- I rarely use macro stuff
|
2022-10-09 03:28:51 +02:00
|
|
|
M.move("q", "yq", { desc = "Record macro" })
|
2022-09-12 13:50:02 +02:00
|
|
|
M.move("Q", "yQ")
|
2022-12-09 02:32:25 +01:00
|
|
|
|
|
|
|
-- Free these up for easymotion-style plugins
|
|
|
|
-- vim.keymap.set("n", "s", "<Nop>")
|
|
|
|
-- vim.keymap.set("n", "S", "<Nop>")
|
|
|
|
|
2022-10-09 03:28:51 +02:00
|
|
|
M.move("<C-^>", "<Leader>a", { desc = "Go to previous file" })
|
2022-09-12 13:50:02 +02:00
|
|
|
|
2022-12-09 02:32:25 +01:00
|
|
|
vim.keymap.set({ "n", "v" }, "<leader>q", function()
|
2022-10-14 13:44:47 +02:00
|
|
|
local buf = vim.api.nvim_win_get_buf(0)
|
|
|
|
|
|
|
|
-- Only save if file is writable
|
2022-12-09 02:32:25 +01:00
|
|
|
if vim.bo[buf].modifiable and not vim.bo[buf].readonly then vim.cmd [[write]] end
|
2022-10-14 13:44:47 +02:00
|
|
|
|
|
|
|
vim.cmd "q"
|
|
|
|
end, { desc = "Quit current buffer" })
|
|
|
|
|
2022-10-09 03:28:51 +02:00
|
|
|
vim.keymap.set("n", "Q", ":wqa<cr>", { desc = "Save all files and quit" })
|
2022-12-09 02:32:25 +01:00
|
|
|
vim.keymap.set("n", "<leader>rw", ":%s/<C-r><C-w>/", { desc = "Replace word in file" })
|
2022-04-04 01:10:26 +02:00
|
|
|
|
2022-10-13 01:05:38 +02:00
|
|
|
M.delimitedTextobject("q", '"', "quotes")
|
|
|
|
M.delimitedTextobject("a", "'", "'")
|
|
|
|
M.delimitedTextobject("r", "[", "square brackets")
|
|
|
|
|
2022-07-19 20:19:36 +02:00
|
|
|
-- Create chords
|
|
|
|
if arpeggio ~= nil then
|
2022-10-09 03:28:51 +02:00
|
|
|
arpeggio.chordSilent("n", "ji", ":silent :write<cr>") -- Saving
|
2022-07-19 20:19:36 +02:00
|
|
|
arpeggio.chord("i", "jk", "<Esc>") -- Remap Esc to jk
|
|
|
|
arpeggio.chord("nv", "cp", "\"+") -- Press cp to use the global clipboard
|
2022-10-09 03:28:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local status, wk = pcall(require, "which-key")
|
|
|
|
|
|
|
|
if status then
|
|
|
|
wk.register({
|
|
|
|
["<leader>"] = {
|
2022-12-09 02:32:25 +01:00
|
|
|
f = { name = "Files" },
|
|
|
|
g = { name = "Go to" },
|
|
|
|
r = { name = "Rename / Replace / Reload" },
|
|
|
|
l = { name = "Local" },
|
2022-10-09 03:28:51 +02:00
|
|
|
v = "which_key_ignore"
|
|
|
|
}
|
|
|
|
})
|
2022-07-19 20:19:36 +02:00
|
|
|
end
|
2022-05-10 14:28:36 +02:00
|
|
|
|
2022-07-19 20:19:36 +02:00
|
|
|
return M
|
2022-01-30 20:19:35 +01:00
|
|
|
end
|
|
|
|
|
2022-02-01 00:06:48 +01:00
|
|
|
return M
|