Update rust tooling, convert more config to lua

* Drop unmaintained rust-tools.
* Adopted rustaceanvm
* Convert Plug config to lua
* Convert key mapping to lua, update LSP bindings
* Remove unused syntastic plugin and config
This commit is contained in:
thomas-gideon-gm 2024-06-22 09:10:01 -04:00
parent 59683c0702
commit 21e9dfa8b0
9 changed files with 168 additions and 322 deletions

View file

@ -4,12 +4,11 @@ local vimrc_git = os.getenv("HOME") .. "/src/vimrc"
-- N.B. should come before plugins and plugin specific settings
vim.g.mapleader = ' '
vim.cmd("source " .. vimrc_git .. "/plug.vim")
vim.cmd("source " .. vimrc_git .. "/plug.lua")
vim.cmd("source " .. vimrc_git .. "/airline.vim")
vim.cmd("source " .. vimrc_git .. "/syntastic.vim")
vim.cmd("source " .. vimrc_git .. "/fzf.vim")
vim.cmd("source " .. vimrc_git .. "/lsp.vim")
vim.cmd("source " .. vimrc_git .. "/mapping.vim")
vim.cmd("source " .. vimrc_git .. "/mapping.lua")
vim.cmd("source " .. vimrc_git .. "/fzf.vim")
vim.cmd("source " .. vimrc_git .. "/jsonnet.vim")
vim.cmd("source " .. vimrc_git .. "/nerdtree.vim")
vim.cmd("source " .. vimrc_git .. "/wiki.vim")

133
init.vim
View file

@ -1,133 +0,0 @@
" set the directory where vimrc git project is located
let vimrc_git=$HOME . "/src/vimrc"
" it is a big fat key, after all
" N.B. should come before plugins and plugin specific settings
let mapleader = "\<Space>"
" source aux files also under git control
let oldwd = getcwd()
exec "cd " . vimrc_git
source plug.vim
source airline.vim
source syntastic.vim
source fzf.vim
source lsp.vim
source mapping.vim
source jsonnet.vim
source nerdtree.vim
source wiki.vim
exec "cd " . oldwd
" set up a line number on the current line but relative above and below to help
" with motion commands
set number
set relativenumber
" even with the nice space/tab autodetect, prefer 4 for tab stops
" but let file type specifics override (for instance a setting of 2 for markdown
set tabstop=4
" default to folding on syntax
set foldmethod=syntax
" disable automatic line breaks, rely on visual wrapping instead
set textwidth=0
" make white space visible, where that matters
set list!
" except for help
autocmd FileType help setlocal nolist
" set up folding preferences
set fde=1
" vim's spelling is smart enough for code, to only check comments
set spell
" add a hint for long lines
set colorcolumn=120
" default to expanding tabs, I'm not insane
set expandtab
" change buffer behaviors to no longer require changes when hiding a buffer
set hidden
" look for vimrc in the current director as well as $MYVIMRC
set exrc
" make looking for local changes secure
set secure
" more secure
set modelines=0
" preserve some context
set scrolloff=3
" make the cursor a bit easier to follows
set cursorline
" make search work a bit more like tab completion in bash
set incsearch
set wildmode=longest:full
set wildmenu
" line break handling
set linebreak
set showbreak=+
" always on status line
set laststatus=2
" let backspace work more naturally
set backspace=start,indent,eol
" favor modern encoding
set enc=utf-8
" more readable config for list mode
set listchars+=nbsp,tab:»·,trail
set listchars-=eol:$
" smarter handling of case during search
set ignorecase
set smartcase
" centralize swap to have backup without clutter
set directory=$HOME/.var/nvim/swp//
" and undo
set undofile
set undodir=$HOME/.nvim/undodir
" make pastemode more accessible
set pastetoggle=<F2>
" save when moving away
au FocusLost * :wa
" make sure to set TERM to xterm-256color in terminal program or app
colorscheme breezy
set background=light
set termguicolors
" ensure autoread works, to detect file changes outside the editor
set autoread
au CursorHold * checktime
" for gui, make it easier to tell different instances apart
set title
" keep nvim from resetting font back to default from terminal config
set guicursor=
set guioptions-=r
set guioptions-=b
set guioptions-=T
set guioptions-=m
set mouse=nv
set gfn=FiraCode\ Nerd\ Font\ Mono:h10
" from https://stackoverflow.com/a/51424640
let s:fontsize = 10
function! AdjustFontSize(amount)
let s:fontsize = s:fontsize+a:amount
:execute "set gfn=FiraCode\\ Nerd\\ Font\\ Mono:h" . s:fontsize
endfunction
noremap <C-Up> :call AdjustFontSize(1)<CR>
noremap <C-Down> :call AdjustFontSize(-1)<CR>
inoremap <C-Up> <Esc>:call AdjustFontSize(1)<CR>a
inoremap <C-Down> <Esc>:call AdjustFontSize(-1)<CR>a
lua << EOF
require('nvim-projectconfig').setup({autocmd=true})
require("trouble").setup {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
EOF

19
lsp.vim
View file

@ -12,25 +12,6 @@ set shortmess+=c
" Recognize slint files
autocmd BufEnter *.slint :setlocal filetype=slint
" Configure LSP through rust-tools.nvim plugin.
" rust-tools will configure and enable certain LSP features for us.
" See https://github.com/simrat39/rust-tools.nvim#configuration
lua <<EOF
local rt = require('rust-tools')
rt.setup({
server = {
server = {
on_attach = function(_, buffnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr})
-- Code action groups
vim.keymap.set("n", "<Leader>a>", rt.code_action_group.code_action_group, { buffer = bufnr})
end
},
}, -- rust-analyer options
})
EOF
" Setup Completion
" See https://github.com/hrsh7th/nvim-cmp#basic-configuration
lua <<EOF

