ditch fennel ? (#3)

yes

Reviewed-on: https://git.earth2077.fr/leana/.files/pulls/3
Co-authored-by: Léana 江 <leana.jiang@icloud.com>
Co-committed-by: Léana 江 <leana.jiang@icloud.com>
This commit is contained in:
Léana 江 2024-02-07 19:47:43 +00:00 committed by Léana 江
parent d0cb07df6d
commit b81732fcf2
41 changed files with 1370 additions and 1114 deletions

View file

@ -0,0 +1,91 @@
local autocmd = vim.api.nvim_create_autocmd
local usercmd = vim.api.nvim_create_user_command
vim.filetype.add { extension = { typ = "typst" } }
vim.filetype.add { extension = { skel = "skel", sk = "skel" } }
vim.filetype.add { extension = { mlw = "why3" } }
autocmd("TextYankPost", { callback = vim.highlight.on_yank })
autocmd("FileType", {
pattern = { "markdown", "tex", "typst" },
callback =
function()
vim.opt_local["shiftwidth"] = 2
vim.opt_local["tabstop"] = 2
vim.opt_local["textwidth"] = 80
end,
})
autocmd("FileType", {
pattern = "skel",
callback = function()
vim.opt_local["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,
})
autocmd("FileType", {
pattern = "fennel",
callback = function()
vim.opt_local["list"] = false
return vim.keymap.set({ "n" }, "<leader>f", function()
vim.cmd "w "
vim.cmd "silent exec '!fnlfmt --fix %'"
vim.cmd "e "
end, { buffer = true, silent = true })
end,
})
autocmd("FileType", {
pattern = "why3",
callback = function()
vim.opt_local["commentstring"] = "(* %s *)"
vim.opt_local["shiftwidth"] = 2
vim.opt_local["tabstop"] = 2
vim.opt_local["expandtab"] = true
end,
})
autocmd("BufEnter", {
pattern = "*Caddyfile",
callback = function()
vim.opt_local["filetype"] = "Caddy"
vim.opt_local["commentstring"] = "# %s"
end,
})
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,
})
usercmd("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])
vim.opt["shiftwidth"] = src
vim.opt["tabstop"] = src
vim.opt["expandtab"] = false
vim.cmd "%retab! "
vim.opt["shiftwidth"] = dst
vim.opt["tabstop"] = dst
vim.opt["expandtab"] = true
vim.cmd "%retab! "
end, { nargs = "+" })

View file

