Last active
December 5, 2022 20:27
-
-
Save coffebar/6c09c75d5dafcf1d76cc1079e140939c to your computer and use it in GitHub Desktop.
Neovim project-related lua config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Local project-level config for Neovim | |
-- Based on https://gist.github.com/coffebar/6c09c75d5dafcf1d76cc1079e140939c | |
local augroup_name = "tmp_local_group" | |
local augroup = vim.api.nvim_create_augroup(augroup_name, { clear = true }) | |
local unbind_table = {} | |
local function bind(op, outer_opts) | |
outer_opts = outer_opts or { noremap = true } | |
return function(lhs, rhs, opts) | |
opts = vim.tbl_extend("force", outer_opts, opts or {}) | |
vim.keymap.set(op, lhs, rhs, opts) | |
table.insert(unbind_table, { | |
op = op, | |
lhs = lhs, | |
}) | |
end | |
end | |
vim.api.nvim_create_autocmd("DirChangedPre", { | |
group = augroup, | |
-- Undo all changes | |
callback = function() | |
vim.api.nvim_del_augroup_by_name(augroup_name) | |
-- undo keymaps | |
for _, b in ipairs(unbind_table) do | |
vim.keymap.set(b.op, b.lhs, "<nop>", { noremap = true }) | |
end | |
end, | |
}) | |
-- Setup | |
local nnoremap = bind("n") | |
-- local vnoremap = bind("v") | |
-- Add maps | |
nnoremap("<leader>ex", ":w!<cr>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Add this to your nvim config | |
local augroup = vim.api.nvim_create_augroup("user_cmds", { clear = true }) | |
vim.api.nvim_create_autocmd("DirChanged", { | |
group = augroup, | |
desc = "Source local nvim config", | |
callback = function() | |
local rc = ".vimrc.lua" | |
if vim.fn.filereadable(rc) == 1 then | |
local cwd = vim.fn.getcwd() | |
local confirm = "Do you trust " .. cwd .. "/" .. rc .. "?" | |
if vim.fn.confirm(confirm, "Yes\nNo") == 1 then | |
vim.api.nvim_command("source .vimrc.lua") | |
end | |
end | |
end, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment