diff --git a/common/neovim/coc-settings.json b/common/neovim/coc-settings.json deleted file mode 100644 index 9461396..0000000 --- a/common/neovim/coc-settings.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "coc.preferences.formatOnSaveFiletypes": ["elixir", "ex", "exs", "typescript", "css", "markdown", "sh", "bash"], - "languageserver": { - "nim": { - "command": "nimlsp", - "filetypes": ["nim"] - }, - "zls": { - "command": "~/zls/zls", - "filetypes": ["zig"] - }, - "godot": { - "host": "127.0.0.1", - "filetypes": ["gd", "gdscript3"], - "port": 6008 - } - }, - "elixir.pathToElixirLS": "~/.elixir-ls/release/language_server.sh", - "rust-analyzer.checkOnSave.command": "clippy", - "diagnostic-languageserver": { - "enable": true, - "mergeConfig": true, - "linters": { - "shellcheck": { - "command": "shellcheck", - "debounce": 100, - "args": [ - "-x", - "--format", - "json1", - "-" - ], - "sourceName": "shellcheck", - "parseJson": { - "errorsRoot": "comments", - "line": "line", - "column": "column", - "endLine": "endLine", - "endColumn": "endColumn", - "message": "${message} [${code}]", - "security": "level" - }, - "securities": { - "error": "error", - "warning": "warning", - "info": "info", - "style": "hint" - } - } - }, - "filetypes": { - "elixir": ["mix_credo", "mix_credo_compile"], - "eelixir": ["mix_credo", "mix_credo_compile"], - "sh": "shellcheck", - "bash": "shellcheck" - }, - "formatters": { - "shfmt": { - "command": "shfmt", - "args": ["-i", "2", "-bn", "-ci", "-sr", "-kp"] - } - }, - "formatFiletypes": { - "elixir": "mix_format", - "eelixir": "mix_format", - "sh": "shfmt", - "bash": "shfmt" - } - } -} - diff --git a/common/neovim/init.lua b/common/neovim/init.lua index add9d03..b57d79a 100644 --- a/common/neovim/init.lua +++ b/common/neovim/init.lua @@ -1,52 +1,7 @@ vim.g.vimdir = os.getenv('XDG_CONFIG_HOME') .. '/nvim' --- TODO: learn about the wildmenu `q:` --- TODO: what is `let &fcs = 'eob: '` for? - -require('plugins').setup() +require'plugins' require'options' require'keymap' -require('fold').setup() --- require('lsp').setup() -require('statusline').setup() - -function Dbg(a, d) - if d == nil then d = 0 end - if type(a) == 'table' then - local s = '{\n' - local indent = string.rep(' ', d) - for k,v in pairs(a) do - s = s .. ' ' .. indent .. tostring(k) .. '=' .. Dbg(v, d+1) .. '\n' - end - return s .. '\n' .. indent .. '}' - elseif type(a) == 'string' then - return a - elseif type(a) == 'number' then - return tostring(a) - else - return 'type:'..type(a)..',tostring:'..tostring(a) - end -end - -local plugin_setups = { - telescope = { - defaults = { - prompt_prefix = "", - mappings = {i = {['c-u'] = false, ['c-d'] = false}}, - generic_sorter = require('telescope.sorters').get_fzy_sorter, - file_sorter = require('telescope.sorters').get_fzy_sorter, - } - }, -} - -for k,v in pairs(plugin_setups) do - if type(v) == 'function' then - v(require(k)) - elseif type(v) == 'table' then - require(k).setup(v) - elseif type(v) == 'string' then - require(k)[v]() - elseif v == true then - require(k) - end -end +require'statusline' +require'lsp' diff --git a/common/neovim/lua/config.moon b/common/neovim/lua/config.moon deleted file mode 100644 index e69de29..0000000 diff --git a/common/neovim/lua/fold.lua b/common/neovim/lua/fold.lua index bd8bed5..e69de29 100644 --- a/common/neovim/lua/fold.lua +++ b/common/neovim/lua/fold.lua @@ -1,12 +0,0 @@ -function NeatFoldText() - -- TODO: finish this! - -- local lines_count = vim.foldend - vim.foldstart + 1 - -- local foldchar = vim.fn.matchstr(vim.fillchars, 'fold:\\zs.') - -- local foldtextstart = vim.fn.strpart('^' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3) - -- let foldtextend = printf("%s %".(winwidth(0)-20)."dL", foldtextstart, getline(v:foldstart), lines_count) - -- let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn - -- return printf("%s%d", substitute(getline(v:foldstart), "^.", ">"), lines_count) -end --- set foldtext=NeatFoldText() - -return {setup = function() end} diff --git a/common/neovim/lua/keymap.lua b/common/neovim/lua/keymap.lua index aa228b7..b62a651 100644 --- a/common/neovim/lua/keymap.lua +++ b/common/neovim/lua/keymap.lua @@ -7,33 +7,42 @@ local m = { } local keymap = { n = { + ['/'] = {':let @/ = "":', m.s}, + ['r'] = {':luafile ' .. vim.g.vimdir .. '/init.lua:echo \'Reloaded init.lua\'', m.s}, ['gv'] = {':e ' .. vim.g.vimdir .. '/init.lua', m.s}, + ['w'] = {':bd', m.s}, ['h'] = {':b#', m.s}, ['k'] = {':bnext', m.s}, ['j'] = {':bprevious', m.s}, - ['/'] = {':let @/ = "":', m.s}, + [''] = ':qa', + [''] = 'Telescope git_files', [''] = 'Telescope live_grep', [''] = 'Telescope buffers', ['t'] = 'Telescope help_tags', + [''] = ':TmuxNavigateLeft', [''] = ':TmuxNavigateDown', [''] = ':TmuxNavigateUp', [''] = ':TmuxNavigateRight', + [' n'] = "'Nn'[v:searchforward]", [' N'] = "'nN'[v:searchforward]", [''] = ':lua SynGroup()', - ['g]'] = '(coc-diagnostic-next)', - ['g['] = '(coc-diagnostic-prev)', }, + + -- terminal bindings t = {}, + [''] = { [''] = {'', m.sn}, + + -- remove trailing whitespace [''] = 'mw:%s/\\s\\+$//:let @/ = ""\'w', - [''] = ':setlocal spell!', + ['gs'] = ':setlocal spell!', [',w'] = {'CamelCaseMotion_w', m.s}, [',b'] = {'CamelCaseMotion_b', m.s}, [',e'] = {'CamelCaseMotion_e', m.s}, diff --git a/common/neovim/lua/lsp.lua b/common/neovim/lua/lsp.lua index e0c514b..d46268f 100644 --- a/common/neovim/lua/lsp.lua +++ b/common/neovim/lua/lsp.lua @@ -1,86 +1,64 @@ -local opts = {noremap=true, silent=true} +local lsp = require'lspconfig' +-- local coq = require'coq' -vim.api.nvim_set_keymap('n', '[g', '(coc-diagnostic-prev)', opts) -vim.api.nvim_set_keymap('n', ']g', '(coc-diagnostic-next)', opts) +-- TODO: replace with nvim lsp bindings for jumping to next linting issue? +--vim.api.nvim_set_keymap('n', '[d', ')', opts) -vim.api.nvim_set_keymap('n', 'gd', '(coc-definition)', opts) -vim.api.nvim_set_keymap('n', 'gy', '(coc-type-definition)', opts) +local opts = { + noremap = true, + silent = true, +} -local nvim_lsp = require('lspconfig') -local on_attach = function(_client, bufnr) - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - local kmaps = { - ['gD']='lua vim.lsp.buf.declaration()' - } +local on_attach = function(_, bufnr) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'e', 'lua vim.diagnostic.open_float()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'g]', 'lua vim.diagnostic.goto_next()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'g[', 'lua vim.diagnostic.goto_prev()', opts) - for k,v in pairs(kmaps) do - vim.api.nvim_buf_set_keymap(bufnr, 'n', k, v, opts) - end - - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts) end -local servers = {'clangd', 'rust_analyzer', 'pyright', 'tsserver'} -for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup{on_attach=on_attach} +local common_config = { + capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()), + on_attach = on_attach, + flags = { + debounce_text_changes = 150 + }, +} + +local lsp_configs = { + elixirls = { + cmd = { vim.fn.expand'~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' }, + }, + sumneko_lua = {}, + vimls = {}, + rust_analyzer = {}, + denols = {} +} + +for server, config in pairs(lsp_configs) do + for k,v in pairs(common_config) do config[k] = v end + lsp[server].setup(config) end -local sumneko_root_path = vim.fn.getenv('HOME')..'/.local/bin/sumneko_lua' -local sumneko_binary_path = '/bin/linux/lua-language-server' -nvim_lsp.sumneko_lua.setup{ - cmd={sumneko_root_path .. sumneko_binary_path, '-E', sumneko_root_path..'/main.lua'}; - on_attach=on_attach, - settings={ - Lua={ - runtime={ - version='LuaJIT', - path=vim.split(package.path, ';'), - }, - diagnostics={ - globals={'vim'}, - }, - workspace={ - library={ - [vim.fn.expand('$VIMRUNTIME/lua')] = true, - [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true, - }, - }, - }, - }, -} +local lsp_installer = require'nvim-lsp-installer' +lsp_installer.on_server_ready(function(server) + local server_opts = {} -vim.cmd "command! Format execute 'lua vim.lsp.buf.formatting()'" -vim.o.completeopt = 'menuone,noinsert' + -- if server.name == "elixirls" then + -- server_opts.cmd = { vim.fn.expand'~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' } + -- end ---[[require'compe'.setup{ - enabled=true, - autocomplete=true, - debug=false, - min_length=1, - preselect='enable', - throttle_time=80, - source_timeout=200, - incomplete_delay=400, - max_abbr_width=100, - max_kind_width=100, - max_menu_width=100, - documentation=true, - source={path=true, nvim_lsp=true}, -} -]]-- - -return { - setup=function() - end -} + server:setup(server_opts) +end) diff --git a/common/neovim/lua/nvim_lsp.lua b/common/neovim/lua/nvim_lsp.lua deleted file mode 100644 index db29563..0000000 --- a/common/neovim/lua/nvim_lsp.lua +++ /dev/null @@ -1,6 +0,0 @@ --- local completion = require('completion') -local lsp = require('lspconfig') - -lsp.elixirls.setup{} -lsp.sumneko_lua.setup{} -lsp.vimls.setup{} diff --git a/common/neovim/lua/options.lua b/common/neovim/lua/options.lua index 115e859..8e308ee 100644 --- a/common/neovim/lua/options.lua +++ b/common/neovim/lua/options.lua @@ -1,4 +1,8 @@ local globals = { + coq_settings = { + ['display.icons.mode'] = 'none' + }, + dashboard_default_executive = 'telescope', mapleader = ' ', maplocalleader = ' ', completion_enable_auto_popup = 0, @@ -81,9 +85,21 @@ function SynGroup() print(vim.fn.synIDattr(s, 'name') .. ' -> ' .. vim.fn.synIDattr(vim.fn.synIDtrans(s), 'name')) end -print(vim.api.nvim_exec([[ +vim.api.nvim_exec([[ au! TextYankPost * silent! lua vim.highlight.on_yank { higroup='Search', timeout=200 } au! FileType gitcommit exec 'norm gg' | startinsert! au! BufNewFile,BufRead *.slimleex set syntax=slime command! W write -]], true)) +]], true) +-- au! VimEnter * COQnow -s + +function NeatFoldText() + -- TODO: finish this! + -- local lines_count = vim.foldend - vim.foldstart + 1 + -- local foldchar = vim.fn.matchstr(vim.fillchars, 'fold:\\zs.') + -- local foldtextstart = vim.fn.strpart('^' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3) + -- let foldtextend = printf("%s %".(winwidth(0)-20)."dL", foldtextstart, getline(v:foldstart), lines_count) + -- let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn + -- return printf("%s%d", substitute(getline(v:foldstart), "^.", ">"), lines_count) +end +-- set foldtext=NeatFoldText() diff --git a/common/neovim/lua/plugins.lua b/common/neovim/lua/plugins.lua index df3e529..d5e0b75 100644 --- a/common/neovim/lua/plugins.lua +++ b/common/neovim/lua/plugins.lua @@ -1,48 +1,121 @@ -local setup = function() - local packer_install_path = vim.fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' - if #vim.fn.glob(packer_install_path) == 0 then - vim.fn.system {'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path} - vim.api.nvim_command'packadd packer.nvim' - end - - vim.g.polyglot_disabled = {'cue'} - - local packer = require'packer' - packer.startup(function() - local plugins = { - 'wbthomason/packer.nvim', - 'editorconfig/editorconfig-vim', - 'tpope/vim-sleuth', - 'vim-scripts/LargeFile', - 'vim-scripts/restore_view.vim', - 'christoomey/vim-tmux-navigator', - 'tpope/vim-fugitive', - 'tpope/vim-rhubarb', - 'tpope/vim-commentary', - 'tpope/vim-repeat', - 'machakann/vim-sandwich', - 'michaeljsmith/vim-indent-object', - 'wellle/targets.vim', - 'bkad/CamelCaseMotion', - 'ludovicchabant/vim-gutentags', - 'tpope/vim-obsession', - 'dhruvasagar/vim-prosession', - 'nvim-lua/popup.nvim', - 'nvim-lua/plenary.nvim', - {'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}}, - -- 'joshdick/onedark.vim', - 'lukas-reineke/indent-blankline.nvim', - -- {'lewis6991/gitsigns.nvim', requires = {'nvim-lua/plenary.nvim'}}, - 'neovim/nvim-lspconfig', - 'hrsh7th/nvim-compe', - 'jjo/vim-cue', - 'sheerun/vim-polyglot', - {'neoclide/coc.nvim', branch = 'release'}, - } - for _,plugin in ipairs(plugins) do - packer.use(plugin) - end - end) +local packer_install_path = vim.fn.stdpath'data' .. '/site/pack/packer/start/packer.nvim' +if #vim.fn.glob(packer_install_path) == 0 then + vim.fn.system{'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path} + vim.api.nvim_command'packadd packer.nvim' end -return {setup = setup} +local packer = require'packer' +packer.startup(function() + local plugins = { + 'wbthomason/packer.nvim', -- neovim plugin manager + + 'vim-scripts/LargeFile', -- degrade gracefully with large files + 'tpope/vim-repeat', -- enable repeat for plugin maps + 'tpope/vim-sleuth', -- use whatever whitespace is in the file + 'editorconfig/editorconfig-vim', -- handle .editorconfig files + 'christoomey/vim-tmux-navigator', -- navigate vim splits and tmux panes fluidly + 'machakann/vim-sandwich', -- edit surrounding characters + 'michaeljsmith/vim-indent-object', -- adds indent-level text objects + 'wellle/targets.vim', -- add many other text objects + 'bkad/CamelCaseMotion', -- invaluable motions for properly operating on various casings + + { + -- session management + 'olimorris/persisted.nvim', + config = function() + -- TODO: only load session if no arguments passed? + require'persisted'.setup{ + autoload = true, + } + end + }, + { + -- toggle comments + 'terrortylor/nvim-comment', + config = function() + require'nvim_comment'.setup() + end + }, + { + -- fuzzy finder + 'nvim-telescope/telescope.nvim', + requires = { + 'nvim-lua/popup.nvim', + 'nvim-lua/plenary.nvim', + } + }, + -- TODO: add keymap ig for toggling these + 'lukas-reineke/indent-blankline.nvim', -- indentation guide lines + 'neovim/nvim-lspconfig', + 'williamboman/nvim-lsp-installer', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + { + 'hrsh7th/nvim-cmp', + config = function() + local cmp = require'cmp' + + cmp.setup{ + mapping = { + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.mapping{ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }, + [''] = cmp.mapping.confirm{select = true}, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }, + sources = cmp.config.sources{ + { name = 'nvim_lsp' }, + { name = 'buffer' }, + }, + } + + cmp.setup.cmdline('/', { + sources = { + {name = 'buffer'}, + } + }) + + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + {name = 'path'} + }, { + {name = 'cmdline'} + }) + }) + end, + }, + -- TODO: automate this installation process of :COQdeps:COQnow + -- {'ms-jpq/coq_nvim', branch = 'coq'}, + -- {'ms-jpq/coq.thirdparty', branch = '3p'}, + { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate', + config = function() + require'nvim-treesitter.configs'.setup { + ensure_installed = "maintained", + sync_install = false, + ignore_install = {}, + indent = { + enable = true, + }, + highlight = { + enable = true, + disable = {}, + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + -- additional_vim_regex_highlighting = false, + }, + } + end + }, + } + for _,plugin in pairs(plugins) do packer.use(plugin) end +end) diff --git a/common/neovim/lua/statusline.lua b/common/neovim/lua/statusline.lua index 5bc66c5..c5061d1 100644 --- a/common/neovim/lua/statusline.lua +++ b/common/neovim/lua/statusline.lua @@ -73,8 +73,4 @@ function StatusLine() return status_line_buffers() .. '%*%=%c,%l/%L (%p%%)' end -return { - setup=function() - vim.o.statusline = '%!v:lua.StatusLine()' - end -} +vim.o.statusline = '%!v:lua.StatusLine()'