@ -0,0 +1,21 @@
(local M {})
(lambda M.req-plugins! [ns]
`(each [_# n# (ipairs ,ns)]
(require (.. :plugins._ n#))))
(lambda M.fst! [obj]
`(. ,obj 1))
(lambda M.snd! [obj]
`(. ,obj 2))
(lambda M.req-do! [module callback]
`(,callback (require ,module)))
(lambda M.elem! [obj tbl]
`(each [_# v# (pairs ,tbl)]
(when (= v# ,obj) (lua "return true"))
false))
M

View file

@ -0,0 +1,111 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "
local map = vim.keymap.set
local unmap = vim.keymap.del
local autocmd = vim.api.nvim_create_autocmd
-- Move
map("v", "J", ":m '>+1<CR>gv=gv")
map("v", "K", ":m '<-2<CR>gv=gv")
-- Centered motions
map("n", "<C-d>", "<C-d>zz")
map("n", "<C-u>", "<C-u>zz")
map("n", "n", "nzzzv")
map("n", "N", "Nzzzv")
map("n", "J", "mzJ`z")
-- Better clipboard
map({ "n", "x", "v" }, "<leader>d", '"_d')
map({ "n", "x", "v" }, "<leader>c", '"_dc')
map({ "n", "x", "v" }, "<leader>p", '"_dP')
map({ "n", "x", "v" }, "<leader>y", '"+y')
-- Linewrap jk
-- Only use gj et al. when needed
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- Replace selected token
map("v", "<leader>r", [["ry:%s/\(<C-r>r\)//g<Left><Left>]])
map("n", "<leader>pv", function() vim.cmd "Oil" end) -- Project View
map("n", "<leader>nf", function() vim.cmd "enew" end) -- New File
map("n", "<leader>so", function() vim.cmd "so %" end) -- Source buffer
map("c", "#capl", [[\(.\{-}\)]]) -- helpers in regex
map("c", "#capm", [[\(.*\)]])
map("n", "<leader>+x", function() vim.cmd "!chmod +x %" end) -- Permission
map("n", "<leader>-x", function() vim.cmd "!chmod -x %" end)
map("n", "<leader>hg", function() vim.cmd "Inspect" end) -- Highlight Group
map("n", "Q", "<nop>") -- *do not* repeat the last recorded register [count] times.
-- Diagnostics
map("n", "<leader>e", vim.diagnostic.open_float)
map("n", "<leader>pe", vim.diagnostic.goto_prev)
map("n", "<leader>ne", vim.diagnostic.goto_next)
map("t", "<Leader><ESC>", "<C-\\><C-n>")
-- Resize window using shift + arrow keys
-- Credit: github.com/GrizzlT
map("n", "<S-Up>", "<cmd>resize +2<cr>")
map("n", "<S-Down>", "<cmd>resize -2<cr>")
map("n", "<S-Left>", "<cmd>vertical resize -2<cr>")
map("n", "<S-Right>", "<cmd>vertical resize +2<cr>")
-------------
-- Plugins --
-------------
-- Tabular
map("n", "<leader>ta", function() vim.cmd "Tabularize /=" end)
map("n", "<leader>tc", function() vim.cmd "Tabularize /:" end)
map("n", "<leader>tC", function() vim.cmd "Tabularize trailing_c_comments" end)
-- Twilight
map("n", "<leader>tw", function() vim.cmd "Twilight" end)
-- Gitsigns
map("n", "<leader>gl",
function()
vim.cmd "Gitsigns toggle_numhl"
vim.cmd "Gitsigns toggle_signs"
end
)
-- Fugitive
map("n", "<leader>gP", function() vim.cmd "G push" end)
map("n", "<leader>gp", function() vim.cmd "G pull" end)
map("n", "<leader><space>", ":Git<CR>5<Down>")
map("n", "<leader>gu", ":diffget //2<CR>")
map("n", "<leader>gh", ":diffget //3<CR>")
autocmd("FileType", {
pattern = "fugitive",
callback = function() map("n", "<leader><space>", ":q<CR>", { buffer = true }) end,
})
map("n", "<leader>gb", ":Git blame<CR>")
autocmd("FileType", {
pattern = "fugitiveblame",
callback = function() map("n", "<leader>gb", ":q<CR>", { buffer = true }) end,
})
-- NoNeckPain
map("n", "<leader>z", ":NoNeckPain<CR>")
-- Todo-Comments
map("n", "<leader>td", function() vim.cmd "TodoTelescope" end)
-- Undotree
map("n", "<leader>u", function()
vim.cmd "UndotreeToggle"
vim.cmd "UndotreeFocus"
end)
autocmd("FileType", {
pattern = "undotree",
callback = function() map("n", "<leader>gb", ":q<CR>", { buffer = true }) end,
})
-- color-picker
map("n", "<C-c>", function() vim.cmd "CccPick" end, { silent = true })

View file

@ -0,0 +1,47 @@
local opt = vim.opt
opt.hlsearch = false
opt.incsearch = true
opt.number = true
opt.relativenumber = true
opt.cursorline = true
opt.signcolumn = "yes"
opt.tabstop = 4
opt.expandtab = true
opt.shiftwidth = 4
opt.wrap = false -- Slows the editor
opt.linebreak = true
opt.breakindent = true
opt.filetype = "on"
opt.swapfile = false
opt.backup = false
opt.undofile = true
opt.termguicolors = true
opt.mouse = "a"
opt.ignorecase = true
opt.smartcase = true
opt.autoindent = true
opt.smartindent = true
opt.scrolloff = 3
opt.colorcolumn = "80"
opt.foldlevel = 99
opt.foldlevelstart = 99
opt.foldenable = true
opt.winbar = "%{%v:lua.require'opts.winbar'.eval()%}"
opt.showmode = false
opt.listchars = { tab = "", trail = "" }
opt.list = true
vim.g.netrw_banner = 0

View file

@ -0,0 +1,36 @@
local M = {}
local api = vim.api
local fn = vim.fn
api.nvim_set_hl(0, "WinBar", { fg = "#dedede" })
api.nvim_set_hl(0, "WinBarPath", { bg = "#dedede" })
api.nvim_set_hl(0, "WinBarModified", { bg = "#dedede", bold = true })
function M.eval()
local buffer = api.nvim_win_get_buf(0)
local bufname = fn.bufname(buffer)
local modified = ""
local readonly = ""
if vim.bo[buffer].readonly then
readonly = "[RO] "
end
if vim.bo[buffer].modified then
modified = "[+] "
end
bufname = fn.fnamemodify(bufname, ":p:~")
return "%="
.. "%#WinBarModified#"
.. readonly
.. modified
.. "%*"
.. "%#WinBarPath#"
.. bufname
.. "%*"
end
return M

View file

@ -0,0 +1,52 @@
local Rule = require "nvim-autopairs.rule"
local cond = require "nvim-autopairs.conds"
local npairs = require "nvim-autopairs"
local cmp = require "cmp"
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
npairs.setup {
disable_filetype = { "fennel", "clojure", "lisp", "racket", "scheme" },
}
do end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
for _, punct in pairs { ",", ";" } do
require "nvim-autopairs".add_rules {
require "nvim-autopairs.rule" ("", punct)
:with_move(function(opts) return opts.char == punct end)
:with_pair(function() return false end)
:with_del(function() return false end)
:with_cr(function() return false end)
:use_key(punct),
}
end
local function pair_with_insertion(a1, ins, a2, lang)
npairs.add_rule(
Rule(ins, ins, lang)
:with_pair(function(opts) return a1 .. a2 == opts.line:sub(opts.col - #a1, opts.col + #a2 - 1) end)
:with_move(cond.none())
:with_cr(cond.none())
:with_del(function(opts)
local col = vim.api.nvim_win_get_cursor(0)[2]
return a1 .. ins .. ins .. a2 ==
opts.line:sub(col - #a1 - #ins + 1, col + #ins + #a2) -- insert only works for #ins == 1 anyway
end)
)
end
pair_with_insertion("(", "*", ")", { "ocaml", "why3", "skel" })
pair_with_insertion("(*", " ", "*)", { "ocaml", "why3", "skel" })
pair_with_insertion("[", " ", "]", { "typst", "python", "haskell" })
pair_with_insertion("{", " ", "}", nil)
for _, symb in ipairs { "$", "```", "_", "*" } do
npairs.add_rule(Rule(symb, symb, "typst")
:with_pair(cond.not_before_text(symb))
:with_pair(cond.not_after_regex "%a")
:with_pair(cond.not_before_regex "%a"):with_move(cond.done))
end
npairs.add_rule(Rule("let", "in", "nix"):with_move(cond.done))
pair_with_insertion("let", " ", "in", "nix")

View file

@ -0,0 +1,223 @@
local cmp = require "cmp"
local ls = require "luasnip"
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local cr = function() return t { "", "" } end -- linebreak
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
local r = ls.restore_node
local l = require "luasnip.extras".lambda
local rep = require "luasnip.extras".rep
local p = require "luasnip.extras".partial
local m = require "luasnip.extras".match
local n = require "luasnip.extras".nonempty
local dl = require "luasnip.extras".dynamic_lambda
local fmt = require "luasnip.extras.fmt".fmt
local fmta = require "luasnip.extras.fmt".fmta
local types = require "luasnip.util.types"
local conds = require "luasnip.extras.conditions"
local conds_expand = require "luasnip.extras.conditions.expand"
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
end
-----------------
-- Lazy loader --
-----------------
require "luasnip.loaders.from_vscode".lazy_load { paths = { "./snippets" } }
----------
-- Init --
----------
ls.setup { update_events = { "TextChanged", "TextChangedI" } }
-----------
-- Typst --
-----------
local function show_date_typst_entry()
return os.date "(year: %Y, month: %m, day: %d, hour: %H, minute: %M, second: %S)"
end
ls.add_snippets("typst", {
s("entry", {
t "#entry(",
f(show_date_typst_entry),
t { ")[", "" },
i(0),
t { "", "]" },
}),
})
local function get_cms()
assert(vim.bo.commentstring ~= "", "comment string is not set")
local left = vim.bo.commentstring:gsub("%s*%%s.*", "")
local right = vim.bo.commentstring:gsub(".*%%s%s*", "")
if right == "" then right = left end
return { left = left, right = right }
end
local function horizon(args)
local cms = get_cms()
local chr = cms.left:sub(-1)
local len = vim.fn.strdisplaywidth(args[1][1])
local acc = cms.left
for _ = cms.left:len(), len + cms.right:len() + 1, 1 do
acc = acc .. chr
end
acc = acc .. cms.right
return acc
end
local function left()
local cms = get_cms()
return cms.left .. " "
end
local function right()
local cms = get_cms()
return " " .. cms.right
end
ls.add_snippets("all", {
s("banner", {
f(horizon, { 1 }),
t { "", "" },
f(left), i(1), f(right),
t { "", "" },
f(horizon, { 1 }),
}),
})
------------
-- Ledger --
------------
local function show_date_ledger_entry()
return os.date "%Y-%m-%d"
end
-- shortcuts
ls.add_snippets("ledger", {
s("lessive", {
f(show_date_ledger_entry), t " ", t "Lave linge (CROUS)", cr(),
t "\texpenses 3,00 EUR", cr(),
t "\tassets:compte_courant -3,00 EUR", cr(),
}),
s("sechoir", {
f(show_date_ledger_entry), t " ", t "Sèche linge (CROUS)", cr(),
t "\texpenses 1,50 EUR", cr(),
t "\tassets:compte_courant -1,50 EUR", cr(),
}),
})
-- generalized entry
local id = function(args) return args[1][1] end
ls.add_snippets("ledger", {
s("entry", {
f(show_date_ledger_entry), t " ", i(1), cr(),
t "\texpenses:", i(2), t " ", i(3), t " EUR", cr(),
t "\tassets:compte_courant -", f(id, { 3 }), t " EUR", cr(),
}),
s("date-entry", {
i(1), t " ", i(2), cr(),
t "\texpenses:", i(3), t " ", i(4), t " EUR", cr(),
t "\tassets:compte_courant -", f(id, { 4 }), t " EUR", cr(),
}),
})
-------------
-- Haskell --
-------------
local haskell_snippets = require "haskell-snippets".all
ls.add_snippets("haskell", haskell_snippets, { key = "haskell" })
---------------
-- Setup CMP --
---------------
local of_filetype = function(fts)
local ft = vim.bo.filetype
for _, v in ipairs(fts) do
if v == ft then return true end
end
return false
end
cmp.setup {
snippet = {
expand = function(args)
ls.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
["<Tab>"] = cmp.mapping(function(fallback) -- Next or jump
if cmp.visible() then
cmp.select_next_item()
elseif ls.expand_or_locally_jumpable() then
ls.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) -- Previous
if cmp.visible() then
cmp.select_prev_item()
elseif ls.jumpable(-1) then
ls.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<A-Tab>"] = cmp.mapping(function(fallback) -- Force jump
if ls.expand_or_locally_jumpable() then
ls.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<CR>"] = cmp.mapping(function(fallback) -- Confirm
if cmp.visible() then
cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
} ()
else
fallback()
end
end, { "i", "s" }),
["<S-CR>"] = cmp.mapping(function(fallback) -- Confirm and replace
if cmp.visible() then
cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
} ()
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = "luasnip" },
{ name = "nvim_lsp" },
{
name = "buffer", keyword_length = 10,
option = {
enable_in_context = function()
return of_filetype { "tex", "markdown", "typst" }
end,
},
},
{
name = "spell", keyword_length = 10,
option = {
keep_all_entries = true,
enable_in_context = function()
return of_filetype { "tex", "markdown", "typst" }
end,
},
},
},
}

View file

@ -0,0 +1,21 @@
local default = {
RGB = true, -- #RGB hex codes
RRGGBB = true, -- #RRGGBB hex codes
names = false, -- "Name" codes like Blue or blue
RRGGBBAA = false, -- #RRGGBBAA hex codes
AARRGGBB = false, -- 0xAARRGGBB hex codes
rgb_fn = false, -- CSS rgb() and rgba() functions
hsl_fn = false, -- CSS hsl() and hsla() functions
css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn
mode = "background",
always_update = true,
}
require "colorizer".setup {
filetypes = {
"*",
},
user_default_options = default,
}

View file

@ -0,0 +1,38 @@
require "gitsigns".setup {
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "<leader>hj", gs.next_hunk)
map("n", "<leader>hk", gs.prev_hunk)
-- Actions
map("n", "<leader>hs", gs.stage_hunk)
map("n", "<leader>hu", gs.undo_stage_hunk)
map("n", "<leader>hr", gs.reset_hunk)
map("v", "<leader>hs", function() gs.stage_hunk { vim.fn.line ".", vim.fn.line "v" } end)
map("v", "<leader>hr", function() gs.reset_hunk { vim.fn.line ".", vim.fn.line "v" } end)
map("n", "<leader>hS", gs.stage_buffer)
map("n", "<leader>hR", gs.reset_buffer)
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function() gs.blame_line { full = true } end)
map("n", "<leader>tb", gs.toggle_current_line_blame)
map("n", "<leader>hd", gs.diffthis)
map("n", "<leader>hD", function() gs.diffthis "~" end)
map("n", "<leader>pd", gs.toggle_deleted)
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
}

View file

@ -0,0 +1,19 @@
require "harpoon".setup()
local ui = require "harpoon.ui"
local mark = require "harpoon.mark"
local map = vim.keymap.set
-- add and view
map({ "n", "i" }, "<A-c>", function() mark.add_file() end)
map({ "n", "i" }, "<A-g>", function() ui.toggle_quick_menu() end)
-- switch it up!
map({ "n", "i" }, "<A-h>", function() ui.nav_file(1) end)
map({ "n", "i" }, "<A-t>", function() ui.nav_file(2) end)
map({ "n", "i" }, "<A-n>", function() ui.nav_file(3) end)
map({ "n", "i" }, "<A-s>", function() ui.nav_file(4) end)
map({ "n", "i" }, "<A-m>", function() ui.nav_file(5) end)
map({ "n", "i" }, "<A-w>", function() ui.nav_file(6) end)
map({ "n", "i" }, "<A-v>", function() ui.nav_file(7) end)
map({ "n", "i" }, "<A-z>", function() ui.nav_file(8) end)

View file

@ -0,0 +1,166 @@
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system {
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
}
end
vim.opt.rtp:prepend(lazypath)
local plugins
local function _2_()
local function _3_(_2410)
return _2410.add_default_mappings()
end
return _3_(require "leap")
end
plugins = {
----------------------
-- Misc / utilities --
----------------------
"nvim-tree/nvim-web-devicons", -- Icons
"tpope/vim-sleuth", -- Tab / Space detection
"tpope/vim-surround", -- Surround motions
"tpope/vim-fugitive", -- Git util
"windwp/nvim-autopairs", -- Pair symbols
"mbbill/undotree", -- Treeview of history
"godlygeek/tabular", -- Vertical alignment
"uga-rosa/ccc.nvim", -- Color picker
"stevearc/oil.nvim", -- File manager
-- `gc` to comment
{ "numToStr/Comment.nvim", opts = {} },
-- Jump anywhere
{
"ggandor/leap.nvim",
dependencies = "tpope/vim-repeat",
config = function() require "leap".add_default_mappings() end,
},
-- Folding
{
"kevinhwang91/nvim-ufo",
dependencies = "kevinhwang91/promise-async",
},
-- Generate `.gitignore`
{
"wintermute-cell/gitignore.nvim",
dependencies = "nvim-telescope/telescope.nvim",
},
----------------
-- Style / UI --
----------------
"folke/twilight.nvim", -- Zen mode
{ "shortcuts/no-neck-pain.nvim", version = "*" }, -- Align buffer
"lewis6991/gitsigns.nvim", -- Gitsigns in gutter
"NvChad/nvim-colorizer.lua", -- Show color
-- Jump like a ninja
{ "ThePrimeagen/harpoon", dependencies = "nvim-lua/plenary.nvim" },
-- Highlight comments
{ "folke/todo-comments.nvim", dependencies = "nvim-lua/plenary.nvim" },
-- Status line
"nvim-lualine/lualine.nvim",
-- Breadcrumbs
{ "SmiteshP/nvim-navic", dependencies = "neovim/nvim-lspconfig" },
---------------
-- LSP / DAP --
---------------
{
"neovim/nvim-lspconfig", -- (official) basic LSP Configuration & Plugins
dependencies = {
{ "j-hui/fidget.nvim", tag = "legacy" }, -- LSP Spinner
"folke/neodev.nvim", -- Additional lua configuration
},
},
"mfussenegger/nvim-dap", -- DAP
{ "ray-x/lsp_signature.nvim", event = "VeryLazy" },
-----------------------
-- Language specific --
-----------------------
"mfussenegger/nvim-jdtls",
{ "scalameta/nvim-metals", dependencies = "nvim-lua/plenary.nvim" },
{ "simrat39/rust-tools.nvim", dependencies = "neovim/nvim-lspconfig" },
{
"mrcjkb/rustaceanvim",
version = "^4",
ft = "rust",
},
{
"mrcjkb/haskell-tools.nvim",
dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" },
ft = { "haskell", "lhaskell", "cabal", "cabalproject" },
version = "^3",
lazy = false,
},
{
"kaarmu/typst.vim",
ft = "typst",
lazy = false,
},
{
"turbio/bracey.vim",
build = "npm install --prefix server",
},
{
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
dependencies = { "nvim-lua/plenary.nvim",
{
"nvim-telescope/telescope-fzf-native.nvim",
build = "make",
cond = (vim.fn.executable "make" == 1),
},
},
},
---------------
-- TreeSitter --
----------------
{
"nvim-treesitter/nvim-treesitter",
dependencies = "nvim-treesitter/nvim-treesitter-textobjects",
build = ":TSUpdate",
},
"nvim-treesitter/nvim-treesitter-context",
{ "nvim-treesitter/playground", enabled = false },
-----------
-- Games --
-----------
"ThePrimeagen/vim-be-good",
"Eandrju/cellular-automaton.nvim",
"wakatime/vim-wakatime",
------------------
-- Colorschemes --
------------------
"owickstrom/vim-colors-paramount",
{ "https://git.earth2077.fr/leana/curry.nvim", branch = "lua" },
----------------
-- Completion --
----------------
{
"hrsh7th/nvim-cmp", -- Autocompletion
dependencies = {
"L3MON4D3/LuaSnip", -- Snippet Engine
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp", -- LSP completion
"rafamadriz/friendly-snippets", -- Adds a number of user-friendly snippets
"hrsh7th/cmp-buffer", -- Buffer cmp Source
"f3fora/cmp-spell", -- Spell cmp source
"mrcjkb/haskell-snippets.nvim", -- Haskell snippets
},
},
}
local opts = { performance = { rtp = { reset = false } } }
require "lazy".setup(plugins, opts)

View file

@ -0,0 +1,305 @@
local map = vim.keymap.set
----------------------
-- Language servers --
----------------------
-- NOTE: put settings into `settings`
-- use another `on_attach` field if needed
local servers = {
bashls = {}, -- Bash
clangd = {}, -- C/CPP
cssls = {}, -- CSS
html = {}, -- HTML
jsonls = {}, -- JSON
lemminx = {}, -- XML
marksman = {}, -- Markdown
phpactor = {}, -- PHP
pylsp = {}, -- Python
pyright = {},
taplo = {}, -- TOML
texlab = {}, -- texlab
tsserver = {}, -- TypeScript
vimls = {}, -- Vim Script
ocamllsp = {}, -- OCaml
typst_lsp = { -- Typst
settings = {
root_dir =
vim.fs.dirname(vim.fs.find({ ".git" }, { upward = true })[1])
or vim.loop.cwd(),
exportPdf = "never",
},
on_attach = function(_, bufno)
map("n", "<leader>f", function()
vim.cmd ":w"
vim.cmd [[silent exec "!typstfmt %"]]
vim.cmd ":e"
end, { buffer = bufno })
end,
},
lua_ls = { -- Lua
settings = {
Lua = {
format = {
defaultConfig = {
-- Learn more:
-- https://github.com/CppCXY/EmmyLuaCodeStyle/blob/master/docs/format_config.md
indent_style = "space",
quote_style = "double",
call_arg_parentheses = "remove",
trailing_table_separator = "smart",
},
},
},
},
},
nil_ls = { -- Nix
on_attach = function(_, bufno)
vim.api.nvim_buf_set_option(bufno, "omnifunc", "v:lua.vim.lsp.omnifunc")
map("n", "<leader>f",
function()
vim.cmd ":w"
vim.cmd [[silent exec "!alejandra %"]]
vim.cmd ":e"
end,
{ buffer = bufno })
end,
},
}
-------------
-- Helpers --
-------------
local on_attach = function(client, bufno)
vim.api.nvim_buf_set_option(bufno, "omnifunc", "v:lua.vim.lsp.omnifunc")
local ts = require "telescope.builtin"
local opts = { buffer = bufno }
map("n", "K", vim.lsp.buf.hover, opts)
map("n", "<C-k>", vim.lsp.buf.signature_help, opts)
map("n", "gD", vim.lsp.buf.declaration, opts)
map("n", "gd", vim.lsp.buf.definition, opts)
map("n", "gtd", vim.lsp.buf.type_definition, opts)
map("n", "gi", vim.lsp.buf.implementation, opts)
map("n", "gu", ts.lsp_references, opts)
map("n", "<leader>ca", vim.lsp.buf.code_action, opts)
map("n", "<leader>cl", vim.lsp.codelens.run, opts)
map("n", "<leader>r", vim.lsp.buf.rename, opts)
map("n", "<leader>f", function() vim.lsp.buf.format { async = true } end, opts)
if client.server_capabilities.documentSymbolProvider then
require "nvim-navic".attach(client, bufno)
end
end
-- Helix style border
local border = {
{ " ", "FloatBorder" }, { " ", "FloatBorder" },
{ " ", "FloatBorder" }, { " ", "FloatBorder" },
{ " ", "FloatBorder" }, { " ", "FloatBorder" },
{ " ", "FloatBorder" }, { " ", "FloatBorder" },
}
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
opts.border = border
return orig_util_open_floating_preview(contents, syntax, opts, ...)
end
-- Type signature
require "lsp_signature".setup {
doc_lines = 7,
bind = true,
border = border,
hint_enable = false,
}
-- Diagnostic display configuration
vim.diagnostic.config { virtual_text = false, severity_sort = true }
-- Set log level
vim.lsp.set_log_level "off"
-- Gutter symbols setup
vim.fn.sign_define("DiagnosticSignError",
{ text = "E", texthl = "DiagnosticSignError", numhl = "DiagnosticSignError" })
vim.fn.sign_define("DiagnosticSignWarn", { text = "W", texthl = "DiagnosticSignWarn", numhl = "DiagnosticSignWarn" })
vim.fn.sign_define("DiagnosticSignHint", { text = "H", texthl = "DiagnosticSignHint", numhl = "DiagnosticSignHint" })
vim.fn.sign_define("DiagnosticSignInfo", { text = "·", texthl = "DiagnosticSignInfo", numhl = "DiagnosticSignInfo" })
-- Capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require "cmp_nvim_lsp".default_capabilities(capabilities)
----------
-- Init --
----------
require "fidget".setup { text = { spinner = "dots" } }
require "neodev".setup()
-- Folding
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
local handler = function(virtText, lnum, endLnum, width, truncate)
local newVirtText = {}
local suffix = (" 󰁂 %d "):format(endLnum - lnum)
local sufWidth = vim.fn.strdisplaywidth(suffix)
local targetWidth = width - sufWidth
local curWidth = 0
for _, chunk in ipairs(virtText) do
local chunkText = chunk[1]
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
if targetWidth > curWidth + chunkWidth then
table.insert(newVirtText, chunk)
else
chunkText = truncate(chunkText, targetWidth - curWidth)
local hlGroup = chunk[2]
table.insert(newVirtText, { chunkText, hlGroup })
chunkWidth = vim.fn.strdisplaywidth(chunkText)
-- str width returned from truncate() may less than 2nd argument, need padding
if curWidth + chunkWidth < targetWidth then
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
end
break
end
curWidth = curWidth + chunkWidth
end
table.insert(newVirtText, { suffix, "MoreMsg" })
return newVirtText
end
require "ufo".setup { fold_virt_text_handler = handler }
for k, v in pairs(servers) do
require "lspconfig"[k].setup {
capabilities = capabilities,
settings = v.settings,
on_attach = function(client, bufno)
on_attach(client, bufno)
v.on_attach(client, bufno)
end,
}
end
------------------------
-- Standalone plugins --
------------------------
-- Java
local config = {
on_attach = on_attach,
capabilities = capabilities,
cmd = {
-- https://github.com/NixOS/nixpkgs/issues/232822#issuecomment-1564243667
-- `-data` argument is necessary
"jdtls",
"-data", vim.fn.expand "~/.cache/jdtls" .. vim.fn.expand "%:p:h",
},
root_dir = vim.fs.dirname(vim.fs.find({ "gradlew", ".git", "mvnw" }, { upward = true })[1]),
}
local jdtls_group = vim.api.nvim_create_augroup("jdtls", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = { "java" },
callback = function()
require "jdtls".start_or_attach(config)
end,
group = jdtls_group,
})
-- Scala
local metals = require "metals"
local metals_config = metals.bare_config()
metals_config.capabilities = capabilities
metals_config.settings.useGlobalExecutable = true
require "dap".configurations.scala = {
{
type = "scala",
request = "launch",
name = "RunOrTest",
metals = { runType = "runOrTestFile" },
},
{
type = "scala",
request = "launch",
name = "Test Target",
metals = { runType = "testTarget" },
},
}
metals_config.on_attach = function(client, bufnr)
metals.setup_dap()
map("n", "<leader>ws", metals.hover_worksheet)
map("n", "<leader>dc", require "dap".continue)
map("n", "<leader>dr", require "dap".repl.toggle)
map("n", "<leader>dK", require "dap.ui.widgets".hover)
map("n", "<leader>dt", require "dap".toggle_breakpoint)
map("n", "<leader>dso", require "dap".step_over)
map("n", "<leader>dsi", require "dap".step_into)
map("n", "<leader>dl", require "dap".run_last)
on_attach(client, bufnr)
end
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt" },
callback = function()
require "metals".initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})
-- Haskell
vim.g.haskell_tools = {
tools = {
log = { level = vim.log.levels.OFF },
hover = {
border = border,
stylize_markdown = true,
},
},
hls = {
on_attach = function(client, bufnr)
local ht = require "haskell-tools"
local opts = { buffer = bufnr }
map("n", "<leader>hhe", ht.lsp.buf_eval_all, opts)
map("n", "<leader>hhs", ht.hoogle.hoogle_signature, opts)
map("n", "<leader>hhr", ht.repl.toggle, opts)
vim.opt_local.shiftwidth = 2
on_attach(client, bufnr)
end,
default_settings = {
haskell = {
-- formattingProvider = "fourmolu",
formattingProvider = "stylish-haskell",
cabalFormattingProvider = "cabal-fmt",
},
},
},
}
----------
-- Rust --
----------
vim.g.rustaceanvim = {
server = {
on_attach = on_attach,
settings = {
["rust-analyzer"] = { files = { excludeDirs = { ".direnv/" } } },
},
},
tools = {
hover = {
border = border,
stylize_markdown = true,
},
log = { level = vim.log.levels.OFF },
},
}

