nvim-config

Log | Files | Refs | Submodules | README

commit 747ae64f13cad81cdaa4cf41a9ae88975d3731e8
parent 839125cd97f9d5e240cf81299688361df780b13a
Author: Thomas Vigouroux <tomvig38@gmail.com>
Date:   Wed,  8 Sep 2021 09:18:26 +0200

Update

Diffstat:
Mafter/ftplugin/c.vim | 3++-
Aafter/ftplugin/fennel.vim | 1+
Mafter/ftplugin/help.vim | 2+-
Aafter/ftplugin/markdown.lua | 11+++++++++++
Dafter/ftplugin/markdown.vim | 5-----
Mafter/plugin/config/nvim-lsp.vim | 12+-----------
Mafter/plugin/mappings.vim | 15++++++---------
Mafter/plugin/statusline.vim | 24++++--------------------
Minit.lua | 19++++++++++++++-----
Mlua/completree-config.lua | 129++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mlua/lsp_config.lua | 82++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mlua/mappings.lua | 13++-----------
Alua/neogit-config.lua | 8++++++++
Mlua/plugins.lua | 40++++++++++++++++++++--------------------
Mlua/tele_config.lua | 3---
Mlua/ts_config.lua | 2+-
Aplugin/zest.lua | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
17 files changed, 308 insertions(+), 113 deletions(-)

