From 3c280675d8910bcc731a2521d9232274be8c9c0e Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 13 Jun 2022 23:44:08 -0500 Subject: [PATCH] Hopefully fix neovim config --- common/neovim/colors/base16-donokai.vim | 1 - common/neovim/ftplugin/nim.vim | 1 - common/neovim/init.lua | 564 +++++++++++++++++++++++- common/neovim/lua/fold.lua | 0 common/neovim/lua/keymap.lua | 79 ---- common/neovim/lua/lsp.lua | 92 ---- common/neovim/lua/options.lua | 105 ----- common/neovim/lua/plugins.lua | 192 -------- common/neovim/lua/statusline.lua | 86 ---- 9 files changed, 559 insertions(+), 561 deletions(-) delete mode 120000 common/neovim/colors/base16-donokai.vim delete mode 100644 common/neovim/ftplugin/nim.vim delete mode 100644 common/neovim/lua/fold.lua delete mode 100644 common/neovim/lua/keymap.lua delete mode 100644 common/neovim/lua/lsp.lua delete mode 100644 common/neovim/lua/options.lua delete mode 100644 common/neovim/lua/plugins.lua delete mode 100644 common/neovim/lua/statusline.lua diff --git a/common/neovim/colors/base16-donokai.vim b/common/neovim/colors/base16-donokai.vim deleted file mode 120000 index 3af3c64..0000000 --- a/common/neovim/colors/base16-donokai.vim +++ /dev/null @@ -1 +0,0 @@ -/home/daniel/.home/.config/lytedev-dotfiles/common/colors/vim \ No newline at end of file diff --git a/common/neovim/ftplugin/nim.vim b/common/neovim/ftplugin/nim.vim deleted file mode 100644 index d5a9f89..0000000 --- a/common/neovim/ftplugin/nim.vim +++ /dev/null @@ -1 +0,0 @@ -set expandtab diff --git a/common/neovim/init.lua b/common/neovim/init.lua index b57d79a..f5a9e07 100644 --- a/common/neovim/init.lua +++ b/common/neovim/init.lua @@ -1,7 +1,561 @@ vim.g.vimdir = os.getenv('XDG_CONFIG_HOME') .. '/nvim' -require'plugins' -require'options' -require'keymap' -require'statusline' -require'lsp' +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.cmd 'packadd packer.nvim' +end + +local has_words_before = function() + local line, col = 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 + +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() + local should_autoload = #vim.v.argv >= 1 + require 'persisted'.setup { + autoload = should_autoload, + autosave = should_autoload, + } + 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', + } + }, + { + 'nvim-telescope/telescope-fzf-native.nvim', + run = 'make', + }, + { + 'tzachar/cmp-fuzzy-path', + requires = { 'hrsh7th/nvim-cmp', 'tzachar/fuzzy.nvim' }, + }, + + -- TODO: add keymap ig for toggling these + 'lukas-reineke/indent-blankline.nvim', -- indentation guide lines + 'L3MON4D3/LuaSnip', + + { + -- completion engine + 'hrsh7th/nvim-cmp', + config = function() + local cmp = require 'cmp' + local luasnip = require 'luasnip' + + --[[ + local prev_item = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end + + local next_item = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end + ]] -- + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + window = { + }, + 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.n + [''] = cmp.mapping { + i = cmp.mapping.close, + c = cmp.mapping.close, + }, + [''] = cmp.mapping.confirm { select = false }, + -- [""] = cmp.mapping(next_item, { "i", "s" }), + -- [""] = cmp.mapping(prev_item, { "i", "s" }), + -- [''] = cmp.mapping(next_item, { "i", "s" }), + -- [''] = cmp.mapping(prev_item, { "i", "s" }), + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'nvim_lsp_signature_help' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + { name = 'path' }, + { name = 'fuzzy_path' }, + }), + formatting = { + format = require("lspkind").cmp_format { + with_text = true, + menu = { + nvim_lsp = "[LSP]", + }, + } + }, + } + + cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' }, + { name = 'fuzzy_path' }, + } + }) + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + end, + }, + 'neovim/nvim-lspconfig', -- language server configuration helper + 'williamboman/nvim-lsp-installer', -- plugin containing installation commands for many language servers + 'hrsh7th/cmp-nvim-lsp-signature-help', + 'hrsh7th/cmp-nvim-lsp', -- add lsp to completion engine + 'hrsh7th/cmp-buffer', -- add buffer information to completion engine + 'hrsh7th/cmp-path', -- add filesystem information to complete enging + 'hrsh7th/cmp-cmdline', -- add completion for vim commands + 'onsails/lspkind-nvim', + 'saadparwaiz1/cmp_luasnip', + -- TODO: automate this installation process of :COQdeps:COQnow + -- {'ms-jpq/coq_nvim', branch = 'coq'}, + -- {'ms-jpq/coq.thirdparty', branch = '3p'}, + { + -- syntax highlighting and indentation + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate', + config = function() + require 'nvim-treesitter.configs'.setup { + ensure_installed = "all", + sync_install = false, + ignore_install = { "phpdoc" }, + 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 + }, + 'lukas-reineke/lsp-format.nvim', + } + for _, plugin in pairs(plugins) do packer.use(plugin) end +end) + +local globals = { + mapleader = ' ', + maplocalleader = ' ', + -- skipview_files = { 'COMMIT_EDITMSG' }, + indent_blankline_char = '▏', + indent_blankline_filetype_exclude = { 'help', 'packer' }, + indent_blankline_buftype_exclude = { 'terminal', 'nofile' }, + indent_blankline_char_highlight = 'LineNr', +} +for k, v in pairs(globals) do vim.g[k] = v end + +local options = { + clipboard = 'unnamedplus', + inccommand = 'nosplit', + tabstop = 2, + softtabstop = 2, + shiftwidth = 2, + smartindent = true, + list = true, + listchars = 'trail:·,tab: ', + linebreak = true, + formatoptions = 'crql1jn', + synmaxcol = 200, + lazyredraw = true, + scrolloff = 8, + sidescrolloff = 15, + mouse = 'a', + splitright = true, + splitbelow = true, + errorbells = false, + visualbell = true, + backup = false, + writebackup = false, + swapfile = false, + timeout = true, + timeoutlen = 150, + hidden = true, + shortmess = 'filnxToOFIac', + history = 1000, + undofile = true, + undodir = vim.fn.stdpath 'data' .. '/undo', + undolevels = 1000, + undoreload = 1000, + spellfile = vim.fn.stdpath 'data' .. '/spell/en.utf-8.add', + ignorecase = true, + smartcase = true, + incsearch = true, + wrapscan = true, + hlsearch = true, + foldmethod = 'syntax', + foldlevel = 99, + foldnestmax = 10, + foldlevelstart = 99, + autowrite = false, + autochdir = false, + autoread = true, + modeline = false, + showmode = false, + showcmd = false, + laststatus = 2, + ruler = false, + number = true, + -- cmdheight = 0, +} +for k, v in pairs(options) do + vim.o[k] = v +end + +vim.api.nvim_command 'colorscheme donokai' + +function SynGroup() + local s = vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1) + -- TODO: instead of printing, put it in a popup? virtual text? + print(vim.fn.synIDattr(s, 'name') .. ' -> ' .. vim.fn.synIDattr(vim.fn.synIDtrans(s), 'name')) +end + +vim.api.nvim_create_autocmd("TextYankPost", { + pattern = "*", + callback = function() + vim.highlight.on_yank { higroup = 'Search', timeout = 200 } + end, +}) + +vim.api.nvim_create_autocmd("FileType", { + pattern = "gitcommit", + callback = function() + vim.cmd 'startinsert' + end, +}) + +vim.cmd 'command! W write' + +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() + +for _, keys in ipairs { 'jj', 'jJ', 'Jj', 'JJ', 'jk', 'jK', 'Jk', 'JK' } do + vim.api.nvim_set_keymap('i', keys, '', {}) +end + +local m = { + s = { silent = true }, + n = { noremap = true }, + sn = { silent = true, noremap = true }, +} +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 }, + + [''] = ':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()', + + ['s'] = "SessionToggleecho 'Persisting Session: ' .. g:persisting .. ' (' .. getcwd() .. ')'", + ['S'] = "SessionSaveecho 'Saved Session: ' .. getcwd()", + ['l'] = "SessionLoadecho 'Loaded Session: ' .. getcwd()", + ['L'] = "SessionLoadLastecho 'Loaded Last Session: ' .. getcwd()", + ['d'] = "SessionDeleteecho 'Deleted Session for cwd: ' .. getcwd()", + }, + + -- terminal bindings + t = {}, + + [''] = { + [''] = { '', m.sn }, + + -- remove trailing whitespace + [''] = 'mw:%s/\\s\\+$//:let @/ = ""\'w', + ['gs'] = ':setlocal spell!', + [',w'] = { 'CamelCaseMotion_w', m.s }, + [',b'] = { 'CamelCaseMotion_b', m.s }, + [',e'] = { 'CamelCaseMotion_e', m.s }, + [',ge'] = { 'CamelCaseMotion_ge', m.s }, + }, + o = { + ['ib'] = { 'CamelCaseMotion_ib', m.s }, + ['ie'] = { 'CamelCaseMotion_ie', m.s }, + }, + x = { + ['<'] = ''] = '>gv', + ['ib'] = { 'CamelCaseMotion_ib', m.s }, + ['ie'] = { 'CamelCaseMotion_ie', m.s }, + }, + i = { + [''] = '', + }, +} +for mode, mappings in pairs(keymap) do + for key, bind in pairs(mappings) do + if type(bind) == 'table' then + vim.api.nvim_set_keymap(mode, key, bind[1], bind[2]) + else + vim.api.nvim_set_keymap(mode, key, bind, {}) + end + end +end + +local status_line_max_length = 5 + +-- TODO: only update this portion when needed instead of every render? +local status_line_buffer_by_num = function(bufnum) + local is_active = false + local bufinfo = vim.fn.getbufinfo(bufnum)[1] + local prefix = ' %#InactiveBuffer#' + local suffix = '%* ' + + if bufinfo.changed == 1 then + prefix = '%#DirtyBuffer# ' + suffix = ' %*' + end + + local windex = vim.fn.index(bufinfo.windows, vim.g.statusline_winid) + if bufinfo.hidden and windex >= 0 then + is_active = true + prefix = '%#ActiveBuffer# ' + suffix = ' %*' + if bufinfo.changed == 1 then + prefix = '%#ActiveDirtyBuffer# *' + suffix = ' %*' + end + end + + return (prefix .. vim.fn.fnamemodify(vim.fn.bufname(bufnum), ':t') .. suffix), is_active +end + +local status_line_buffers = function() + local active_index = -1 + local acc = {} + for _, bufnum in ipairs(vim.api.nvim_list_bufs()) do + local bufinfo = vim.fn.getbufinfo(bufnum)[1] + if bufinfo.listed ~= 0 then + local entry, is_active = status_line_buffer_by_num(bufnum) + table.insert(acc, entry) + if is_active then + active_index = #acc + end + end + end + if active_index >= 0 then + local offset = status_line_max_length / 2 + local min_buf_num = math.max(0, (active_index - offset)) + local max_buf_num = math.min(#acc - 1, min_buf_num + status_line_max_length - 1) + min_buf_num = math.max(0, max_buf_num - status_line_max_length + 1) + local buflist = table.concat({ unpack(acc, min_buf_num + 1, max_buf_num + 1) }, '') + local prefix = '' + local suffix = '' + if min_buf_num > 0 then + prefix = '< ' + end + if max_buf_num < (#acc - 1) then + suffix = ' >' + end + return prefix .. buflist .. suffix + else + local suffix = '' + if #acc - 1 > status_line_max_length then + suffix = ' >' + end + local buflist = table.concat({ unpack(acc, 1, math.min(#acc, status_line_max_length)) }, '') + return buflist .. suffix .. active_index + end +end + +local whitespace = function() + local result = "" + if vim.o.expandtab == true then + result = result .. vim.o.shiftwidth .. "S" + else + result = result .. vim.o.tabstop .. "T" + end + return result +end + +function StatusLine() + return status_line_buffers() .. '%*%=%{&filetype} %l;%c (%p%%/%L) ' .. whitespace() +end + +vim.o.statusline = '%!v:lua.StatusLine()' + +local lsp = require 'lspconfig' +-- local coq = require'coq' + +local lsp_format = require 'lsp-format' + +local on_attach = function(client, bufnr) + lsp_format.on_attach(client) + + local lsp_mappings = { + ['n'] = { + ['e'] = 'vim.diagnostic.open_float()', + [''] = 'vim.lsp.buf.signature_help()', + ['gi'] = 'vim.lsp.buf.implementation()', + ['K'] = 'vim.lsp.buf.hover()', + ['gd'] = 'vim.lsp.buf.definition()', + ['gD'] = 'vim.lsp.buf.declaration()', + ['g['] = 'vim.diagnostic.goto_prev()', + ['g]'] = 'vim.diagnostic.goto_next()', + ['wa'] = 'vim.lsp.buf.add_workspace_folder()', + ['wr'] = 'vim.lsp.buf.remove_workspace_folder()', + ['wl'] = 'print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', + ['D'] = 'vim.lsp.buf.type_definition()', + ['rn'] = 'vim.lsp.buf.rename()', + ['ca'] = 'vim.lsp.buf.code_action()', + ['gr'] = 'vim.lsp.buf.references()', + ['f'] = 'vim.lsp.buf.formatting_seq_sync()', + } + } + + for mode, mappings in pairs(lsp_mappings) do + for keys, script in pairs(mappings) do + vim.api.nvim_buf_set_keymap(bufnr, mode, keys, 'lua ' .. script .. '', m.sn) + end + end +end + +--[[ + +set els_path ~/.local/share/nvim/lsp_servers/elixir +curl -fLO https://github.com/elixir-lsp/elixir-ls/releases/latest/download/elixir-ls.zip +mkdir -p $els_path +unzip elixir-ls.zip -d $els_path/elixir-ls/ +chmod +x $els_path/elixir-ls/language_server.sh + +]] -- + +local lsp_configs = { + gopls = {}, + elixirls = { + cmd = { vim.fn.expand '~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' }, + settings = { + elixirLS = { + dialyzerEnabled = true, + fetchDeps = false, + } + } + }, + sumneko_lua = { + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } + }, + vimls = {}, + rust_analyzer = {}, + -- tsserver = {}, + pylsp = {}, + denols = { + root_dir = lsp.util.root_pattern("deno.json"), + }, +} + +local capabilities = require 'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()) +local common_config = { + capabilities = capabilities, + on_attach = on_attach, + flags = { + debounce_text_changes = 150 + }, +} + +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 + +require 'nvim-lsp-installer'.setup { + automatic_installation = true, +} diff --git a/common/neovim/lua/fold.lua b/common/neovim/lua/fold.lua deleted file mode 100644 index e69de29..0000000 diff --git a/common/neovim/lua/keymap.lua b/common/neovim/lua/keymap.lua deleted file mode 100644 index 414ae64..0000000 --- a/common/neovim/lua/keymap.lua +++ /dev/null @@ -1,79 +0,0 @@ -for _, keys in ipairs { 'jj', 'jJ', 'Jj', 'JJ', 'jk', 'jK', 'Jk', 'JK' } do vim.api.nvim_set_keymap('i', keys, '', {}) end - -local m = { - s = { silent = true }, - n = { noremap = true }, - sn = { silent = true, noremap = true }, -} -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 }, - - [''] = ':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()', - - ['s'] = "SessionToggleecho 'Persisting Session: ' .. g:persisting .. ' (' .. getcwd() .. ')'", - ['S'] = "SessionSaveecho 'Saved Session: ' .. getcwd()", - ['l'] = "SessionLoadecho 'Loaded Session: ' .. getcwd()", - ['L'] = "SessionLoadLastecho 'Loaded Last Session: ' .. getcwd()", - ['d'] = "SessionDeleteecho 'Deleted Session for cwd: ' .. getcwd()", - }, - - -- terminal bindings - t = {}, - - [''] = { - [''] = { '', m.sn }, - - -- remove trailing whitespace - [''] = 'mw:%s/\\s\\+$//:let @/ = ""\'w', - ['gs'] = ':setlocal spell!', - [',w'] = { 'CamelCaseMotion_w', m.s }, - [',b'] = { 'CamelCaseMotion_b', m.s }, - [',e'] = { 'CamelCaseMotion_e', m.s }, - [',ge'] = { 'CamelCaseMotion_ge', m.s }, - }, - o = { - ['ib'] = { 'CamelCaseMotion_ib', m.s }, - ['ie'] = { 'CamelCaseMotion_ie', m.s }, - }, - x = { - ['<'] = ''] = '>gv', - ['ib'] = { 'CamelCaseMotion_ib', m.s }, - ['ie'] = { 'CamelCaseMotion_ie', m.s }, - }, - i = { - [''] = '', - }, -} -for mode, mappings in pairs(keymap) do - for key, bind in pairs(mappings) do - if type(bind) == 'table' then - vim.api.nvim_set_keymap(mode, key, bind[1], bind[2]) - else - vim.api.nvim_set_keymap(mode, key, bind, {}) - end - end -end diff --git a/common/neovim/lua/lsp.lua b/common/neovim/lua/lsp.lua deleted file mode 100644 index 7c27933..0000000 --- a/common/neovim/lua/lsp.lua +++ /dev/null @@ -1,92 +0,0 @@ -local lsp = require 'lspconfig' --- local coq = require'coq' - --- TODO: replace with nvim lsp bindings for jumping to next linting issue? ---vim.api.nvim_set_keymap('n', '[d', ')', opts) - -local opts = { - noremap = true, - silent = true, -} - -local lsp_format = require 'lsp-format' - -local on_attach = function(client, bufnr) - lsp_format.on_attach(client) - - 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) - - 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, 'i', '', 'lua vim.lsp.buf.signature_help()', 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', 'f', 'lua vim.lsp.buf.formatting_seq_sync()', opts) -end - -local capabilities = require 'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()) -local common_config = { - capabilities = capabilities, - on_attach = on_attach, - flags = { - debounce_text_changes = 150 - }, -} - ---[[ - -set els_path ~/.local/share/nvim/lsp_servers/elixir -curl -fLO https://github.com/elixir-lsp/elixir-ls/releases/latest/download/elixir-ls.zip -mkdir -p $els_path -unzip elixir-ls.zip -d $els_path/elixir-ls/ -chmod +x $els_path/elixir-ls/language_server.sh - -]] - -local lsp_configs = { - gopls = {}, - elixirls = { - cmd = { vim.fn.expand '~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' }, - settings = { - elixirLS = { - dialyzerEnabled = true, - fetchDeps = false, - } - } - }, - sumneko_lua = { - settings = { - Lua = { - diagnostics = { - globals = { 'vim' } - } - } - } - }, - vimls = {}, - rust_analyzer = {}, - -- tsserver = {}, - pylsp = {}, - denols = { - root_dir = lsp.util.root_pattern("deno.json"), - }, -} - -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 - -require'nvim-lsp-installer'.setup{ - automatic_installation = true, -} diff --git a/common/neovim/lua/options.lua b/common/neovim/lua/options.lua deleted file mode 100644 index 72896a0..0000000 --- a/common/neovim/lua/options.lua +++ /dev/null @@ -1,105 +0,0 @@ -local globals = { - coq_settings = { - ['display.icons.mode'] = 'none' - }, - dashboard_default_executive = 'telescope', - mapleader = ' ', - maplocalleader = ' ', - completion_enable_auto_popup = 0, - skipview_files = {'COMMIT_EDITMSG'}, - indent_blankline_char = '▏', - indent_blankline_filetype_exclude = {'help', 'packer'}, - indent_blankline_buftype_exclude = {'terminal', 'nofile'}, - indent_blankline_char_highlight = 'LineNr', - svelte_preprocessors = {'typescript', 'coffeescript', 'sass', 'pug'}, - svelte_preprocessor_tags = { - {name = 'sass', tag = 'lang', as = 'sass'}, - {name = 'coffeescript', tag = 'lang', as = 'coffeescript'}, - {name = 'pug', tag = 'pug', as = 'pug'}, - }, - svelte_indent_script = 0, - svelte_indent_style = 0, -} -for k,v in pairs(globals) do vim.g[k] = v end - -local options = { - clipboard = 'unnamedplus', - inccommand = 'nosplit', - tabstop = 2, - softtabstop = 2, - shiftwidth = 2, - smartindent = true, - list = true, - listchars = 'trail:·,tab: ', - linebreak = true, - formatoptions = 'crql1jn', - synmaxcol = 200, - lazyredraw = true, - scrolloff = 8, - sidescrolloff = 15, - mouse = 'a', - splitright = true, - splitbelow = true, - errorbells = false, - visualbell = true, - backup = false, - writebackup = false, - swapfile = false, - timeout = true, - timeoutlen = 150, - hidden = true, - shortmess = 'filnxToOFIac', - history = 1000, - undofile = true, - undodir = vim.fn.stdpath'data' .. '/undo', - undolevels = 1000, - undoreload = 1000, - spellfile = vim.fn.stdpath'data' .. '/spell/en.utf-8.add', - ignorecase = true, - smartcase = true, - incsearch = true, - wrapscan = true, - hlsearch = true, - foldmethod = 'syntax', - foldlevel = 99, - foldnestmax = 10, - foldlevelstart = 99, - autowrite = false, - autochdir = false, - autoread = true, - modeline = false, - showmode = false, - showcmd = false, - laststatus = 2, - ruler = false, - number = true, -} -for k,v in pairs(options) do - vim.o[k] = v -end - -vim.api.nvim_command'colorscheme donokai' - -function SynGroup() - local s = vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1) - print(vim.fn.synIDattr(s, 'name') .. ' -> ' .. vim.fn.synIDattr(vim.fn.synIDtrans(s), 'name')) -end - -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) --- 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 deleted file mode 100644 index b7d5774..0000000 --- a/common/neovim/lua/plugins.lua +++ /dev/null @@ -1,192 +0,0 @@ -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 - -local has_words_before = function() - local line, col = 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 - -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() - local should_autoload = #vim.v.argv == 1 - require 'persisted'.setup { - autoload = should_autoload, - autosave = should_autoload, - } - 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', - } - }, - { - 'nvim-telescope/telescope-fzf-native.nvim', - run = 'make', - }, - { - 'tzachar/cmp-fuzzy-path', - requires = { 'hrsh7th/nvim-cmp', 'tzachar/fuzzy.nvim' }, - }, - -- TODO: add keymap ig for toggling these - 'lukas-reineke/indent-blankline.nvim', -- indentation guide lines - 'L3MON4D3/LuaSnip', - - 'neovim/nvim-lspconfig', -- language server configuration helper - 'williamboman/nvim-lsp-installer', -- plugin containing installation commands for many language servers - 'hrsh7th/cmp-nvim-lsp-signature-help', - 'hrsh7th/cmp-nvim-lsp', -- add lsp to completion engine - 'hrsh7th/cmp-buffer', -- add buffer information to completion engine - 'hrsh7th/cmp-path', -- add filesystem information to complete enging - 'hrsh7th/cmp-cmdline', -- add completion for vim commands - 'onsails/lspkind-nvim', - 'saadparwaiz1/cmp_luasnip', - { - -- completion engine - 'hrsh7th/nvim-cmp', - config = function() - local cmp = require 'cmp' - local luasnip = require 'luasnip' - - local prev_item = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end - - local next_item = function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end - - cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - 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, - [''] = cmp.mapping { - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }, - [''] = cmp.mapping.confirm { select = false }, - [""] = cmp.mapping(next_item, { "i", "s" }), - [""] = cmp.mapping(prev_item, { "i", "s" }), - [''] = cmp.mapping(next_item, { "i", "s" }), - [''] = cmp.mapping(prev_item, { "i", "s" }), - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'nvim_lsp_signature_help' }, - { name = 'luasnip' }, - }, { - { name = 'buffer' }, - { name = 'path' }, - { name = 'fuzzy_path' }, - }), - formatting = { - format = require("lspkind").cmp_format { - with_text = true, - menu = { - nvim_lsp = "[LSP]", - }, - } - }, - } - - cmp.setup.cmdline('/', { - -- mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' }, - { name = 'fuzzy_path' }, - } - }) - - cmp.setup.cmdline(':', { - -- mapping = cmp.mapping.preset.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'}, - { - -- syntax highlighting and indentation - 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate', - config = function() - require 'nvim-treesitter.configs'.setup { - ensure_installed = "all", - sync_install = false, - ignore_install = { "phpdoc" }, - 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 - }, - 'lukas-reineke/lsp-format.nvim', - } - 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 deleted file mode 100644 index 91c18da..0000000 --- a/common/neovim/lua/statusline.lua +++ /dev/null @@ -1,86 +0,0 @@ -local fn = vim.fn -local api = vim.api -local status_line_max_length = 5 - --- TODO: only update this portion when needed instead of every render? -local status_line_buffer_by_num = function(bufnum) - local is_active = false - local bufinfo = fn.getbufinfo(bufnum)[1] - local prefix = ' %#InactiveBuffer#' - local suffix = '%* ' - - if bufinfo.changed == 1 then - prefix = '%#DirtyBuffer# ' - suffix = ' %*' - end - - local windex = fn.index(bufinfo.windows, vim.g.statusline_winid) - if bufinfo.hidden and windex >= 0 then - is_active = true - prefix = '%#ActiveBuffer# ' - suffix = ' %*' - if bufinfo.changed == 1 then - prefix = '%#ActiveDirtyBuffer# *' - suffix = ' %*' - end - end - - return (prefix .. fn.fnamemodify(fn.bufname(bufnum), ':t') .. suffix), is_active -end - -local status_line_buffers = function() - -- TODO: mark buffers with unsaved changes - - local active_index = -1 - local acc = {} - for _,bufnum in ipairs(api.nvim_list_bufs()) do - local bufinfo = fn.getbufinfo(bufnum)[1] - if bufinfo.listed ~= 0 then - local entry, is_active = status_line_buffer_by_num(bufnum) - table.insert(acc, entry) - if is_active then - active_index = #acc - end - end - end - if active_index >= 0 then - -- TODO: instead implement this as a wraparound carousel? - local offset = status_line_max_length / 2 - local min_buf_num = math.max(0, (active_index - offset)) - local max_buf_num = math.min(#acc - 1, min_buf_num + status_line_max_length - 1) - min_buf_num = math.max(0, max_buf_num - status_line_max_length + 1) - local buflist = table.concat({unpack(acc, min_buf_num+1, max_buf_num+1)}, '') - local prefix = '' - local suffix = '' - if min_buf_num > 0 then - prefix = '< ' - end - if max_buf_num < (#acc - 1) then - suffix = ' >' - end - return prefix .. buflist .. suffix - else - local suffix = '' - if #acc - 1 >status_line_max_length then - suffix = ' >' - end - local buflist = table.concat({unpack(acc, 1, math.min(#acc, status_line_max_length))}, '') - return buflist .. suffix .. active_index - end -end - -local whitespace = function() - local result = "" - if vim.o.expandtab == true then - result = result .. vim.o.shiftwidth .. "S" - else - result = result .. vim.o.tabstop .. "T" - end - return result -end - -function StatusLine() - return status_line_buffers() .. '%*%=%{&filetype} %l;%c (%p%%/%L) ' .. whitespace() -end - -vim.o.statusline = '%!v:lua.StatusLine()'