diff --git a/.config/nvim/ftplugin/gitcommit.lua b/.config/nvim/ftplugin/gitcommit.lua new file mode 100644 index 00000000..20b749f1 --- /dev/null +++ b/.config/nvim/ftplugin/gitcommit.lua @@ -0,0 +1 @@ +vim.bo.textwidth = 72 diff --git a/.config/nvim/ftplugin/go.lua b/.config/nvim/ftplugin/go.lua new file mode 100644 index 00000000..8a1e83ff --- /dev/null +++ b/.config/nvim/ftplugin/go.lua @@ -0,0 +1 @@ +vim.o.expandtab = false diff --git a/.config/nvim/ftplugin/haskell.lua b/.config/nvim/ftplugin/haskell.lua new file mode 100644 index 00000000..ef0c55e6 --- /dev/null +++ b/.config/nvim/ftplugin/haskell.lua @@ -0,0 +1,2 @@ +local opts = require("opts") +opts.matchit_let_in() diff --git a/.config/nvim/ftplugin/ledger.lua b/.config/nvim/ftplugin/ledger.lua new file mode 100644 index 00000000..b6fea40a --- /dev/null +++ b/.config/nvim/ftplugin/ledger.lua @@ -0,0 +1,6 @@ +-- TODO: remove this when PR is merged +vim.bo.commentstring = "; %s" + +vim.bo.varsofttabstop = "4,30,8,4" +vim.o.spell = true +vim.bo.spelllang = "fr" diff --git a/.config/nvim/ftplugin/markdown.lua b/.config/nvim/ftplugin/markdown.lua new file mode 100644 index 00000000..626438b9 --- /dev/null +++ b/.config/nvim/ftplugin/markdown.lua @@ -0,0 +1,4 @@ +vim.o.shiftwidth = 2 +vim.o.tabstop = 2 +vim.o.textwidth = 100 +vim.o.colorcolumn = "100" diff --git a/.config/nvim/ftplugin/nix.lua b/.config/nvim/ftplugin/nix.lua new file mode 100644 index 00000000..ef0c55e6 --- /dev/null +++ b/.config/nvim/ftplugin/nix.lua @@ -0,0 +1,2 @@ +local opts = require("opts") +opts.matchit_let_in() diff --git a/.config/nvim/ftplugin/ocaml.lua b/.config/nvim/ftplugin/ocaml.lua new file mode 100644 index 00000000..ef0c55e6 --- /dev/null +++ b/.config/nvim/ftplugin/ocaml.lua @@ -0,0 +1,2 @@ +local opts = require("opts") +opts.matchit_let_in() diff --git a/.config/nvim/ftplugin/typst.lua b/.config/nvim/ftplugin/typst.lua new file mode 100644 index 00000000..626438b9 --- /dev/null +++ b/.config/nvim/ftplugin/typst.lua @@ -0,0 +1,4 @@ +vim.o.shiftwidth = 2 +vim.o.tabstop = 2 +vim.o.textwidth = 100 +vim.o.colorcolumn = "100" diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 62c0baa5..5f15d853 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,6 +1,5 @@ require("maps") require("opts") -require("cmds") require("_lazy") diff --git a/.config/nvim/lua/cmds.lua b/.config/nvim/lua/cmds.lua deleted file mode 100644 index c0fcd104..00000000 --- a/.config/nvim/lua/cmds.lua +++ /dev/null @@ -1,146 +0,0 @@ -vim.api.nvim_create_autocmd("TextYankPost", { callback = vim.highlight.on_yank }) - -vim.filetype.add { - extension = { - [".*Caddyfile"] = "caddyfile", - hledger = "ledger", - mlw = "why3", - pro = "projet", - sk = "skel", - skel = "skel", - typ = "typst", - thy = "isabelle", - }, -} - -vim.api.nvim_create_autocmd("BufEnter", { - pattern = "justfile", - callback = function() vim.bo.filetype = "make" end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "gitcommit", - callback = function() vim.bo.textwidth = 72 end, -}) - -vim.api.nvim_create_autocmd("BufWinEnter", { - pattern = "*.md", - callback = function() vim.cmd("setlocal sw=2 ts=2 tw=100 colorcolumn=100") end, -}) - -vim.api.nvim_create_autocmd("BufWinEnter", { - pattern = "*.typ", - callback = function() vim.cmd("setlocal sw=2 ts=2 tw=100 colorcolumn=100") end, -}) - -vim.api.nvim_create_autocmd("BufWinEnter", { - pattern = "*.eml", - callback = function() vim.cmd("setlocal sw=2 ts=2 tw=80 colorcolumn=80") end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "ledger", - callback = function() - vim.cmd("setlocal varsofttabstop=4,30,8,4 spell spelllang=fr") - -- TODO: remove this when PR is merged - vim.bo.commentstring = "; %s" - end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "asm", - callback = function() vim.bo.commentstring = "# %s" end, -}) - --- "Projet" language taught at ISTIC -vim.api.nvim_create_autocmd("FileType", { - pattern = "projet", - callback = function() vim.bo.commentstring = "{ %s }" end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "skel", - callback = function() - vim.bo.commentstring = "(* %s *)" - vim.keymap.set("n", "f", function() - vim.cmd("w") - vim.cmd("silent exec '!necroprint % -o %'") - vim.cmd("e") - end, { buffer = true, silent = true }) - end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "why3", - callback = function() - vim.bo.commentstring = "(* %s *)" - vim.cmd([[setlocal sw=2 ts=2 et]]) - end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "go", - callback = function() vim.cmd("set noet") end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = { "nix", "haskell", "ocaml", "skel" }, - callback = function() vim.cmd([[let b:match_words = '\:\']]) end, -}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = "ledger", - callback = function() - vim.keymap.set("n", "f", function() - local saved = vim.fn.winsaveview() - vim.cmd([[%!hledger print -f -]]) - vim.fn.winrestview(saved) - end) - end, -}) - -vim.api.nvim_create_autocmd("OptionSet", { - pattern = "shiftwidth", - callback = function() - if vim.o.expandtab then - local c = "" - for _ = c:len(), vim.o.shiftwidth + 1 do - c = c .. " " - end - return vim.opt.lcs:append("leadmultispace:" .. c) - else - return nil - end - end, -}) - -vim.api.nvim_create_autocmd("OptionSet", { - pattern = "textwidth", - callback = function() vim.wo.colorcolumn = tostring(vim.bo.textwidth) end, -}) - -vim.api.nvim_create_user_command("Retab", function(opts) - if #opts.fargs ~= 2 then - return print("should have exactly two argument: [src] and [dst]") - end - local src = tonumber(opts.fargs[1]) - local dst = tonumber(opts.fargs[2]) - if src == nil then - print("first argument [src] is not a valid number") - end - if dst == nil then - print("second argument [dst] is not a valid number") - end - - vim.bo.shiftwidth = src - vim.bo.tabstop = src - vim.bo.expandtab = false - vim.cmd("%retab!") - vim.bo.shiftwidth = dst - vim.bo.tabstop = dst - vim.bo.expandtab = true - vim.cmd("%retab!") -end, { nargs = "+" }) - --- Dissambiguate the :W shortcut -vim.api.nvim_create_user_command("W", function(opts) vim.cmd(":w") end, { nargs = 0 }) diff --git a/.config/nvim/lua/opts.lua b/.config/nvim/lua/opts.lua index dc89050d..b8e02671 100644 --- a/.config/nvim/lua/opts.lua +++ b/.config/nvim/lua/opts.lua @@ -1,3 +1,5 @@ +M = {} + vim.o.hlsearch = false vim.o.incsearch = true vim.o.ignorecase = true @@ -34,3 +36,7 @@ vim.o.list = true vim.o.splitright = true vim.o.splitbelow = true + +function M.matchit_let_in() vim.b.match_words = [[\:\]] end + +return M diff --git a/.config/nvim/plugin/autocommands.lua b/.config/nvim/plugin/autocommands.lua new file mode 100644 index 00000000..c17fce12 --- /dev/null +++ b/.config/nvim/plugin/autocommands.lua @@ -0,0 +1,29 @@ +vim.api.nvim_create_autocmd("TextYankPost", { + group = vim.api.nvim_create_augroup("Visual", {}), + callback = function() + vim.highlight.on_yank { + higroup = "IncSearch", + timeout = 100, + } + end, +}) + +vim.api.nvim_create_autocmd("OptionSet", { + pattern = "shiftwidth", + callback = function() + if vim.o.expandtab then + local c = "" + for _ = c:len(), vim.o.shiftwidth + 1 do + c = c .. " " + end + return vim.opt.lcs:append("leadmultispace:" .. c) + else + return nil + end + end, +}) + +vim.api.nvim_create_autocmd("OptionSet", { + pattern = "textwidth", + callback = function() vim.wo.colorcolumn = tostring(vim.bo.textwidth) end, +}) diff --git a/.config/nvim/plugin/commands.lua b/.config/nvim/plugin/commands.lua new file mode 100644 index 00000000..4f4ec205 --- /dev/null +++ b/.config/nvim/plugin/commands.lua @@ -0,0 +1,24 @@ +vim.api.nvim_create_user_command("Retab", function(opts) + if #opts.fargs ~= 2 then + return print("should have exactly two argument: [src] and [dst]") + end + local src = tonumber(opts.fargs[1]) + local dst = tonumber(opts.fargs[2]) + if src == nil then + print("first argument [src] is not a valid number") + end + if dst == nil then + print("second argument [dst] is not a valid number") + end + + vim.bo.shiftwidth = src + vim.bo.tabstop = src + vim.bo.expandtab = false + vim.cmd("%retab!") + vim.bo.shiftwidth = dst + vim.bo.tabstop = dst + vim.bo.expandtab = true + vim.cmd("%retab!") +end, { nargs = "+" }) + +vim.api.nvim_create_user_command("W", function() vim.cmd.w() end, {}) diff --git a/.config/nvim/plugin/ftdetect.lua b/.config/nvim/plugin/ftdetect.lua new file mode 100644 index 00000000..f096986e --- /dev/null +++ b/.config/nvim/plugin/ftdetect.lua @@ -0,0 +1,8 @@ +vim.filetype.add { + extension = { + [".*Caddyfile"] = "caddyfile", + hledger = "ledger", + pro = "projet", + typ = "typst", + }, +}