60
mapping.lua Normal file
View file

@ -0,0 +1,60 @@
local bufnr = vim.api.nvim_get_current_buf()
local opts = { buffer = bufnr, noremap = true, silent = true }
-- toggle gundo's display
vim.keymap.set('n', '<F5>', vim.cmd.UndotreeToggle)
-- quickly toggle a left, vsplit for an insanely powerful file explorer
vim.keymap.set('n', '<F8>', vim.cmd.NERDTreeToggle)
vim.keymap.set('n', '<F9>', vim.cmd.NERDTreeFind)
-- use similar key, esc, to exit terminal mode
vim.cmd("tnoremap <C-Space><Esc> <C-\\><C-n>")
-- Code navigation shortcuts
-- from https://github.com/neovim/nvim-lspconfig/blob/master/test/minimal_init.lua#L34
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
-- vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
-- vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
vim.keymap.set('n', '<leader>xx', vim.cmd.TroubleToggle, opts)
vim.keymap.set('n', '<leader>xw', function()
vim.cmd("TroubleToggle workspace_diagnostics")
end, opts)
vim.keymap.set('n', '<leader>xd', function()
vim.cmd("TroubleToggle workspace_diagnostics")
end, opts)
vim.keymap.set('n', '<leader>xq', function()
vim.cmd("TroubleToggle quickfix")
end, opts)
vim.keymap.set('n', '<leader>xl', function()
vim.cmd("TroubleToggle loclist")
end, opts)
-- work with Trouble to view lists of diagnostic warnings/errors
vim.keymap.set('n', '<leader>t', function()
vim.cmd("e ~/Documents/Wiki/tags.md")
end, opts)
vim.keymap.set('n', '<leader>tr', vim.cmd.VimwikiRebuildTags, opts)
vim.keymap.set('n', '<leader>tg', vim.cmd.VimwikiGenerateTagLinks, opts)
-- TODO translate to lua
--function! VimwikiFindAllIncompleteTasks()
-- lvimgrep /- \[ \]/ *
-- lopen
--endfunction
--nmap <Leader>wa :call VimwikiFindAllIncompleteTasks()<CR>

View file

