From 8322dfa4e1b9f1a29721e1426c6f55684661bf30 Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Tue, 14 Dec 2021 00:32:00 -0600 Subject: [PATCH] I have joined the dark side! neovim with plugins! added neovim support for treesitter and LSP, then added a bunch of plugins to take advantage of them. --- .gitignore | 1 + beets/.config/beets/config.yaml | 2 +- neovim/.config/nvim/init.lua | 81 +++++++----- neovim/.config/nvim/lua/LSPconfig.lua | 74 +++++++++++ neovim/.config/nvim/lua/cmp-lsp.lua | 68 +++++++++++ neovim/.config/nvim/lua/packages.lua | 170 ++++++++++++++++++++++++++ 6 files changed, 367 insertions(+), 29 deletions(-) create mode 100644 neovim/.config/nvim/lua/LSPconfig.lua create mode 100644 neovim/.config/nvim/lua/cmp-lsp.lua create mode 100644 neovim/.config/nvim/lua/packages.lua diff --git a/.gitignore b/.gitignore index 8e4c03a..5904c7b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ vifm-help.txt __pycache__/ *.pickle *.spl +neovim/.config/nvim/plugin/ diff --git a/beets/.config/beets/config.yaml b/beets/.config/beets/config.yaml index 2a6e86a..02ae9f1 100644 --- a/beets/.config/beets/config.yaml +++ b/beets/.config/beets/config.yaml @@ -3,7 +3,7 @@ library: ~/Music/library.db import: move: yes write: yes -plugins: [edit, fetchart, chroma, thumbnails, replaygain, mbsync, fuzzy, duplicates] +plugins: [edit, fetchart, chroma, thumbnails, replaygain, mbsync, fuzzy, duplicates, badfiles] replaygain: auto: no backend: ffmpeg diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua index ef770fb..9a072e6 100644 --- a/neovim/.config/nvim/init.lua +++ b/neovim/.config/nvim/init.lua @@ -4,19 +4,21 @@ local opt=vim.opt local fn=vim.fn local map=vim.api.nvim_set_keymap +--do package management +require('packages') +require('LSPconfig') +require('cmp-lsp') + + --helper functions local function keyCode(string) return vim.api.nvim_replace_termcodes(str, true, true, true, true) end ---bootstrapping paq-nvim - local install_path = fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim' - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({'git', 'clone', '--depth=1', 'https://github.com/savq/paq-nvim.git', install_path}) - end - --options using vim.opt (aliased, of course.) + opt.mouse='a' opt.lazyredraw=true + opt.termguicolors=true opt.autoread=true opt.swapfile=false opt.history=500 @@ -53,33 +55,56 @@ local map=vim.api.nvim_set_keymap opt.hlsearch=true opt.incsearch=true --foling stuff - cmd([[source ~/.config/nvim/foldtext.vimrc]]) - opt.foldmethod='indent' - opt.foldtext='minimal_foldtext()' - opt.fillchars='stl:=,stlnc: ,vert:|,fold:-' - opt.foldcolumn='4' - opt.foldenable=true - opt.foldminlines=2 - opt.foldignore='' + opt.foldmethod='expr' + opt.foldexpr='nvim_treesitter#foldexpr()' + -- cmd([[source ~/.config/nvim/foldtext.vimrc]]) + -- opt.foldmethod='indent' + -- opt.foldtext='minimal_foldtext()' + -- opt.fillchars='stl:=,stlnc: ,vert:|,fold:-' + -- opt.foldcolumn='4' + -- opt.foldenable=true + -- opt.foldminlines=2 + -- opt.foldignore='' --leader key is set through a variable, for some reason. -vim.g.mapleader = '\\' +vim.g.mapleader = ';' --sets colorscheme. to get a list of avalible options, do colorscheme -vim.g.colors_name='default' +vim.cmd 'colorscheme moonfly' --keyboard mappings + local opts = { noremap=true, silent=true } --toggle spell check - map('', 'ss', ':setlocal spell!', {noremap=true, silent=true}) - --easily create splits - map('', '|', ':vs', {noremap=true, silent=true}) - map('', '-', ':sp', {noremap=true, silent=true}) - --use ctrl+direction to move between splits. - map('', '', 'h', {noremap=true, silent=true}) - map('', '', 'j', {noremap=true, silent=true}) - map('', '', 'k', {noremap=true, silent=true}) - map('', '', 'l', {noremap=true, silent=true}) + map('n', 'ss', ':setlocal spell!', opts) + --[[ --easily create splits + map('n', '|', ':vs', opts) ]] + --[[ map('n', '-', ':sp', opts) + --use ctrl+direction to move between splits. ]] + map('n', '', 'h', opts) + map('n', '', 'j', opts) + map('n', '', 'k', opts) + map('n', '', 'l', opts) --toggle folds with space. - map('', '', 'za', {noremap=true, silent=true}) - --clear highlighting with leader+l - map('', 'l', ':nohls', {noremap=true, silent=true}) + map('', '', 'za', opts) + --clear highlighting with leader+h + map('n', 'h', ':nohls', opts) + --open nvim-tree with leader+t + map('n', 't', ':NvimTreeToggle', opts) + --telescope stuff + map('n', 'ff', ':Telescope file_browser', opts) + map('n', 'fg', ':Telescope live_grep', opts) + map('n', 'fb', ':Telescope buffers', opts) + map('n', 'fm', ':Telescope marks', opts) + map('n', 'fp', ':Telescope registers', opts) + map('n', 'fs', ':Telescope spell_suggest', opts) + map('n', 'fh', ':Telescope keymaps', opts) + map('n', 'fz', ':Telescope current_buffer_fuzzy_find', opts) + map('n', 'fgc', ':Telescope git_commits', opts) + map('n', 'fgb', ':Telescope git_branches', opts) + map('n', 'fgs', ':Telescope git_stash', opts) + map('n', 'ft', ':Telescope treesitter', opts) + --Treesitter context + map('n', 'c', ':TSContextToggle', opts) + --tabline stuff (gt and gT are prev/next tab in stock vim) + map('n', 'gf', ':TablineBufferNext', opts) + map('n', 'gF', ':TablineBufferPrevious', opts) diff --git a/neovim/.config/nvim/lua/LSPconfig.lua b/neovim/.config/nvim/lua/LSPconfig.lua new file mode 100644 index 0000000..95f469d --- /dev/null +++ b/neovim/.config/nvim/lua/LSPconfig.lua @@ -0,0 +1,74 @@ +local nvim_lsp = require('lspconfig') + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('', ';lc', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('', ';lf', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('', ';lh', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('', ';li', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('', ';ls', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('', ';lwa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('', ';lwr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('', ';lw', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('', ';lt', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('', ';lr', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('', ';la', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('', ';lc', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('', ';lo', 'lua vim.diagnostic.open_float()', opts) + buf_set_keymap('', ';ln', 'lua vim.diagnostic.goto_prev()', opts) + buf_set_keymap('', ';lp', 'lua vim.diagnostic.goto_next()', opts) + buf_set_keymap('', ';lm', 'lua vim.lsp.buf.formatting()', opts) + +end + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { 'pyright', 'rust_analyzer', 'texlab'} +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + flags = { + debounce_text_changes = 150, + } + } +end + +on_attach() +--lua-language-server needs seperate config. +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") +require'lspconfig'.sumneko_lua.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} diff --git a/neovim/.config/nvim/lua/cmp-lsp.lua b/neovim/.config/nvim/lua/cmp-lsp.lua new file mode 100644 index 0000000..0dbbaff --- /dev/null +++ b/neovim/.config/nvim/lua/cmp-lsp.lua @@ -0,0 +1,68 @@ +--configure nvim-cmp for use with lsp and luasnip. + + +-- Add additional capabilities supported by nvim-cmp +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + + +local lspconfig = require('lspconfig') + +-- Enable some language servers with the additional completion capabilities offered by nvim-cmp +local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' } +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + -- on_attach = my_custom_on_attach, + capabilities = capabilities, + } +end + +-- Set completeopt to have a better completion experience +vim.o.completeopt = 'menuone,noselect' + +-- luasnip setup +local luasnip = require 'luasnip' + +-- nvim-cmp setup +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} diff --git a/neovim/.config/nvim/lua/packages.lua b/neovim/.config/nvim/lua/packages.lua new file mode 100644 index 0000000..cdbe59f --- /dev/null +++ b/neovim/.config/nvim/lua/packages.lua @@ -0,0 +1,170 @@ +-- bootstrapping packer +local fn=vim.fn +local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' +if fn.empty(fn.glob(install_path)) > 0 then + Packer_Bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) +end + +return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + + use { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate' + } + + use 'neovim/nvim-lspconfig' + + use 'yamatsum/nvim-cursorline' + + use {'stevearc/dressing.nvim', + config=function() + require('dressing').setup{} + end + } + + use {'nvim-lualine/lualine.nvim', + requires = {'kyazdani42/nvim-web-devicons', opt = true}, + config=function() require('lualine').setup{ + options={ + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = {}, + always_divide_middle = true, + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + extensions = {} + } end, + } + use {'kdheepak/tabline.nvim', + config = function() + require'tabline'.setup { + -- Defaults configuration options + enable = true, + options = { + -- If lualine is installed tabline will use separators configured in lualine by default. + -- These options can be used to override those settings. + -- section_separators = {'', ''}, + -- component_separators = {'', ''}, + -- max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 + show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named + show_devicons = true, -- this shows devicons in buffer section + show_bufnr = true, -- this appends [bufnr] to buffer section, + show_filename_only = false, -- shows base filename only instead of relative path in filename + } + } + vim.cmd[[ + set guioptions-=e " Use showtabline in gui vim + set sessionoptions+=tabpages,globals " store tabpages and globals in session + ]] + end, + requires = { { 'hoob3rt/lualine.nvim', opt=true }, {'kyazdani42/nvim-web-devicons', opt = true} } + } + + + use {'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end + } + + use {'hrsh7th/nvim-cmp', + requires = { + -- 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + 'saadparwaiz1/cmp_luasnip', + 'L3MON4D3/LuaSnip' + } + } + + use {'folke/todo-comments.nvim', + requires = 'nvim-lua/plenary.nvim', + config = function() + require('todo-comments').setup() + end + } + + use {'nvim-telescope/telescope.nvim', + requires = { + {'nvim-lua/plenary.nvim'}, + {'nvim-lua/popup.nvim'}, + {'nvim-treesitter/nvim-treesitter'}, + {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }, + {'nvim-telescope/telescope-symbols.nvim'}, + }, + config=function() + require'telescope'.load_extension('fzf') + end + } + + use {'Shatur/neovim-session-manager', + requires = 'nvim-telescope/telescope.nvim', + config = function() + require('telescope').load_extension('sessions') + end + } + + use {'romgrk/nvim-treesitter-context', + requires = 'nvim-treesitter/nvim-treesitter', + config=function() require('treesitter-context').setup() end, + } + + use {'kyazdani42/nvim-tree.lua', + requires = { + 'kyazdani42/nvim-web-devicons', -- optional, for file icon + }, + config = function() require'nvim-tree'.setup {} end + } + + use {'lewis6991/gitsigns.nvim', + requires = {'nvim-lua/plenary.nvim'}, + tag = 'release', -- To use the latest release + config=function() require('gitsigns').setup() end + } + + use 'chentau/marks.nvim' + + use 'tversteeg/registers.nvim' + + use { + 'sudormrfbin/cheatsheet.nvim', + + requires = { + {'nvim-telescope/telescope.nvim'}, + {'nvim-lua/popup.nvim'}, + {'nvim-lua/plenary.nvim'}, + } + } + + use {'lewis6991/spellsitter.nvim', + config=function() require('spellsitter').setup() end + } + + use 'lukas-reineke/indent-blankline.nvim' + + use 'bluz71/vim-moonfly-colors' + + use 'bluz71/vim-nightfly-guicolors' + + if Packer_Bootstrap then + require('packer').sync() + end +end)