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") local A = require("my.abbreviations")
-- Use vt to test -- Use vt to test
arpeggio.chordSilent("n", "vt", ":VimuxRunCommand \"clear && spago test\"<CR>", vim.keymap.set(
{ settings = "b" }) "n",
"<leader>vt",
':VimuxRunCommand "clear && spago test"<CR>',
{ desc = "[V]imtex run [t]ests", buffer = true }
)
-- Use vb to build -- Use vb to build
arpeggio.chordSilent("n", "vb", ":VimuxRunCommand \"clear && spago build\"<CR>", vim.keymap.set(
{ settings = "b" }) "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 vim.opt.expandtab = true -- Use spaces for the tab char
@ -17,7 +24,7 @@ local abbreviations = {
{ "tto", "->" }, { "tto", "->" },
{ "iip", "=>" }, { "iip", "=>" },
{ "frl", "forall" }, { "frl", "forall" },
{ "ott", "<-" } -- opposite of tto { "ott", "<-" }, -- opposite of tto
} }
A.manyLocalAbbr(abbreviations) 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() 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() function M.setup()
-- Import my other files -- 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.options").setup()
require('my.keymaps').setup() require('my.keymaps').setup()
require('my.plugins').setup()
-- require("telescope.extensions.unicode").setupAbbreviations()
end end
return M return M

View file

