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.
This commit is contained in:
Gabe Venberg 2021-12-14 00:32:00 -06:00
parent 3992946c98
commit 8322dfa4e1
6 changed files with 367 additions and 29 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ vifm-help.txt
__pycache__/ __pycache__/
*.pickle *.pickle
*.spl *.spl
neovim/.config/nvim/plugin/

View file

@ -3,7 +3,7 @@ library: ~/Music/library.db
import: import:
move: yes move: yes
write: yes write: yes
plugins: [edit, fetchart, chroma, thumbnails, replaygain, mbsync, fuzzy, duplicates] plugins: [edit, fetchart, chroma, thumbnails, replaygain, mbsync, fuzzy, duplicates, badfiles]
replaygain: replaygain:
auto: no auto: no
backend: ffmpeg backend: ffmpeg

View file

@ -4,19 +4,21 @@ local opt=vim.opt
local fn=vim.fn local fn=vim.fn
local map=vim.api.nvim_set_keymap local map=vim.api.nvim_set_keymap
--do package management
require('packages')
require('LSPconfig')
require('cmp-lsp')
--helper functions --helper functions
local function keyCode(string) local function keyCode(string)
return vim.api.nvim_replace_termcodes(str, true, true, true, true) return vim.api.nvim_replace_termcodes(str, true, true, true, true)
end 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.) --options using vim.opt (aliased, of course.)
opt.mouse='a'
opt.lazyredraw=true opt.lazyredraw=true
opt.termguicolors=true
opt.autoread=true opt.autoread=true
opt.swapfile=false opt.swapfile=false
opt.history=500 opt.history=500
@ -53,33 +55,56 @@ local map=vim.api.nvim_set_keymap
opt.hlsearch=true opt.hlsearch=true
opt.incsearch=true opt.incsearch=true
--foling stuff --foling stuff
cmd([[source ~/.config/nvim/foldtext.vimrc]]) opt.foldmethod='expr'
opt.foldmethod='indent' opt.foldexpr='nvim_treesitter#foldexpr()'
opt.foldtext='minimal_foldtext()' -- cmd([[source ~/.config/nvim/foldtext.vimrc]])
opt.fillchars='stl:=,stlnc: ,vert:|,fold:-' -- opt.foldmethod='indent'
opt.foldcolumn='4' -- opt.foldtext='minimal_foldtext()'
opt.foldenable=true -- opt.fillchars='stl:=,stlnc: ,vert:|,fold:-'
opt.foldminlines=2 -- opt.foldcolumn='4'
opt.foldignore='' -- opt.foldenable=true
-- opt.foldminlines=2
-- opt.foldignore=''
--leader key is set through a variable, for some reason. --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 <Space> <C-d> --sets colorscheme. to get a list of avalible options, do colorscheme <Space> <C-d>
vim.g.colors_name='default' vim.cmd 'colorscheme moonfly'
--keyboard mappings --keyboard mappings
local opts = { noremap=true, silent=true }
--toggle spell check --toggle spell check
map('', '<leader>ss', ':setlocal spell!<CR>', {noremap=true, silent=true}) map('n', '<leader>ss', ':setlocal spell!<CR>', opts)
--easily create splits --[[ --easily create splits
map('', '<leader>|', ':vs<CR>', {noremap=true, silent=true}) map('n', '<leader>|', ':vs<CR>', opts) ]]
map('', '<leader>-', ':sp<CR>', {noremap=true, silent=true}) --[[ map('n', '<leader>-', ':sp<CR>', opts)
--use ctrl+direction to move between splits. --use ctrl+direction to move between splits. ]]
map('', '<C-h>', '<C-w>h', {noremap=true, silent=true}) map('n', '<C-h>', '<C-w>h', opts)
map('', '<C-j>', '<C-w>j', {noremap=true, silent=true}) map('n', '<C-j>', '<C-w>j', opts)
map('', '<C-k>', '<C-w>k', {noremap=true, silent=true}) map('n', '<C-k>', '<C-w>k', opts)
map('', '<C-l>', '<C-w>l', {noremap=true, silent=true}) map('n', '<C-l>', '<C-w>l', opts)
--toggle folds with space. --toggle folds with space.
map('', '<Space>', 'za', {noremap=true, silent=true}) map('', '<Space>', 'za', opts)
--clear highlighting with leader+l --clear highlighting with leader+h
map('', '<leader>l', ':nohls<CR>', {noremap=true, silent=true}) map('n', '<leader>h', ':nohls<CR>', opts)
--open nvim-tree with leader+t
map('n', '<leader>t', ':NvimTreeToggle<CR>', opts)
--telescope stuff
map('n', '<leader>ff', ':Telescope file_browser<CR>', opts)
map('n', '<leader>fg', ':Telescope live_grep<CR>', opts)
map('n', '<leader>fb', ':Telescope buffers<CR>', opts)
map('n', '<leader>fm', ':Telescope marks<CR>', opts)
map('n', '<leader>fp', ':Telescope registers<CR>', opts)
map('n', '<leader>fs', ':Telescope spell_suggest<CR>', opts)
map('n', '<leader>fh', ':Telescope keymaps<CR>', opts)
map('n', '<leader>fz', ':Telescope current_buffer_fuzzy_find<CR>', opts)
map('n', '<leader>fgc', ':Telescope git_commits<CR>', opts)
map('n', '<leader>fgb', ':Telescope git_branches<CR>', opts)
map('n', '<leader>fgs', ':Telescope git_stash<CR>', opts)
map('n', '<leader>ft', ':Telescope treesitter<CR>', opts)
--Treesitter context
map('n', '<leader>c', ':TSContextToggle<CR>', opts)
--tabline stuff (gt and gT are prev/next tab in stock vim)
map('n', 'gf', ':TablineBufferNext<CR>', opts)
map('n', 'gF', ':TablineBufferPrevious<CR>', opts)

View file

@ -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 <c-x><c-o>
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', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('', ';lf', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('', ';lh', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('', ';li', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('', ';ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('', ';lwa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('', ';lwr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('', ';lw', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('', ';lt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('', ';lr', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('', ';la', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('', ';lc', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('', ';lo', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
buf_set_keymap('', ';ln', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('', ';lp', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('', ';lm', '<cmd>lua vim.lsp.buf.formatting()<CR>', 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,
},
},
},
}

View file

@ -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 = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<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 {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = 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' },
},
}

View file

@ -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)