View file

@ -0,0 +1,70 @@
local function diagnostic_message()
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
local ds = vim.diagnostic.get(0, { lnum = row - 1 })
if #ds >= 1 then
return ds[1].message:gsub("%%", "%%%%");
else
return ""
end
end
local grey = {
a = { bg = "#e4e4e5" },
b = { bg = "#e4e4e5" },
c = { bg = "#e4e4e5" },
x = { bg = "#e4e4e5" },
y = { bg = "#e4e4e5" },
z = { bg = "#e4e4e5" },
}
local curry_theme = {
normal = grey,
insert = grey,
visual = grey,
replace = grey,
inactive = grey,
}
local sections = {
lualine_a = {},
lualine_b = {
{
"diagnostics",
colored = true,
symbols = { error = "E", warn = "W", info = "·", hint = "H" },
},
diagnostic_message,
},
lualine_c = { "navic" },
lualine_x = {},
lualine_y = {},
lualine_z = { "progress", "branch" },
}
require "lualine".setup {
options = {
icons_enabled = true,
theme = curry_theme,
component_separators = {},
section_separators = {},
disabled_filetypes = {
statusline = { "fugitive" },
winbar = { "fugitive" },
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
},
},
sections = sections,
inactive_sections = sections,
winbar = {},
inactive_winbar = {},
tabline = {},
extensions = {},
}

