1
Fork 0

Started rewriting my neovim config

This commit is contained in:
Matei Adriel 2022-12-27 14:02:03 +01:00
parent 686bdd12c4
commit 47d704ad01
17 changed files with 181 additions and 122 deletions

View file

@ -1,13 +1,20 @@
local arpeggio = require("my.plugins.arpeggio")
local A = require("my.abbreviations")
-- Use vt to test
arpeggio.chordSilent("n", "vt", ":VimuxRunCommand \"clear && spago test\"<CR>",
{ settings = "b" })
vim.keymap.set(
"n",
"<leader>vt",
':VimuxRunCommand "clear && spago test"<CR>',
{ desc = "[V]imtex run [t]ests", buffer = true }
)
-- Use vb to build
arpeggio.chordSilent("n", "vb", ":VimuxRunCommand \"clear && spago build\"<CR>",
{ settings = "b" })
vim.keymap.set(
"n",
"<leader>vb",
':VimuxRunCommand "clear && spago build"<CR>',
{ desc = "[V]imtex [b]uild", buffer = true }
)
vim.opt.expandtab = true -- Use spaces for the tab char
@ -17,7 +24,7 @@ local abbreviations = {
{ "tto", "->" },
{ "iip", "=>" },
{ "frl", "forall" },
{ "ott", "<-" } -- opposite of tto
{ "ott", "<-" }, -- opposite of tto
}
A.manyLocalAbbr(abbreviations)

View file

@ -1,2 +1,9 @@
-- vim.opt.runtimepath:prepend(os.getenv("LAZY_NVIM_PATH"))
local lazy_path = os.getenv("LAZY_NVIM_PATH")
if lazy_path == nil then
error("Lazy.nvim not installed!")
end
vim.opt.runtimepath:prepend(lazy_path)
require("my.init").setup()

View file

@ -1,9 +0,0 @@
local M = {}
function M.update()
require("my.helpers").saveCursor(function()
vim.cmd(":%!update-nix-fetchgit")
end)
end
return M

View file

@ -2,13 +2,8 @@ local M = {}
function M.setup()
-- Import my other files
require("impatient") -- should make startups take less
require("my.paq").setup()
require("my.theme").setup()
require("my.options").setup()
require('my.keymaps').setup()
require('my.plugins').setup()
-- require("telescope.extensions.unicode").setupAbbreviations()
end
return M

View file