@ -1,48 +0,0 @@
" quickly clear Syntastic info
nmap <F4> :SyntasticReset<CR>
" toggle gundo's display
nmap <F5> :UndotreeToggle<CR>
" quickly toggle a left, vsplit for an insanely powerful file explorer
nmap <F8> :NERDTreeToggle<CR>
" open tree to current buffer
nmap <F9> :NERDTreeFind<CR>
" use similar key, esc, to exit terminal mode
tnoremap <C-Space><Esc> <C-\><C-n>
" from: https://sharksforarms.dev/posts/neovim-rust/
" Code navigation shortcuts
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-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.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <silent> <Leader>rn <cmd>lua vim.lsp.buf.rename()<CR>
" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.diagnostic.goto_next()<CR>
nnoremap <silent> gE <cmd>lua vim.diagnostic.setloclist()<CR>
" work with Trouble to view lists of diagnostic warnings/errors
nnoremap <leader>xx <cmd>TroubleToggle<cr>
nnoremap <leader>xw <cmd>TroubleToggle workspace_diagnostics<cr>
nnoremap <leader>xd <cmd>TroubleToggle document_diagnostics<cr>
nnoremap <leader>xq <cmd>TroubleToggle quickfix<cr>
nnoremap <leader>xl <cmd>TroubleToggle loclist<cr>
nnoremap gR <cmd>TroubleToggle lsp_references<cr>
nnoremap <leader>t <cmd>e ~/Documents/Wiki/tags.md<cr>
nnoremap <leader>tr <cmd>VimwikiRebuildTags<cr>
nnoremap <leader>tg <cmd>VimwikiGenerateTagLinks<cr>
function! VimwikiFindAllIncompleteTasks()
lvimgrep /- \[ \]/ *
lopen
endfunction
nmap <Leader>wa :call VimwikiFindAllIncompleteTasks()<CR>

105
plug.lua Normal file
View file

@ -0,0 +1,105 @@
local vim = vim
local Plug = vim.fn['plug#']
vim.call('plug#begin')
-- I try to keep these to a minimum and to understand what each plugin does and
-- adds to my existing(set up. I try to capture the value, at least to me, each
-- plugin adds. I've tried to logically group them, as well, to spot overlap
-- and redundancy.
-- dynamic font resizing(using ctl and arrow keys
Plug('tenxsoydev/size-matters.nvim')
-- informational
-- lightweight but sophisticated status line
Plug('vim-airline/vim-airline')
Plug('vim-airline/vim-airline-themes')
-- visualize vim's undo tree
Plug('mbbill/undotree')
-- diagnostics display
Plug('folke/trouble.nvim')
-- icons for Trouble
Plug('kyazdani42/nvim-web-devicons')
-- files, folders, projects, etc.
-- file and dir browser
Plug('preservim/nerdtree')
-- integrate ripgrep, especially to be able to open matches, hugely useful for
-- code aware search
Plug('jremmen/vim-ripgrep')
-- Support for the cd replacement, zoxide
Plug('nanotee/zoxide.vim')
-- taskwarrior
Plug('xarthurx/taskwarrior.vim')
-- Wiki support - my life is in vimwiki
Plug('vimwiki/vimwiki', { ['branch'] = 'dev' })
-- git integration
Plug('tpope/vim-fugitive')
Plug('tpope/vim-rhubarb')
Plug('mhinz/vim-signify')
-- git support for nerdtree
Plug('Xuyuanp/nerdtree-git-plugin')
-- better support for JS
Plug('pangloss/vim-javascript')
-- find, complete, etc. on steroids
-- fast fuzzy finder
Plug('junegunn/fzf', { ['dir'] = '~/.fzf', ['do'] = function()
vim.fn['fzf#install']()
end })
Plug('junegunn/fzf.vim')
-- auto detect tab and space handling(rather than setting per project
Plug('tpope/vim-sleuth')
-- tools - all languages
-- look for .editorconfig(and merge into vim settings
Plug('editorconfig/editorconfig-vim')
-- auto format all the things
Plug('sbdchd/neoformat')
-- load config(from $CWD/.config/init.vim
Plug('windwp/nvim-projectconfig')
-- Collection of common configurations for the Nvim LSP client
Plug('neovim/nvim-lspconfig')
-- Add commands to add and manage lsp plugins
Plug('williamboman/nvim-lsp-installer')
-- Completion framework
-- I found these when updating(my lsp configuration and after using the
-- additional sources for a while, find them super useful for general editing
-- too
-- See hrsh7th's other plugins for more completion sources!
Plug('hrsh7th/nvim-cmp')
-- LSP completion source for nvim-cmp
Plug('hrsh7th/cmp-nvim-lsp')
-- Snippet completion source for nvim-cmp
Plug('hrsh7th/cmp-vsnip')
-- Other useful completion sources
Plug('hrsh7th/cmp-path')
Plug('hrsh7th/cmp-buffer')
-- Snippet engine
Plug('hrsh7th/vim-vsnip')
-- allows other programs and scripts to hook into NeoVim's language server
-- protocol support; adopted as a pre-requisite for prettier integration
Plug('jose-elias-alvarez/null-ls.nvim')
-- specific languages, programming(and otherwise
-- support for the Rust programming(language
Plug('rust-lang/rust.vim')
-- handles Rust configuration for LSP
Plug('mrcjkb/rustaceanvim')
-- support for jsonnet
Plug('google/vim-jsonnet')
-- nvm to make JS/TS/Node easier to work with
Plug('marene/nvm.vim')
vim.call('plug#end')

107
plug.vim
View file

@ -1,107 +0,0 @@
call plug#begin("~/.config/nvim/plugged")
" I try to keep these to a minimum and to understand what each plugin does and
" adds to my existing set up. I try to capture the value, at least to me, each
" plugin adds. I've tried to logically group them, as well, to spot overlap
" and redundancy.
"
Plug 'tenxsoydev/size-matters.nvim'
" informational
" lightweight but sophisticated status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" visualize vim's undo tree
Plug 'mbbill/undotree'
" diagnostics display
Plug 'folke/trouble.nvim'
" icons for Trouble
Plug 'kyazdani42/nvim-web-devicons'
" files, folders, projects, etc.
" file and dir browser
Plug 'preservim/nerdtree'
" integrate ripgrep, especially to be able to open matches, hugely useful for
" code aware search
Plug 'jremmen/vim-ripgrep'
" Support for the cd replacement, zoxide
Plug 'nanotee/zoxide.vim'
" taskwarrior
Plug 'xarthurx/taskwarrior.vim'
" Wiki support - my life is in vimwiki
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
" git integration
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'mhinz/vim-signify'
" git support for nerdtree
Plug 'Xuyuanp/nerdtree-git-plugin'
" better support for JS
Plug 'pangloss/vim-javascript'
" find, complete, etc. on steroids
" fast fuzzy finder
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" auto detect tab and space handling rather than setting per project
Plug 'tpope/vim-sleuth'
" tools - all languages
" look for .editorconfig and merge into vim settings
Plug 'editorconfig/editorconfig-vim'
" syntax checking on steroids
Plug 'scrooloose/syntastic'
" auto format all the things
Plug 'sbdchd/neoformat'
" load config from $CWD/.config/init.vim
Plug 'windwp/nvim-projectconfig'
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
" Add commands to add and manage lsp plugins
Plug 'williamboman/nvim-lsp-installer'
" Completion framework
" I found these when updating my lsp configuration and after using the
" additional sources for a while, find them super useful for general editing
" too
" See hrsh7th's other plugins for more completion sources!
Plug 'hrsh7th/nvim-cmp'
" LSP completion source for nvim-cmp
Plug 'hrsh7th/cmp-nvim-lsp'
" Snippet completion source for nvim-cmp
Plug 'hrsh7th/cmp-vsnip'
" Other useful completion sources
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
" Snippet engine
Plug 'hrsh7th/vim-vsnip'
" allows other programs and scripts to hook into NeoVim's language server
" protocol support; adopted as a pre-requisite for prettier integration
Plug 'jose-elias-alvarez/null-ls.nvim'
" specific languages, programming and otherwise
" support for the Rust programming language
Plug 'rust-lang/rust.vim'
" the rest of the rust config came from: https://sharksforarms.dev/posts/neovim-rust/
" To enable more of the features of rust-analyzer, such as inlay hints and more!
Plug 'simrat39/rust-tools.nvim'
" support for jsonnet
Plug 'google/vim-jsonnet'
" groovy syntax and indent
Plug 'vim-scripts/groovy.vim'
Plug 'vim-scripts/groovyindent-unix'
" nvm to make JS/TS/Node easier to work with
Plug 'marene/nvm.vim'
" All of your Plugins must be added before the following line
call plug#end() " required

View file

@ -1,11 +0,0 @@
" configure syntastic, advanced syntax checker, with some reasonable behaviors
"
" always stick detected errors in the location list
let g:syntastic_always_populate_loc_list = 1
" open but only when errors are detected; default closes when errors are cleared
" but doesn't open the list automatically
let g:syntastic_auto_loc_list = 0
" check when first opening a file
let g:syntastic_check_on_open = 0
" don't check on writing and quitting
let g:syntastic_check_on_wq = 0