diff --git a/after/ftplugin/c.vim b/after/ftplugin/c.vim @@ -1,4 +1,4 @@ -" Last Change: 2021 Aug 03 +" Last Change: 2021 Aug 20 setlocal expandtab setlocal textwidth=80 " Nvim uses this @@ -8,6 +8,7 @@ setlocal foldexpr=nvim_treesitter#foldexpr() setlocal foldlevel=0 setlocal omnifunc=v:lua.vim.lsp.omnifunc setlocal comments^=:/// +setlocal commentstring=//%s if !empty(findfile('.clang-format', ';')) setlocal formatprg=clang-format\ -style=file diff --git a/after/ftplugin/fennel.vim b/after/ftplugin/fennel.vim @@ -0,0 +1 @@ +set lisp diff --git a/after/ftplugin/help.vim b/after/ftplugin/help.vim @@ -1,3 +1,3 @@ set colorcolumn= autocmd BufWritePost *.txt helptags %:h - +set nowrap diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua @@ -0,0 +1,11 @@ +vim.cmd[[setlocal textwidth=70]] +vim.cmd[[setlocal nowrap]] +vim.cmd[[compiler mdpdf]] + + +if #(vim.fn.system{ 'zest', 'search', string.format('file:%s', vim.fn.expand"%:p")}) ~= 0 then + vim.api.nvim_buf_set_keymap(0, 'n', '<Leader>r', '<cmd>ZestRefs<CR>', { noremap=true, silent=true }) + vim.api.nvim_buf_set_keymap(0, 'n', 'gf', ':ZestGoto file:<C-R><C-W><CR>', { noremap=true, silent=true }) + + vim.cmd[[au BufWritePost <buffer> :silent! !zest update]] +end diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim @@ -1,5 +0,0 @@ -" Last Change: 2021 Jan 20 - -setlocal textwidth=70 -setlocal nowrap -compiler mdpdf diff --git a/after/plugin/config/nvim-lsp.vim b/after/plugin/config/nvim-lsp.vim @@ -1,14 +1,4 @@ -" Last Change: 2021 Aug 04 +" Last Change: 2021 Sep 03 " Utility to store lsp/completion config lua require'lsp_config' - -nnoremap <silent> <Leader>d <cmd>lua vim.lsp.buf.definition()<CR> -nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR> -nnoremap <silent> <C-S-K> <cmd>lua vim.lsp.buf.signature_help()<CR> -nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR> -nnoremap <silent> gr <cmd>lua vim.lsp.buf.rename()<CR> -nnoremap <silent> gR <cmd>lua vim.lsp.buf.references()<CR> -nnoremap <silent> <Leader>= <cmd>lua vim.lsp.buf.formatting_sync()<CR> - -autocmd CursorHold,CursorHoldI *.rs lua vim.lsp.diagnostic.show_line_diagnostics{focusable=false} diff --git a/after/plugin/mappings.vim b/after/plugin/mappings.vim @@ -1,21 +1,18 @@ -" Last Change: 2021 Aug 02 +" Last Change: 2021 Sep 03 vnoremap <silent> < <gv vnoremap <silent> > >gv +nnoremap <silent> Q @@ + nnoremap <silent> yq :copen<CR> nnoremap <silent> yQ :cclose<CR> -inoremap <expr><CR> pumvisible() ? "\<C-y>" : "\<CR>" +inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" -imap <expr><TAB> v:lua.tab_complete() +imap <expr> <TAB> v:lua.tab_complete() snoremap <silent> <Tab> <cmd>lua require('luasnip').jump(1)<Cr> -" -"imap <expr><S-TAB> v:lua.s_tab_complete() -"smap <expr><S-TAB> v:lua.s_tab_complete() - -nnoremap <expr>K v:lua.K_help_hover() -imap <expr><S-Tab> pumvisible() ? "\<C-P>" : "\<S-TAB>" +imap <expr> <S-Tab> pumvisible() ? "\<C-P>" : "\<S-TAB>" nnoremap ' ` nnoremap ` ' diff --git a/after/plugin/statusline.vim b/after/plugin/statusline.vim @@ -1,27 +1,11 @@ -" Last Change: 2020 Nov 19 - -function! GitFileSummary() abort - if ! exists('b:gitgutter') - return "" - else - let l:git_summary = GitGutterGetHunkSummary() - return "+".l:git_summary[0] . " ~".l:git_summary[1] . " -".l:git_summary[2] - endif -endfunction - -" Statusline -function! LspStatus() abort - " if luaeval('#vim.lsp.buf_get_clients() > 0') - " return luaeval("require('lsp-status').status()") - " endif - return '' -endfunction - +" Last Change: 2021 Sep 08 function! StatusLineActive() let l:status = "%-6.{mode(6)}\ " let l:status .= "%<%.50f%m\ " - let l:status .= "%y%q%w%{ObsessionStatus()}%12.{GitFileSummary()}\ %{LspStatus()}%=" + let l:status .= "%y%q%w" + let l:status .= "%=" + let l:status .= "%-20.(%8.{get(b:,'gitsigns_head','')}%12.{get(b:,'gitsigns_status','')}%)\ " let l:status .= "%16.(%10.(%l/%LL%),\ %-5.(%c%V%)%)" let l:status .= "\ %10.P" diff --git a/init.lua b/init.lua @@ -1,5 +1,7 @@ local M = {} +require'impatient'.enable_profile() + vim.g.python_host_prog = "/bin/python" if jit.os == "Linux" then @@ -14,7 +16,6 @@ o.number = true o.relativenumber = true o.showmode = false o.hidden = true -o.cursorline = true o.termguicolors = true o.splitright = true o.lazyredraw = true @@ -23,7 +24,7 @@ o.spelllang = { "en", "fr" } o.spellfile = vim.fn.stdpath("config") .. "/spell/correct.UTF-8.add" o.textwidth = 100 o.colorcolumn = "+0" -o.signcolumn = "yes:2" +o.signcolumn = "number" o.scrolloff = 5 o.winblend = 10 o.updatetime = 500 @@ -32,6 +33,12 @@ o.cursorline = false o.mouse = "n" o.previewheight = 10 o.title = true +o.cursorline = true +o.cursorlineopt = { "number" } +o.wrap = true +o.linebreak = true +o.breakindent = true +o.showbreak = "> " -- Completion and ui o.inccommand = "nosplit" @@ -48,6 +55,7 @@ o.listchars = { o.tags = ".tags;/" o.undofile = true o.grepprg = "rg --vimgrep" +o.grepformat = "%f:%l:%c:%m" -- Conceal o.conceallevel = 1 @@ -65,12 +73,13 @@ o.sessionoptions:remove "buffers" vim.g.mapleader = " " vim.g.maplocalleader = "&" -vim.api.nvim_command [[language time POSIX]] +vim.cmd [[au TextYankPost * silent! lua vim.highlight.on_yank{higroup="Visual", timeout=250}]] +vim.cmd [[language en_US.utf8]] +vim.cmd [[language time POSIX]] -- Now load plugins and such -vim.api.nvim_command"packadd packer.nvim" require "plugins" -- Load all plugins -require "colorizer".setup() require "mappings" +require "neogit-config" return M diff --git a/lua/completree-config.lua b/lua/completree-config.lua @@ -1,10 +1,43 @@ -local comp = require"completree" -local s = require"completree.sources" +local comp = require"complementree" +local s = require"complementree.sources" +local api = vim.api + +local function zest_complete(_, _, preffix, _) + local query + if preffix and #preffix ~= 0 then + query = string.format("file:%s", preffix) + else + query = "*" + end + local files = vim.fn.systemlist{"zest", "search", query } + + + local ret = {} + for _, fname in ipairs(files) do + local fullpath, title = unpack(vim.split(fname, ':', true)) + table.insert(ret, { + word = vim.fn.fnamemodify(fullpath, ":p:t"), + menu = title, + kind = "F" + }) + end + + return ret +end + +local function md_complete(...) + local fullpath = vim.fn.expand "%:p" + if #(vim.fn.system{ 'zest', 'search', string.format('file:%s', fullpath)}) ~= 0 then + s.wrap(zest_complete)(...) + else + s.ins_completion("C-F")(...) + end +end local lsp_completion = { default = s.lsp, string = s.ins_completion "C-F", - comment = s.dummy + comment = s.luasnip, } comp.setup { @@ -12,5 +45,93 @@ comp.setup { vim = s.ins_completion "C-V", c = lsp_completion, lua = lsp_completion, - rust = lsp_completion + rust = lsp_completion, + ocaml = lsp_completion, + + -- For git commit and text only do luasnip + gitcommit = s.luasnip, + text = s.luasnip, + markdown = md_complete +} + +-- Luasnip config +local ls = require("luasnip") +-- some shorthands... +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local l = require("luasnip.extras").lambda +local r = 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 types = require("luasnip.util.types") + +local function convcommit_snippet(type) + return { + t(type .. '('), i(1, "scope"), t '): ', + i(2, "title"), + t { "", "", "" }, -- close previous line, open blank, open next + i(0, "body") + } +end + +local comment_tag = (function() + local regex_escape = { + ["-"] = "%-", + ["%"] = "%%", + } + + return function(_, _, kind) + -- TODO(vigoux): Only works for preffix only commentstring + local cmt = api.nvim_buf_get_option(0, 'commentstring') + local curline = api.nvim_get_current_line() + + local preffix + local reg = string.format(cmt, ".*$"):gsub(".", regex_escape) + print(reg) + if curline:match(reg) then + -- Already commented + preffix = t(kind .. "(vigoux): ") + else + preffix = t(string.format(cmt, " " .. kind .. "(vigoux): ")) + end + + return sn(nil, { + preffix, + i(1, "content") + }) + end +end)() + +ls.snippets = { + all = { + s("todo", { d(1, comment_tag, {}, "TODO") }), + s("fixme", { d(1, comment_tag, {}, "FIXME") }), + }, + gitcommit = { + s({ trig = "coauth", name = "Co Author", dscr = "A git co-author"}, { + t "Co-authored-by: ", i(1, "name"), t" <", i(2, "email"), t">" + }), + s({ trig = "fix", name = "Fix message", dscr = "Fix without scope or breaking" }, convcommit_snippet"fix"), + s({ trig = "feat", name = "Feature message", dscr = "Feature without scope or breaking" }, convcommit_snippet"feat"), + s({ trig = "chore", name = "Chore change", dscr = "An update or whatever" }, convcommit_snippet "chore") + }, + text = { + s({ trig = "ts", dscr = "Tree-sitter test case"}, { + t { "", "=====================", ""}, + i(1, "Title"), + t{ "", "=====================", "" }, + i(2, "Body"), + t { "", "---------------" } + }) + }, + lua = { + s('lreq', { t 'local ', dl(2, l._1:match '[^.]+$', 1), t " = require'", i(1), t { "'", '' } }), + } } diff --git a/lua/lsp_config.lua b/lua/lsp_config.lua @@ -1,29 +1,66 @@ -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true +local lsp = require'lspconfig' -vim.cmd[[packadd nvim-lsp]] +vim.cmd[[packadd nvim-lspconfig]] +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + -- Enable underline, use default values + underline = true, + virtual_text = true, + -- Disable a feature + update_in_insert = false, + severity_sort = true + } +) -local nvim_lsp = require'lspconfig' -local protocol = require'vim.lsp.protocol' +local function on_attach(client, bufnr) + local function buf_set_keymap(lhs, rhs) + vim.api.nvim_buf_set_keymap(bufnr, 'n', lhs, string.format("<cmd>lua %s<CR>", rhs), + { noremap=true, silent=true }) + end + -- Mappings. +-- autocmd CursorHold,CursorHoldI *.rs lua vim.lsp.diagnostic.show_line_diagnostics{focusable=false} + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('gD', 'vim.lsp.buf.implementation()') + buf_set_keymap('<Leader>d', 'vim.lsp.buf.definition()') + buf_set_keymap('K', 'vim.lsp.buf.hover()') + buf_set_keymap('<C-S-K>', 'vim.lsp.buf.signature_help()') + buf_set_keymap('gr', 'vim.lsp.buf.rename()') + buf_set_keymap('<Leader>a', 'vim.lsp.buf.code_action()') + buf_set_keymap('[d', 'vim.lsp.diagnostic.goto_prev()') + buf_set_keymap(']d', 'vim.lsp.diagnostic.goto_next()') + buf_set_keymap('<Leader>l', 'vim.lsp.diagnostic.set_loclist()') + buf_set_keymap('<Leader>q', 'vim.lsp.diagnostic.set_qflist()') + buf_set_keymap('<Leader>=', 'vim.lsp.buf.formatting()') + buf_set_keymap('gR', 'require"telescope.builtin".lsp_references()') + buf_set_keymap('<Leader>s', 'require"telescope.builtin".lsp_dynamic_workspace_symbols()') --- Not sure this is useful -nvim_lsp.util.default_config = vim.tbl_extend( - "force", - nvim_lsp.util.default_config, - { log_level = vim.lsp.protocol.MessageType.Info } -) + vim.api.nvim_buf_call(bufnr, function() + vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.diagnostic.show_line_diagnostics{focusable = false}]] + vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]] + vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]] + end) +end -nvim_lsp.ccls.setup{ capabilities = capabilities } -nvim_lsp.als.setup{ capabilities = capabilities } -nvim_lsp.rust_analyzer.setup{ capabilities = capabilities } -nvim_lsp.ghcide.setup{ capabilities = capabilities } -nvim_lsp.tsserver.setup{ capabilities = capabilities } -nvim_lsp.pylsp.setup { capabilities = capabilities } +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true +local default_lsps = { + 'ccls', + 'als', + 'rust_analyzer', + 'ghcide', + 'pylsp', + 'ocamllsp', +} + +for _,lname in ipairs(default_lsps) do + lsp[lname].setup { capabilities = capabilities, on_attach = on_attach } +end local sumneko_root_path = vim.fn.expand('$HOME')..'/src/lua-language-server' local sumneko_binary = sumneko_root_path.."/bin/Linux/lua-language-server" -require'lspconfig'.sumneko_lua.setup { +lsp.sumneko_lua.setup { + on_attach = on_attach, cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}; settings = { Lua = { @@ -53,8 +90,8 @@ require'lspconfig'.sumneko_lua.setup { } -- texlab -local function texlab_attach() - protocol.SymbolKind = { +local function texlab_attach(client, bufnr) + vim.lsp.protocol.SymbolKind = { 'file'; 'sec'; 'fold'; @@ -82,7 +119,7 @@ local function texlab_attach() 'part'; 'coll'; } - protocol.CompletionItemKind = { + vim.lsp.protocol.CompletionItemKind = { 'string'; ''; ''; @@ -109,9 +146,10 @@ local function texlab_attach() 'part'; 'collect'; } + on_attach(client, bufnr) end -nvim_lsp.texlab.setup{ +lsp.texlab.setup{ cmd = {vim.fn.expand("$HOME") ..'/.cargo/bin/texlab'}, on_attach = texlab_attach, } diff --git a/lua/mappings.lua b/lua/mappings.lua @@ -10,20 +10,11 @@ local call = vim.api.nvim_call_function function tab_complete() if vim.fn.pumvisible() == 1 then return rt '<C-N>' - elseif vim.api.nvim_get_current_line():match("^%s+$") then + elseif vim.api.nvim_get_current_line():match("^%s*$") then return rt '<Tab>' elseif luasnip.jumpable(1) then return rt '<Plug>luasnip-jump-next' else - return rt '<Plug>(completree-complete)' - end -end - --- Help -function K_help_hover() - if vim.tbl_isempty(vim.lsp.buf_get_clients(0)) then - return "K" - else - return rt("<cmd>lua vim.lsp.buf.hover()<CR>") + return rt '<Plug>(complementree-complete)' end end diff --git a/lua/neogit-config.lua b/lua/neogit-config.lua @@ -0,0 +1,8 @@ +local gitsigns = require'gitsigns' + +gitsigns.setup { + current_line_blame = true, + current_line_blame_opts = { + delay = 1000, + } +} diff --git a/lua/plugins.lua b/lua/plugins.lua @@ -6,8 +6,8 @@ local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path) - execute 'packadd packer.nvim' end +execute 'packadd packer.nvim' return require"packer".startup(function(use) @@ -42,32 +42,18 @@ return require"packer".startup(function(use) -- use { 'neovim/nvimdev.nvim', requires = {'neomake/neomake'}} - -- Running things - use {'tpope/vim-dispatch', opt = true, keys = {'m<CR>', '`<CR>'}, cmd = {'Make', 'Dispatch'}} - -- tpope <3 - use 'tpope/vim-obsession' use 'tpope/vim-commentary' use 'tpope/vim-surround' -- LSP related use 'neovim/nvim-lspconfig' + use 'nvim-lua/lsp-status.nvim' -- Treesitter related localuse 'nvim-treesitter/nvim-treesitter' - use 'nvim-treesitter/nvim-tree-docs' use 'nvim-treesitter/playground' - -- experiments for treesitter - use 'bakpakin/fennel.vim' - use 'Olical/aniseed' - localuse 'vigoux/ratatoskr.nvim' - - -- Filetypes - use 'cespare/vim-toml' - use 'PProvost/vim-ps1' - use 'tamarin-prover/editors' - -- Mine use 'vigoux/templar.nvim' use { 'vigoux/LanguageTool.nvim', opt = true } @@ -75,13 +61,27 @@ return require"packer".startup(function(use) -- Misc localuse 'vim-conf-live/pres.vim' localuse 'vigoux/architext.nvim' - localuse 'vigoux/mem.nvim' - localuse 'vigoux/scope-tree' - localuse 'vigoux/completree' + localuse 'vigoux/complementree.nvim' + localuse { 'vigoux/ratatoskr.nvim', opt = true } use 'L3MON4D3/LuaSnip' - use 'norcalli/nvim-colorizer.lua' use 'bfredl/luarefvim' -- lua docs from nvim + use { 'norcalli/nvim-colorizer.lua', config = function () + require'colorizer'.setup() + end} + use 'lewis6991/impatient.nvim' + use { "steelsojka/pears.nvim", config = function() + require "pears".setup() + end } + + -- Git because git + use { 'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' } } -- One true colorscheme localuse 'vigoux/oak' -- Not sure it is that binary + + -- Byte update debugging help + use 'tjdevries/nsync.nvim' + + -- sunjon <3 + use 'sunjon/extmark-toy.nvim' end) diff --git a/lua/tele_config.lua b/lua/tele_config.lua @@ -24,9 +24,6 @@ map('n', '<Leader>oc', lua_call('telescope.builtin', 'find_files', { cwd = '/hom map('n', '<Leader>b', lua_call('telescope.builtin', 'buffers')) map('n', '<Leader>q', lua_call('telescope.builtin', 'quickfix')) map('n', '<Leader>r', lua_call('telescope.builtin', 'live_grep')) -map('n', 'gR', lua_call('telescope.builtin', 'lsp_references')) -map('n', '<Leader>a', lua_call('telescope.builtin', 'lsp_code_actions')) -map('n', '<Leader>S', lua_call('tele-config', 'workspace_symbols')) map('n', 'z=', lua_call('telescope.builtin', 'spell_suggest')) local sorters = require'telescope.sorters' diff --git a/lua/ts_config.lua b/lua/ts_config.lua @@ -28,5 +28,5 @@ require'nvim-treesitter.configs'.setup { } }, playground = { enable = true }, - ensure_installed = {'rust', 'c', 'lua', 'query', 'fennel', 'python'} -- one of 'all', 'language', or a list of languages + ensure_installed = {'rust', 'c', 'lua', 'query', 'fennel', 'python', 'vim', 'bash'} -- one of 'all', 'language', or a list of languages } diff --git a/plugin/zest.lua b/plugin/zest.lua @@ -0,0 +1,52 @@ +local api = vim.api + +local M = {} + +local function zest(...) + return vim.fn.systemlist{'zest', ...} +end + +function Zest_create() + local fname = (zest 'create')[1] + vim.cmd(string.format("edit %s", fname)) + + vim.cmd[[autocmd BufUnload <buffer> !zest update]] +end + +local function set_qflist_with(res) + local qflist = {} + for _,r in ipairs(res) do + local filename, title = unpack(vim.split(r, ':', true)) + table.insert(qflist, { + filename = filename, + text = title + }) + end + + vim.fn.setqflist(qflist, 'r') + vim.cmd[[copen]] +end + +function Zest_refs() + local fname = vim.fn.expand("%:p") + local refs = zest('search', string.format("ref:%s", fname)) + set_qflist_with(refs) +end + +function Zest_search(query) + set_qflist_with(zest('search', query)) +end + +function Zest_goto(query) + local res = zest('search', query)[1] + if not res then return end + + vim.cmd(string.format("edit %s", vim.split(res, ':', true)[1])) +end + +vim.cmd[[command! ZestCreate lua Zest_create()]] +vim.cmd[[command! ZestRefs lua Zest_refs()]] +vim.cmd[[command! -nargs=1 ZestSearch lua Zest_search(<f-args>)]] +vim.cmd[[command! -nargs=1 ZestGoto lua Zest_goto(<f-args>)]] + +return M