@ -1,21 +1,43 @@
local helpers = require("my.helpers")
local arpeggio = require("my.plugins.arpeggio")
local M = {}
-- {{{ Helpers
-- Performs a basic move operation
---Performs a basic move operation
---Moves a keybind to a different set of keys.
---Useful for moving built in keybinds out of the way.
---@param from string
---@param to string
---@param opts table|nil
function M.move(from, to, opts)
vim.keymap.set("n", to, from, opts)
vim.keymap.set("n", from, "<Nop>")
end
---Create a textobject defined by some delimiters
---@param from string
---@param to string
---@param name string
---@param perhapsOpts table|nil
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
---Helper to create a normal mode mapping and give it some description.
---@param from string
---@param to string|function
---@param desc string
---@param silent boolean|nil
function M.nmap(from, to, desc, silent)
if silent == nil then
silent = true
end
vim.keymap.set("n", from, to, { desc = desc })
end
-- }}}
function M.setup()
@ -23,47 +45,38 @@ function M.setup()
M.move("q", "yq", { desc = "Record macro" })
M.move("Q", "yQ")
-- }}}
-- {{{ Easier access to C^
M.move("<C-^>", "<Leader>a", { desc = "Go to previous file" })
-- {{{ Easier access to <C-^>
M.move("<C-^>", "<Leader>a", { desc = "[A]lternate file" })
-- }}}
-- {{{ Quit current buffer / all buffers
vim.keymap.set({ "n", "v" }, "<leader>q", function()
local buf = vim.api.nvim_win_get_buf(0)
-- Only save if file is writable
if vim.bo[buf].modifiable and not vim.bo[buf].readonly then vim.cmd [[write]] end
if vim.bo[buf].modifiable and not vim.bo[buf].readonly then
vim.cmd([[write]])
end
vim.cmd "q"
end, { desc = "Quit current buffer" })
vim.cmd("q")
end, { desc = "[q]uit current buffer" })
vim.keymap.set("n", "Q", ":wqa<cr>", { desc = "Save all files and quit" })
M.nmap("Q", ":wqa<cr>", "Save all files and [q]uit")
-- }}}
-- {{{ Replace word in file
vim.keymap.set("n", "<leader>rw", ":%s/<C-r><C-w>/", { desc = "Replace word in file" })
M.nmap("<leader>rw", ":%s/<C-r><C-w>/", "[R]eplace [w]ord in file")
-- }}}
-- {{{ Text objects
M.delimitedTextobject("q", '"', "quotes")
M.delimitedTextobject("a", "'", "'")
M.delimitedTextobject("r", "[", "square brackets")
M.delimitedTextobject("q", '"', "[q]uotes")
M.delimitedTextobject("a", "'", "[a]postrophes")
M.delimitedTextobject("r", "[", "squa[r]e brackets")
-- }}}
-- {{{Diagnostic keymaps
do
local opts = function(desc)
return { noremap = true, silent = true, desc = desc }
end
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts("Goto previous diagnostic"))
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts("Goto next diagnostic"))
vim.keymap.set('n', 'J', vim.diagnostic.open_float, opts("Open current diagnostic"))
vim.keymap.set('n', '<leader>J', vim.diagnostic.setloclist, opts("Set diagnostics loclist"))
end
M.nmap("[d", vim.diagnostic.goto_prev, "Goto previous [d]iagnostic")
M.nmap("]d", vim.diagnostic.goto_next, "Goto next [d]iagnostic")
M.nmap("J", vim.diagnostic.open_float, "Open current diagnostic")
M.nmap("<leader>D", vim.diagnostic.setloclist, "[S]iagnostic loclist")
-- }}}
-- {{{ Chords
if arpeggio ~= nil then
arpeggio.chordSilent("n", "ji", ":silent :write<cr>") -- Saving
arpeggio.chord("i", "jk", "<Esc>") -- Remap Esc to jk
arpeggio.chord("nv", "cp", "\"+") -- Press cp to use the global clipboard
end
-- {{{ Chords (exit insert mode, save, clipboard)
-- }}}
-- {{{ Set up which-key structure
local status, wk = pcall(require, "which-key")
@ -71,16 +84,31 @@ function M.setup()
if status then
wk.register({
["<leader>"] = {
f = { name = "Files" },
g = { name = "Go to" },
r = { name = "Rename / Replace / Reload" },
l = { name = "Local" },
v = "which_key_ignore"
}
f = { name = "[F]iles" },
g = { name = "[G]o to" },
r = { name = "[R]ename / [R]eplace / [R]eload" },
l = { name = "[L]ocal" },
w = { name = "[W]orkspace" },
v = "which_key_ignore",
},
})
end
-- }}}
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = {
"help",
"man",
"notify",
"lspinfo"
},
callback = function(event)
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true, desc = "[q]uit current buffer" })
end,
})
return M
end

View file

@ -1,5 +1,3 @@
local helpers = require("my.helpers")
local M = {}
function M.setup()
@ -39,8 +37,8 @@ function M.setup()
-- Set leader
vim.g.mapleader = " "
-- Import other options
require("my.options.folding").setup()
-- Folding
vim.o.foldmethod = "marker"
end
return M

View file

@ -1,7 +0,0 @@
local M = {}
function M.setup()
vim.o.foldmethod = "marker"
end
return M

View file