View file

@ -0,0 +1,6 @@
require "no-neck-pain".setup {
width = 75,
buffers = {
right = { enabled = false },
},
}

View file

@ -0,0 +1,32 @@
require "oil".setup {
default_file_explorer = false,
columns = {
-- "icon",
-- "permissions",
-- "size",
-- "mtime",
},
skip_confirm_for_simple_edits = true,
prompt_save_on_select_new_entry = false,
keymaps = {
["g?"] = "actions.show_help",
["<CR>"] = "actions.select",
["<C-v>"] = "actions.select_vsplit",
["<C-x>"] = "actions.select_split",
["<C-t>"] = "actions.select_tab",
["<C-p>"] = "actions.preview",
["<C-c>"] = "actions.close",
["<C-l>"] = "actions.refresh",
["-"] = "actions.parent",
["_"] = "actions.open_cwd",
["`"] = "actions.cd",
["~"] = "actions.tcd",
["gs"] = "actions.change_sort",
["gx"] = "actions.open_external",
["g."] = "actions.toggle_hidden",
["g\\"] = "actions.toggle_trash",
},
view_options = {
show_hidden = true,
},
}

View file

@ -0,0 +1,47 @@
local ts = require "telescope"
local actions = require "telescope.actions"
local themes = require "telescope.themes"
local config = require "telescope.config"
local builtin = require "telescope.builtin"
local map = vim.keymap.set
-- Clone the default Telescope configuration
local vimgrep_arguments = { unpack(config.values.vimgrep_arguments) }
table.insert(vimgrep_arguments, "--hidden") -- search hidden
table.insert(vimgrep_arguments, "--glob") -- ignore git
table.insert(vimgrep_arguments, "!**/.git/*")
ts.setup {
defaults = {
vimgrep_arguments = vimgrep_arguments,
mappings = {
i = {
["<esc>"] = actions.close,
},
},
},
pickers = {
find_files = {
find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" },
},
},
}
-- Enable telescope fzf native, if installed
pcall(require "telescope".load_extension, "fzf")
map("n", "<leader>/",
function()
builtin.current_buffer_fuzzy_find(themes.get_dropdown { previewer = false })
end
)
map("n", "<leader>sf", builtin.find_files)
map("n", "<leader>gf", builtin.git_files)
map("n", "<leader>?", builtin.help_tags)
map("n", "<leader>sw", builtin.grep_string)
map("n", "<leader>sg", builtin.live_grep)
map("n", "<leader>sd", builtin.diagnostics)
map("n", "<leader>b", builtin.buffers)
map("n", "<leader>sp", builtin.spell_suggest)

View file

@ -0,0 +1,11 @@
require "todo-comments".setup {
keywords = {
FIX = { icon = "", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" } },
TODO = { icon = "", color = "info" },
HACK = { icon = "!", color = "warning", alt = { "DEBUG" } },
WARN = { icon = "!", color = "warning", alt = { "WARNING", "XXX" } },
NOTE = { icon = "·", color = "hint", alt = { "INFO" } },
TEST = { icon = "T", color = "test", alt = { "TESTING", "PASSED", "FAILED" } },
Q = { icon = "?", color = "warning" },
},
}

View file

@ -0,0 +1,56 @@
require "nvim-treesitter.configs".setup {
ensure_installed = {},
sync_install = false,
auto_install = true,
highlight = { enable = true },
-- Disable for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
-- Text objets
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
},
selection_modes = {
["@parameter.outer"] = "v", -- charwise
["@function.outer"] = "V", -- linewise
["@class.outer"] = "<c-v>", -- blockwise
},
include_surrounding_whitespace = true,
},
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
},
}
require "treesitter-context".setup {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
max_lines = 2, -- How many lines the window should span. Values < = 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values < = 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to collapse for a single context line
trim_scope = "outer", -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = "topline", -- Line used to calculate context. Choices: 'cursor', 'topline'
zindex = 20, -- The Z-index of the context window
}

View file

@ -0,0 +1,15 @@
for _, name in ipairs {
"lazy",
"autopairs",
"cmp",
"colorizer",
"gitsigns",
"harpoon",
"lsp",
"lualine",
"no-neck-pain",
"oil",
"telescope",
"todo-comments",
"treesitter",
} do require("plugins._" .. name) end