@ -1,21 +1,43 @@
local helpers = require("my.helpers") local helpers = require("my.helpers")
local arpeggio = require("my.plugins.arpeggio")
local M = {} local M = {}
-- {{{ Helpers -- {{{ 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) function M.move(from, to, opts)
vim.keymap.set("n", to, from, opts) vim.keymap.set("n", to, from, opts)
vim.keymap.set("n", from, "<Nop>") vim.keymap.set("n", from, "<Nop>")
end 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) function M.delimitedTextobject(from, to, name, perhapsOpts)
local opts = helpers.mergeTables(perhapsOpts or {}, { desc = name }) local opts = helpers.mergeTables(perhapsOpts or {}, { desc = name })
vim.keymap.set({ "v", "o" }, "i" .. from, "i" .. to, opts) vim.keymap.set({ "v", "o" }, "i" .. from, "i" .. to, opts)
vim.keymap.set({ "v", "o" }, "a" .. from, "a" .. to, opts) vim.keymap.set({ "v", "o" }, "a" .. from, "a" .. to, opts)
end 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() function M.setup()
@ -23,47 +45,38 @@ function M.setup()
M.move("q", "yq", { desc = "Record macro" }) M.move("q", "yq", { desc = "Record macro" })
M.move("Q", "yQ") M.move("Q", "yQ")
-- }}} -- }}}
-- {{{ Easier access to C^ -- {{{ Easier access to <C-^>
M.move("<C-^>", "<Leader>a", { desc = "Go to previous file" }) M.move("<C-^>", "<Leader>a", { desc = "[A]lternate file" })
-- }}} -- }}}
-- {{{ Quit current buffer / all buffers -- {{{ Quit current buffer / all buffers
vim.keymap.set({ "n", "v" }, "<leader>q", function() vim.keymap.set({ "n", "v" }, "<leader>q", function()
local buf = vim.api.nvim_win_get_buf(0) local buf = vim.api.nvim_win_get_buf(0)
-- Only save if file is writable -- 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" vim.cmd("q")
end, { desc = "Quit current buffer" }) 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 -- {{{ 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 -- {{{ Text objects
M.delimitedTextobject("q", '"', "quotes") M.delimitedTextobject("q", '"', "[q]uotes")
M.delimitedTextobject("a", "'", "'") M.delimitedTextobject("a", "'", "[a]postrophes")
M.delimitedTextobject("r", "[", "square brackets") M.delimitedTextobject("r", "[", "squa[r]e brackets")
-- }}} -- }}}
-- {{{Diagnostic keymaps -- {{{Diagnostic keymaps
do M.nmap("[d", vim.diagnostic.goto_prev, "Goto previous [d]iagnostic")
local opts = function(desc) M.nmap("]d", vim.diagnostic.goto_next, "Goto next [d]iagnostic")
return { noremap = true, silent = true, desc = desc } M.nmap("J", vim.diagnostic.open_float, "Open current diagnostic")
end M.nmap("<leader>D", vim.diagnostic.setloclist, "[S]iagnostic loclist")
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
-- }}} -- }}}
-- {{{ Chords -- {{{ Chords (exit insert mode, save, clipboard)
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
-- }}} -- }}}
-- {{{ Set up which-key structure -- {{{ Set up which-key structure
local status, wk = pcall(require, "which-key") local status, wk = pcall(require, "which-key")
@ -71,16 +84,31 @@ function M.setup()
if status then if status then
wk.register({ wk.register({
["<leader>"] = { ["<leader>"] = {
f = { name = "Files" }, f = { name = "[F]iles" },
g = { name = "Go to" }, g = { name = "[G]o to" },
r = { name = "Rename / Replace / Reload" }, r = { name = "[R]ename / [R]eplace / [R]eload" },
l = { name = "Local" }, l = { name = "[L]ocal" },
v = "which_key_ignore" w = { name = "[W]orkspace" },
} v = "which_key_ignore",
},
}) })
end 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 return M
end end

View file

@ -1,5 +1,3 @@
local helpers = require("my.helpers")
local M = {} local M = {}
function M.setup() function M.setup()
@ -39,8 +37,8 @@ function M.setup()
-- Set leader -- Set leader
vim.g.mapleader = " " vim.g.mapleader = " "
-- Import other options -- Folding
require("my.options.folding").setup() vim.o.foldmethod = "marker"
end end
return M 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 themePackages = require("my.theme").deps
local base = { local base = {
"nvim-lua/plenary.nvim", -- async utility lib it seems? "nvim-lua/plenary.nvim", -- async utility lib it seems?
--------------------------------- Unuported
"folke/neoconf.nvim", -- per project neovim configuration "folke/neoconf.nvim", -- per project neovim configuration
"neovim/nvim-lspconfig", -- configures lsps for me "neovim/nvim-lspconfig", -- configures lsps for me
"folke/neodev.nvim", -- lua support "folke/neodev.nvim", -- lua support

View file

@ -3,25 +3,43 @@ local arpeggio = vim.fn["arpeggio#map"]
local M = {} 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 if string.len(mode) > 1 then
for i = 1, #mode do for i = 1, #mode do
local c = mode:sub(i, i) local c = mode:sub(i, i)
M.chord(c, lhs, rhs, opts) chord(c, lhs, rhs, opts)
end end
else else
local options = helpers.mergeTables(opts or {}, { noremap = true }) local options = helpers.mergeTables(opts or {}, { noremap = true })
local settings = options.settings or "" 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) arpeggio(mode, settings, not options.noremap, lhs, rhs)
end end
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 }) 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 end
return M return M

View file

@ -1,18 +1,7 @@
local arpeggio = require("my.plugins.arpeggio")
local lspconfig = require("my.plugins.lspconfig") local lspconfig = require("my.plugins.lspconfig")
local M = {} 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() function M.setup()
local idris2 = require("idris2") local idris2 = require("idris2")
@ -21,14 +10,28 @@ function M.setup()
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
lspconfig.on_attach(client, bufnr) lspconfig.on_attach(client, bufnr)
for key, value in pairs(idrisChords) do local function nmap(from, to, desc)
arpeggio.chord("n", "i" .. key, vim.keymap.set("n", "<leader>I" .. from, function()
":lua require('idris2.code_action')." .. value .. "()<CR>", require("idris2.code_action")[to]()
{ settings = "b" }) end, { desc = desc, bufnr = true })
end 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
end,
}, },
client = { hover = { use_split = true } } client = { hover = { use_split = true } },
}) })
end end

View file

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

View file

@ -41,7 +41,7 @@ function M.setup()
local status, wk = pcall(require, "which-key") 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 end
return M return M

View file

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

View file

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

View file

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

View file

@ -1,11 +1,27 @@
local arpeggio = require("my.plugins.arpeggio") local K = require("my.keymaps")
local M = {} local M = {}
function M.setup() function M.setup()
arpeggio.chordSilent("n", "vp", ":VimuxPromptCommand<CR>") --{{{ Register keybinds
arpeggio.chordSilent("n", "vc", ":VimuxRunCommand \"clear\"<CR>") K.nmap("<leader>vp", ":VimuxPromptCommand<CR>", "[V]imux: [p]rompt for command")
arpeggio.chordSilent("n", "vl", ":VimuxRunLastCommand<CR>") 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 end
return M 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/theming/lua/my/theme.lua".source = theme.neovim.theme;
home.file."${nixPlugins}/start/teal/lua".source = teal; # teal (typed lua) home.file."${nixPlugins}/start/teal/lua".source = teal; # teal (typed lua)
home.file."${nixPlugins}/start/snippets".source = simlink "${paths.dotfiles}/vscode-snippets"; 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; programs.neovim.enable = false;