@ -5,6 +5,7 @@ function M.setup()
local themePackages = require("my.theme").deps
local base = {
"nvim-lua/plenary.nvim", -- async utility lib it seems?
--------------------------------- Unuported
"folke/neoconf.nvim", -- per project neovim configuration
"neovim/nvim-lspconfig", -- configures lsps for me
"folke/neodev.nvim", -- lua support

View file

@ -3,25 +3,43 @@ local arpeggio = vim.fn["arpeggio#map"]
local M = {}
function M.chord(mode, lhs, rhs, opts)
---Create an arpeggio mapping
---@param mode string
---@param lhs string
---@param rhs string
---@param opts table|nil
local function chord(mode, lhs, rhs, opts)
if string.len(mode) > 1 then
for i = 1, #mode do
local c = mode:sub(i, i)
M.chord(c, lhs, rhs, opts)
chord(c, lhs, rhs, opts)
end
else
local options = helpers.mergeTables(opts or {}, { noremap = true })
local settings = options.settings or ""
if options.silent then settings = settings .. "s" end
if options.silent then
settings = settings .. "s"
end
arpeggio(mode, settings, not options.noremap, lhs, rhs)
end
end
function M.chordSilent(mode, lhs, rhs, opts)
---Create a silent arpeggio mapping
---@param mode string
---@param lhs string
---@param rhs string
---@param opts table|nil
local function chordSilent(mode, lhs, rhs, opts)
local options = helpers.mergeTables(opts or {}, { silent = true })
M.chord(mode, lhs, rhs, options)
chord(mode, lhs, rhs, options)
end
function M.setup()
chordSilent("n", "ji", ":silent :write<cr>") -- Saving
chord("i", "jk", "<Esc>") -- Remap Esc to jk
chord("nv", "cp", '"+') -- Press cp to use the global clipboard
end
return M

View file

@ -1,18 +1,7 @@
local arpeggio = require("my.plugins.arpeggio")
local lspconfig = require("my.plugins.lspconfig")
local M = {}
local idrisChords = {
sc = "case_split",
mc = "make_case",
ml = "make_lemma",
es = "expr_search",
gd = "generate_def",
rh = "refine_hole",
ac = "add_clause"
}
function M.setup()
local idris2 = require("idris2")
@ -21,14 +10,28 @@ function M.setup()
on_attach = function(client, bufnr)
lspconfig.on_attach(client, bufnr)
for key, value in pairs(idrisChords) do
arpeggio.chord("n", "i" .. key,
":lua require('idris2.code_action')." .. value .. "()<CR>",
{ settings = "b" })
local function nmap(from, to, desc)
vim.keymap.set("n", "<leader>I" .. from, function()
require("idris2.code_action")[to]()
end, { desc = desc, bufnr = true })
end
nmap("C", "make_case", "Make [c]plit")
nmap("L", "make_lemma", "Make [l]emma")
nmap("c", "add_clause", "Add [c]lause")
nmap("s", "expr_search", "Expression [s]earch")
nmap("d", "generate_def", "Generate [d]efinition")
nmap("s", "case_split", "Case [s]plit")
nmap("h", "refine_hole", "Refine [h]ole")
local status, wk = pcall(require, "which-key")
if status then
wk.register({ ["<leader>I"] = { name = "[I]dris", buffer = bufnr } })
end
end,
},
client = { hover = { use_split = true } }
client = { hover = { use_split = true } },
})
end

View file

@ -38,7 +38,6 @@ function M.setup()
require("my.plugins.vimtex").setup()
-- require("my.plugins.lean").setup()
require("my.plugins.notify").setup()
require("my.plugins.iron").setup()
end)
if env.neovide.active() then
@ -59,7 +58,8 @@ function M.setup()
require("my.plugins.hydra").setup()
require("my.plugins.clipboard-image").setup()
require("my.plugins.mind").setup()
require("my.plugins.ufo").setup()
-- require("my.plugins.ufo").setup()
require("my.plugins.arpeggio").setup()
-- require("my.plugins.slam").setup()
end

View file

@ -41,7 +41,7 @@ function M.setup()
local status, wk = pcall(require, "which-key")
if status then wk.register({ ["<leader>i"] = { name = "Iron repl commands" } }) end
if status then wk.register({ ["<leader>i"] = { name = "[I]ron repl commands", s = {name = "[s]end"}, m = "[m]ark" } }) end
end
return M

View file

