mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
nvim: refactor cmds into commands
This commit is contained in:
parent
1bdcd3386e
commit
7ae86384f6
14 changed files with 89 additions and 147 deletions
1
.config/nvim/ftplugin/gitcommit.lua
Normal file
1
.config/nvim/ftplugin/gitcommit.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
vim.bo.textwidth = 72
|
||||
1
.config/nvim/ftplugin/go.lua
Normal file
1
.config/nvim/ftplugin/go.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
vim.o.expandtab = false
|
||||
2
.config/nvim/ftplugin/haskell.lua
Normal file
2
.config/nvim/ftplugin/haskell.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
local opts = require("opts")
|
||||
opts.matchit_let_in()
|
||||
6
.config/nvim/ftplugin/ledger.lua
Normal file
6
.config/nvim/ftplugin/ledger.lua
Normal file
|
|
@ -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"
|
||||
4
.config/nvim/ftplugin/markdown.lua
Normal file
4
.config/nvim/ftplugin/markdown.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
vim.o.shiftwidth = 2
|
||||
vim.o.tabstop = 2
|
||||
vim.o.textwidth = 100
|
||||
vim.o.colorcolumn = "100"
|
||||
2
.config/nvim/ftplugin/nix.lua
Normal file
2
.config/nvim/ftplugin/nix.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
local opts = require("opts")
|
||||
opts.matchit_let_in()
|
||||
2
.config/nvim/ftplugin/ocaml.lua
Normal file
2
.config/nvim/ftplugin/ocaml.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
local opts = require("opts")
|
||||
opts.matchit_let_in()
|
||||
4
.config/nvim/ftplugin/typst.lua
Normal file
4
.config/nvim/ftplugin/typst.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
vim.o.shiftwidth = 2
|
||||
vim.o.tabstop = 2
|
||||
vim.o.textwidth = 100
|
||||
vim.o.colorcolumn = "100"
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
require("maps")
|
||||
require("opts")
|
||||
require("cmds")
|
||||
|
||||
require("_lazy")
|
||||
|
||||
|
|
|
|||
|
|
@ -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", "<leader>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 = '\<let\>:\<in\>']]) end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "ledger",
|
||||
callback = function()
|
||||
vim.keymap.set("n", "<leader>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 })
|
||||
|
|
@ -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 = [[\<let\>:\<in\>]] end
|
||||
|
||||
return M
|
||||
|
|
|
|||
29
.config/nvim/plugin/autocommands.lua
Normal file
29
.config/nvim/plugin/autocommands.lua
Normal file
|
|
@ -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,
|
||||
})
|
||||
24
.config/nvim/plugin/commands.lua
Normal file
24
.config/nvim/plugin/commands.lua
Normal file
|
|
@ -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, {})
|
||||
8
.config/nvim/plugin/ftdetect.lua
Normal file
8
.config/nvim/plugin/ftdetect.lua
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
vim.filetype.add {
|
||||
extension = {
|
||||
[".*Caddyfile"] = "caddyfile",
|
||||
hledger = "ledger",
|
||||
pro = "projet",
|
||||
typ = "typst",
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue