Nvim: Update config from tarneaux/.f

This commit is contained in:
risitas@cocinero 2024-01-07 11:36:18 +01:00
parent 57b534219b
commit 8c2b1b6d52
2 changed files with 335 additions and 62 deletions

View File

@ -33,7 +33,7 @@ vim.opt.termguicolors = true
require("lazy").setup({
-- Gruvbox colorscheme
{
"morhetz/gruvbox",
"ellisonleao/gruvbox.nvim",
init = function()
vim.cmd [[colorscheme gruvbox]]
end
@ -53,18 +53,39 @@ require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
dependencies = {
'windwp/nvim-ts-autotag'
'windwp/nvim-ts-autotag',
'nvim-treesitter/nvim-treesitter-textobjects',
},
init = function ()
require('orgmode').setup_ts_grammar()
require'nvim-treesitter.configs'.setup {
ensure_installed = {"c", "lua", "rust", "markdown", "yaml", "bash"},
ensure_installed = {"c", "lua", "rust", "python", "javascript", "typescript", "markdown", "yaml", "org", "nix", "html", "css", "scss", "bash", "haskell", "arduino", "latex", "svelte"},
highlight = {
enable = true,
additional_vim_regex_highlighting = {"org", "python"},
},
autotag = {
enable = true,
}
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
},
},
},
}
-- Enable folding
vim.opt.foldmethod = "expr"
-- Enable folding based on treesitter
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
-- Prevent automatic folding
vim.opt.foldlevel = 99
end
},
-- LSP (completion, diagnostics, etc)
@ -72,12 +93,40 @@ require("lazy").setup({
"neovim/nvim-lspconfig",
init = function ()
local lspconfig = require("lspconfig")
local servers = {"pyright", "bashls", "jsonls", "lua_ls", "yamlls"}
local servers = {"clangd", "rust_analyzer", "pyright", "bashls", "html", "jsonls", "astro", "rust_analyzer", "lua_ls", "hls", "eslint", "ansiblels", "yamlls"}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup{
capabilities = require("cmp_nvim_lsp").default_capabilities(),
}
end
-- arduino_language_server specific setup
lspconfig.arduino_language_server.setup{
cmd = { "arduino-language-server", "--fqbn", "esp32:esp32:XIAO_ESP32C3" },
capabilities = require("cmp_nvim_lsp").default_capabilities(),
}
-- texlab specific setup
lspconfig.texlab.setup{
cmd = { "texlab" },
filetypes = { "tex", "bib", "markdown" },
capabilities = require("cmp_nvim_lsp").default_capabilities(),
}
require("which-key").register({
["<leader>l"] = {
name = "LSP actions",
a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code action" },
d = { "<cmd>lua vim.lsp.buf.definition()<cr>", "Go to definition" },
D = { "<cmd>lua vim.lsp.buf.declaration()<cr>", "Go to declaration" },
i = { "<cmd>lua vim.lsp.buf.implementation()<cr>", "Go to implementation" },
r = { "<cmd>lua vim.lsp.buf.references()<cr>", "Go to references" },
R = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
h = { "<cmd>lua vim.lsp.buf.hover()<cr>", "Hover" },
H = { "<cmd>lua vim.lsp.buf.signature_help()<cr>", "Signature help" },
s = { "<cmd>lua vim.lsp.buf.document_symbol()<cr>", "Document symbols" },
S = { "<cmd>lua vim.lsp.buf.workspace_symbol()<cr>", "Workspace symbols" },
t = { "<cmd>lua vim.lsp.buf.type_definition()<cr>", "Go to type definition" },
x = { "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>", "Show line diagnostics" },
}
})
end
},
-- cmp (autocomplete)
@ -85,47 +134,75 @@ require("lazy").setup({
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"saadparwaiz1/cmp_luasnip",
},
init = function ()
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then return false end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line-1, 0, line-1, col, {})[1]:match("^%s*$") == nil
end
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
["<C-CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump()
else fallback() end
local luasnip = require("luasnip")
if cmp.visible() and has_words_before() then
cmp.select_next_item()
-- elseif luasnip.expand_or_jumpable() then
-- luasnip.expand_or_jump()
else
fallback()
end
end, {"i", "s"}),
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "orgmode" },
{ name = "buffer" },
{ name = "luasnip" }
},
})
end
},
-- Luasnip (snippets)
"L3MON4D3/LuaSnip",
-- Luasnip: snippets
{
"L3MON4D3/LuaSnip",
dependencies = {
"rafamadriz/friendly-snippets",
},
init = function ()
-- local luasnip = require("luasnip")
-- luasnip.config.set_config({
-- history = true,
-- updateevents = "TextChanged,TextChangedI",
-- })
require("luasnip/loaders/from_vscode").load()
end
},
-- trouble: show errors with :Trouble
{
'folke/trouble.nvim',
init = function ()
require("which-key").register({
["<space>t"] = { ":TroubleToggle<cr>", "Open/close Trouble" },
["<leader>T"] = { ":TroubleToggle<cr>", "Open/close Trouble" },
})
end
},
@ -138,9 +215,47 @@ require("lazy").setup({
local wk = require('which-key')
wk.setup{}
wk.register({
["<space>"] = {
["<leader>"] = {
w = { ":w<cr>", "Save" },
q = { ":q<cr>", "Quit" },
e = { ":Explore<cr>", "Netrw" },
O = {
name = "Options",
t = {
function ()
local width = vim.ui.input({ prompt = 'Set tab width to: '}, function (input)
if not input then
return
end
input = tonumber(input)
vim.opt.shiftwidth = input
vim.opt.tabstop = input
vim.opt.softtabstop = input
end)
end,
"Set tab width for current buffer"
},
c = {
function ()
if vim.opt.colorcolumn:get()[1] == "81" then
vim.opt.colorcolumn = ""
else
vim.opt.colorcolumn = "81"
end
end,
"toggle colorcolumn between none and 81 for current buffer",
},
w = {
function ()
if vim.opt.textwidth:get() == 0 then
vim.opt.textwidth = 80
else
vim.opt.textwidth = 0
end
end,
"toggle text width for current buffer",
},
},
}
})
end
@ -151,32 +266,28 @@ require("lazy").setup({
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-lua/popup.nvim",
"joaomsa/telescope-orgmode.nvim",
},
init = function()
local telescope = require("telescope")
-- Telescope orgmode integration: search headings and refile
telescope.load_extension("orgmode")
require("which-key").register({
["<space>f"] = {
name = "Find",
f = {"<cmd>Telescope find_files<cr>", "Find files"},
g = {"<cmd>Telescope live_grep<cr>", "Find in files"},
b = {"<cmd>Telescope buffers<cr>", "Find buffers"},
h = {"<cmd>Telescope help_tags<cr>", "Find help"},
["<leader>t"] = {
name = "Go to",
f = {"<cmd>Telescope find_files<cr>", "Files in project"},
g = {"<cmd>Telescope live_grep<cr>", "Text (grep)"},
b = {"<cmd>Telescope buffers<cr>", "Open buffers"},
h = {"<cmd>Telescope help_tags<cr>", "Vim help pages"},
m = {"<cmd>Telescope man_pages<cr>", "Manpages"},
s = {"<cmd>Telescope treesitter<cr>", "Treesitter symbols"},
r = {"<cmd>Telescope lsp_references<cr>", "References (under cursor)"},
d = {"<cmd>Telescope lsp_definitions<cr>", "Jump to definition (under cursor)"},
c = {"<cmd>Telescope lsp_code_actions<cr>", "Code actions (under cursor)"},
}
})
end
},
-- NvimTree: file explorer
{
"nvim-tree/nvim-tree.lua",
init = function ()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
require("which-key").register({
["<space>e"] = { ":NvimTreeToggle<cr>", "Open/close NvimTree" },
})
end,
opts = {}
},
-- change project root to git root
"airblade/vim-rooter",
-- Git helper
@ -184,7 +295,7 @@ require("lazy").setup({
"tpope/vim-fugitive",
init = function ()
require("which-key").register({
["<space>g"] = {
["<leader>g"] = {
name = "Git",
c = { "<cmd>Git commit<cr>", "Commit" },
a = { "<cmd>Git add " .. vim.fn.expand('%:p') .. "<cr>", "Stage current file" },
@ -192,7 +303,8 @@ require("lazy").setup({
u = { "<cmd>Git restore --staged " .. vim.fn.expand('%:p') .. "<cr>", "Unstage current file" },
p = { "<cmd>Git push<cr>", "Push" },
s = { "<cmd>Git status<cr>", "Status" },
d = { "<cmd>Git diff<cr>", "Diff" },
-- d = { "<cmd>Git diff<cr>", "Diff" },
d = { "<cmd>Telescope git_status<cr>", "Diff" }, -- I think the telescope version is a bit more usable
r = { "<cmd>Git restore ".. vim.fn.expand('%:p') .."<cr>", "Restore current file" },
R = { "<cmd>Git restore --patch ".. vim.fn.expand('%:p') .."<cr>", "Restore current file selectively" },
}
@ -202,7 +314,8 @@ require("lazy").setup({
-- Gitgutter
{
"lewis6991/gitsigns.nvim",
opts = {}
opts = {
}
},
-- Auto close brackets that aren't annoying (= closing already closed brackets)
{
@ -212,12 +325,70 @@ require("lazy").setup({
},
-- Automatically add, change, and remove pairs of quotes, brackets, etc.
"tpope/vim-surround",
-- orgmode
{
"nvim-orgmode/orgmode",
opts = {
org_agenda_files = {"~/org/**"},
org_default_notes_file = "~/org/refile.org",
org_todo_keywords = {"DOING", "TODO", "NEXT", "LATER", "TOREAD", "TOWRITE", "WAITING", "DONE"},
org_hide_emphasis_markers = true,
-- Org ellipsis with a chevron
org_ellipsis = "",
org_indent_mode = "noindent",
org_archive_location = "~/org/archive.org::/",
org_blank_before_new_entry = {heading = false, plain_list_item = false},
},
init = function ()
require("which-key").register({
["<leader>o"] = {
name = "Org",
r = { "<cmd>Telescope orgmode refile_heading<cr>", "org refile to heading" },
s = { "<cmd>Telescope orgmode search_headings<cr>", "org search" },
}
})
-- We need to enable conceal for org_hide_emphasis_markers to work
vim.cmd [[ au FileType org setlocal conceallevel=3 ]]
end
},
-- prettier orgmode bullets
{
"akinsho/org-bullets.nvim",
opts = {
symbols = {
headlines = {"*"},
},
concealcursor = true
}
},
-- orgmode and markdown tables. See the repo's README for more info
{
"dhruvasagar/vim-table-mode",
init = function ()
-- Enable table mode in orgmode
vim.cmd [[ au FileType org silent TableModeEnable ]]
-- Same for markdown
vim.cmd [[ au FileType markdown silent TableModeEnable ]]
-- According to my tests there is no problem with other filetypes, even when
-- opening a non-org file after an org file.
end
},
-- Easily comment/decomment code
"tpope/vim-commentary",
-- Automatically detect tab/space indentation
"tpope/vim-sleuth",
-- Fountain (screenplay magkup language) support
"kblin/vim-fountain",
{
"kblin/vim-fountain",
},
-- True zen: distraction-free writing
{
"Pocco81/TrueZen.nvim",
opts = {},
init = function ()
require("which-key").register({
["<leader>z"] = { "<cmd>TZAtaraxis<cr>", "Zen mode" },
})
end
},
-- Rust integration
{
"rust-lang/rust.vim",
@ -225,6 +396,27 @@ require("lazy").setup({
vim.g.rustfmt_autosave = 1
end
},
-- Leap.nvim: jump to any word in the buffer
{
"ggandor/leap.nvim",
dependencies = {
"tpope/vim-repeat"
},
init = function ()
require('leap').add_default_mappings()
end
},
-- Editorconfig: parse .editorconfig files
"editorconfig/editorconfig-vim",
-- DiffView: see git diffs
{
"sindrets/diffview.nvim",
init = function ()
require("which-key").register({
["<leader>d"] = { "<cmd>DiffviewOpen<cr>", "Open diffview" },
})
end
},
})
@ -250,6 +442,10 @@ vim.opt.undodir = vim.fn.stdpath("cache") .. "/undo"
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.expandtab = true
-- Use two spaces for indentation when editing HTML, TS, JS, CSS, SCSS.
vim.cmd [[ au FileType html,typescript,javascript,css,scss,typescriptreact setlocal shiftwidth=2 tabstop=2 softtabstop=2 ]]
-- Enable mouse support just in case I turn into a normie (magic!)
vim.opt.mouse = "a"
@ -261,8 +457,75 @@ vim.opt.clipboard = "unnamedplus"
vim.opt.wrap = true
vim.opt.linebreak = true
-- Bind S to replace every occurence (normal mode)
vim.cmd [[map S :%s//g<Left><Left>]]
vim.opt.scrolloff = 2
-- Add french to spellcheck and keep english
-- For this we need to add the classic vim RTP (for neovim to find the spell files)
vim.opt.runtimepath:append("/usr/share/vim/vimfiles/")
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown,org",
callback = function ()
vim.opt.spelllang:append("fr")
end
})
-- When editing a git commit message, org or markdown file, enable spellcheck
vim.api.nvim_create_autocmd("FileType", {
pattern = "gitcommit,markdown,org",
callback = function ()
vim.opt.spell = true
end
})
-- When editing a git commit message, set the textwidth and colorcolumn to the recommended values
vim.api.nvim_create_autocmd("Filetype", {
pattern = "gitcommit",
callback = function ()
vim.opt.textwidth = 72
vim.opt.colorcolumn = "73"
end
})
-- python formatter
vim.api.nvim_create_autocmd("Filetype", {
pattern = "python",
callback = function ()
vim.keymap.set("n", "<leader>f", ":!black %<cr>", {desc = "Format python file"})
end
})
-- <leader>s to search and replace
vim.keymap.set("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/g<Left><Left>]], {desc = "Search and replace"})
-- Case insensitive
vim.keymap.set("n", "<leader>S", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]], {desc = "Search and replace (case insensitive)"})
-- <leader>p to paste in visual & select modes without changing the register
vim.keymap.set("x", "<leader>p", '"_dP')
-- Shift+Up/Down to move lines
vim.keymap.set("n", "<S-Up>", "<cmd>m .-2<cr>==")
vim.keymap.set("n", "<S-Down>", "<cmd>m .+1<cr>==")
-- Shift+Up/Down to move selected lines in visual mode
vim.keymap.set("x", "<S-Up>", ":move'<-2<CR>gv=gv")
vim.keymap.set("x", "<S-Down>", ":move'>+1<CR>gv=gv")
-- Add signature at bottom of email files
vim.api.nvim_create_autocmd("Filetype", {
pattern = "mail",
callback = function ()
vim.keymap.set("n", ",s", function () vim.cmd [[ :r ~/.config/aerc/signature.txt ]] end, { buffer = true })
end
})
vim.g.pyindent_open_paren = "shiftwidth()"
-- Enable colorcolumn in all programming files
vim.api.nvim_create_autocmd("Filetype", {
pattern = "python,html,css,scss,typescript,javascript,rust,sh,lua",
callback = function ()
vim.opt.colorcolumn = "81"
end
})
-- When editing a commit message, set the textwidth to 79, spellcheck, wrap and colorcolumn
vim.cmd [[ au FileType gitcommit setlocal textwidth=79 spell wrap colorcolumn=80 ]]

View File

@ -1,27 +1,37 @@
{
"LuaSnip": { "branch": "master", "commit": "6085dfd1808fb0059e13d160317a10c3a68c5407" },
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"gitsigns.nvim": { "branch": "main", "commit": "2272cf9f0c092e908f892f5b075e6cc2a8d3d07d" },
"gruvbox": { "branch": "master", "commit": "f1ecde848f0cdba877acb0c740320568252cc482" },
"lazy.nvim": { "branch": "main", "commit": "59335c5b9d116f5d3948f833288a89e2a829a005" },
"lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" },
"nvim-autopairs": { "branch": "master", "commit": "de4f7138a68d5d5063170f2182fd27faf06b0b54" },
"nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" },
"nvim-lspconfig": { "branch": "master", "commit": "361a2878a41f23452457eec12a807ff59bc75882" },
"nvim-tree.lua": { "branch": "master", "commit": "7dcda5d3b6d2fce7b7baa471b7ad6525383e27bb" },
"nvim-treesitter": { "branch": "master", "commit": "812c2dd8fe838bb26cb53f0d251116468c2cae37" },
"nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" },
"nvim-web-devicons": { "branch": "master", "commit": "45d0237c427baba8cd05e0ab26d30e2ee58c2c82" },
"plenary.nvim": { "branch": "master", "commit": "9ce85b0f7dcfe5358c0be937ad23e456907d410b" },
"LuaSnip": { "branch": "master", "commit": "2f0db89fcb22d27b908b3609d2441c02798106ab" },
"TrueZen.nvim": { "branch": "main", "commit": "2b9e210e0d1a735e1fa85ec22190115dffd963aa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" },
"editorconfig-vim": { "branch": "master", "commit": "95cb75e21d11206dad4bd3895c99459bdaa13dd1" },
"friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
"gitsigns.nvim": { "branch": "main", "commit": "3e6e91b09f0468c32d3b96dcacf4b947f037ce25" },
"gruvbox.nvim": { "branch": "main", "commit": "4176b0b720db0c90ab4030e5c1b4893faf41fd51" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"leap.nvim": { "branch": "main", "commit": "b63f14d7474002573710d10f02f1af33a4910490" },
"lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" },
"nvim-autopairs": { "branch": "master", "commit": "9fd41181693dd4106b3e414a822bb6569924de81" },
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
"nvim-lspconfig": { "branch": "master", "commit": "796394fd19fb878e8dbc4fd1e9c9c186ed07a5f4" },
"nvim-treesitter": { "branch": "master", "commit": "5032f9952ad2a3a7f7792ac438c4f9e2bd53e0b9" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "85b9d0cbd4ff901abcda862b50dbb34e0901848b" },
"nvim-ts-autotag": { "branch": "main", "commit": "8515e48a277a2f4947d91004d9aa92c29fdc5e18" },
"nvim-web-devicons": { "branch": "master", "commit": "db0c864375c198cacc171ff373e76bfce2a85045" },
"org-bullets.nvim": { "branch": "main", "commit": "6e0d60e901bb939eb526139cb1f8d59065132fd9" },
"orgmode": { "branch": "master", "commit": "c60cf77031a5a9a3c590c6f7b876bc7117603e57" },
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
"popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" },
"rust.vim": { "branch": "master", "commit": "889b9a7515db477f4cb6808bef1769e53493c578" },
"telescope.nvim": { "branch": "master", "commit": "8c69f58427f98b2ca39a90a36db830c06e30351c" },
"trouble.nvim": { "branch": "main", "commit": "3f85d8ed30e97ceeddbbcf80224245d347053711" },
"telescope-orgmode.nvim": { "branch": "main", "commit": "eabff061c3852a9aa94e672a7d2fa4a1ef63f9e2" },
"telescope.nvim": { "branch": "master", "commit": "87e92ea31b2b61d45ad044cf7b2d9b66dad2a618" },
"trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" },
"vim-commentary": { "branch": "master", "commit": "e87cd90dc09c2a203e13af9704bd0ef79303d755" },
"vim-fountain": { "branch": "master", "commit": "4464261ce6f173e5c2dab54b34a2860102c27d25" },
"vim-fugitive": { "branch": "master", "commit": "99db68d9b3304580bd383da7aaee05c7a954a344" },
"vim-fugitive": { "branch": "master", "commit": "59659093581aad2afacedc81f009ed6a4bfad275" },
"vim-repeat": { "branch": "master", "commit": "24afe922e6a05891756ecf331f39a1f6743d3d5a" },
"vim-rooter": { "branch": "master", "commit": "1353fa47ee3a81083c284e28ff4f7d92655d7c9e" },
"vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" },
"vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" },
"which-key.nvim": { "branch": "main", "commit": "7ccf476ebe0445a741b64e36c78a682c1c6118b7" }
"vim-table-mode": { "branch": "master", "commit": "4ff8de2ac93431ee6d85a9e04177012752e6abdc" },
"which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }
}