@ -16,7 +16,7 @@ function M.on_attach(client, bufnr)
-- }}}
-- {{{ Keymap helpers
local opts = function(desc)
return { noremap = true, silent = true, desc = desc }
return { noremap = true, silent = true, desc = desc, buffer = true }
end
local nmap = function(from, to, desc)

View file

@ -1,5 +1,3 @@
local arpeggio = require("my.plugins.arpeggio")
local M = {}
local function find_files_by_extension(extension)
@ -14,18 +12,23 @@ local defaultTheme = "ivy"
local keybinds = {
{ "<C-P>", "find_files", "Find files" },
{ "<Leader>ft", find_files_by_extension("tex"), "Find tex files" },
{ "<Leader>fl", find_files_by_extension("lua"), "Find lua files" },
{ "<Leader>fp", find_files_by_extension("purs"), "Find purescript files" },
{ "<Leader>d", "diagnostics", "Diagnostics" },
{ "<C-F>", "live_grep", "Search in project" },
{ "<Leader>t", "builtin", "Show builtin pickers" }
{ "<Leader>ft", find_files_by_extension("tex"), "[F]ind [t]ex files" },
{ "<Leader>fl", find_files_by_extension("lua"), "[F]ind [l]ua files" },
{
"<Leader>fp",
find_files_by_extension("purs"),
"[F]ind [p]urescript files",
},
{ "<Leader>d", "diagnostics", "[D]iagnostics" },
{ "<C-F>", "live_grep", "[F]ind in project" },
{ "<C-S-F>", "file_browser", "[F]ile browser" },
{ "<Leader>t", "builtin", "[T]elescope pickers" },
}
local chords = { { "jp", "file_browser" } }
local function mkAction(action)
if not string.find(action, "theme=") then action = with_theme(action, defaultTheme) end
if not string.find(action, "theme=") then
action = with_theme(action, defaultTheme)
end
return ":Telescope " .. action .. "<cr>"
end
@ -34,8 +37,6 @@ local function setupKeybinds()
for _, mapping in pairs(keybinds) do
vim.keymap.set("n", mapping[1], mkAction(mapping[2]), { desc = mapping[3] })
end
for _, mapping in pairs(chords) do arpeggio.chord("n", mapping[1], mkAction(mapping[2])) end
end
function M.setup()
@ -44,11 +45,11 @@ function M.setup()
local settings = {
defaults = { mappings = { i = { ["<C-h>"] = "which_key" } } },
pickers = { find_files = { hidden = true } },
extensions = { file_browser = { path = "%:p:h" } }
extensions = { file_browser = { path = "%:p:h" } },
}
require("telescope").setup(settings)
require("telescope").load_extension "file_browser"
require("telescope").load_extension("file_browser")
end
return M

View file

@ -7,12 +7,12 @@ function M.setup()
vim.o.foldenable = true
-- Using ufo provider need remap `zR` and `zM`.
-- vim.keymap.set('n', 'zR', require('ufo').openAllFolds)
-- vim.keymap.set('n', 'zM', require('ufo').closeAllFolds)
vim.keymap.set('n', 'zR', require('ufo').openAllFolds)
vim.keymap.set('n', 'zM', require('ufo').closeAllFolds)
-- Tell the server the capability of foldingRange,
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
-- require('ufo').setup()
require('ufo').setup()
end
return M

View file

@ -1,11 +1,27 @@
local arpeggio = require("my.plugins.arpeggio")
local K = require("my.keymaps")
local M = {}
function M.setup()
arpeggio.chordSilent("n", "vp", ":VimuxPromptCommand<CR>")
arpeggio.chordSilent("n", "vc", ":VimuxRunCommand \"clear\"<CR>")
arpeggio.chordSilent("n", "vl", ":VimuxRunLastCommand<CR>")
--{{{ Register keybinds
K.nmap("<leader>vp", ":VimuxPromptCommand<CR>", "[V]imux: [p]rompt for command")
K.nmap("<leader>vc", ':VimuxRunCommand "clear"<CR>', "[V]imux: [c]lear pane")
K.nmap(
"<leader>vl",
":VimuxRunLastCommand<CR>",
"[V]imux: rerun [l]ast command"
)
--}}}
--{{{ Register which-key docs
local status, wk = pcall(require, "which-key")
if status then
wk.register({
["<leader>v"] = {
name = "vimux",
},
})
end
--}}}
end
return M

View file

@ -87,7 +87,8 @@ in
home.file."${nixPlugins}/start/theming/lua/my/theme.lua".source = theme.neovim.theme;
home.file."${nixPlugins}/start/teal/lua".source = teal; # teal (typed lua)
home.file."${nixPlugins}/start/snippets".source = simlink "${paths.dotfiles}/vscode-snippets";
home.file.".config/nvim".source = simlink "${paths.dotfiles}/neovim";
# home.file.".config/nvim".source = simlink "${paths.dotfiles}/neovim";
home.file.".config/nvim".source = ../../dotfiles/neovim;
programs.neovim.enable = false;