From ded7f54b600c98e4b060da490ecc387fd3572e3e Mon Sep 17 00:00:00 2001 From: Knyffen Date: Fri, 19 Jan 2024 19:55:07 +0100 Subject: [PATCH] Various things, but mostly rust and treesitter related --- init.vim | 163 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 135 insertions(+), 28 deletions(-) diff --git a/init.vim b/init.vim index bb6dfac..ad3726e 100644 --- a/init.vim +++ b/init.vim @@ -75,6 +75,7 @@ Plug 'morhetz/gruvbox' " alternate theme Plug 'sonph/onehalf', {'rtp': 'vim/'} " altenate theme Plug 'romainl/vim-dichromatic' " colorblind theme + Plug 'j-hui/fidget.nvim' " UI for notifications and progress info " Linting Plug 'neomake/neomake' @@ -83,11 +84,15 @@ \ 'do': 'make fsautocomplete', \} Plug 'JuliaEditorSupport/julia-vim' - Plug 'rust-lang/rust.vim' + Plug 'alx741/vim-rustfmt' Plug 'tikhomirov/vim-glsl' " Language server Plug 'neovim/nvim-lspconfig' + Plug 'simrat39/rust-tools.nvim' + + " Support for DAP (Debug Adapter Protocol) + Plug 'mfussenegger/nvim-dap' " Fuzzy finding " Plug 'jhawthorn/fzy' " Install this systemwide (or configure a manual @@ -107,6 +112,7 @@ " commenting code Plug 'tpope/vim-commentary' + Plug 'JoosepAlviste/nvim-ts-context-commentstring' " Automatically set commentstring based on treesitter " shell commands without having to leave vim (eg. rename) Plug 'tpope/vim-eunuch' @@ -195,7 +201,7 @@ Plug 'rlue/vim-barbaric' " Arduino integration - if system('command -v arduino-cli') != "" + if executable("arduino-cli") Plug 'stevearc/vim-arduino' endif @@ -203,6 +209,9 @@ Plug 'janko-m/vim-test' " Syntax highlighting {{{ + " Better syntax highlighting using Tree-sitter + " This is the preferred method + Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Bedre perl-highlighting Plug 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp highlight-all-pragmas moose test-more try-tiny method-signatures' } @@ -254,7 +263,7 @@ tnoremap " UI config {{{ " Enable syntax highlighting syntax on - syntax enable + " syntax enable set conceallevel=0 " Highlight unwanted whitespaces @@ -286,27 +295,9 @@ tnoremap " autocmd filetype markdown syntax match markdownIgnore "\\begin{\(\$\|gather\*\?\|align\*\?\)}.*_.*\\end{\1}" containedin=markdown augroup END - " " Colorscheme - " let base16colorspace=256 -" " colorscheme base16-gruvbox-dark-hard - " colorscheme base16-solarized-dark - " let g:solarized_termcolors=256 -" " colorscheme dracula - " " set background=dark - " " disables opaque background - " " NOTE: When a transparent background is needed, ":color default" is - " " easier - " " hi Normal ctermbg=NONE guibg=NONE - " " hi NonText ctermbg=NONE guibg=NONE - - " Gruvbox {{{ - " let g:gruvbox_italic=1 - " let g:gruvbox_contrast_dark='hard' - " colorscheme gruvbox - " }}} - " dichromatic colorscheme dichromatic + " Recolor selected line in QuickFix window hi QuickFixLine ctermbg=15 ctermfg=240 cterm=NONE guibg=#585858 guifg=#FFFFFF gui=NONE hi Pmenu ctermbg=17 guibg=#00005F ctermfg=252 guifg=#DADADA @@ -403,6 +394,10 @@ set smartcase " < and > will hit indentation levels instead of always -4/+4 set shiftround + + " Don't move comments/preprocessor directives starting with # to the + " beginning of the line + set cinkeys-=0# "}}} " Highlight tabs and trailing whitespace {{{ @@ -595,8 +590,10 @@ endif \ ] " Configure for Rust + " Replace with rust-analyzer via the LSP " let g:neomake_rust_enabled_makers = ['rustc', 'cargo'] - let g:neomake_rust_enabled_makers = ['cargo'] + " let g:neomake_rust_enabled_makers = ['cargo'] + let g:neomake_rust_enabled_makers = [] " Disable Neomake " Configure for Haskell let g:neomake_haskell_enabled_makers = ['hlint'] @@ -799,7 +796,7 @@ EOF highlight SignColumn ctermbg=none " }}} -" Configure Vim-Commentary +" Configure Vim-Commentary {{{ augroup CustomCommentDefinitions function! SetCommentString() let syntaxGroups = map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') @@ -836,6 +833,30 @@ augroup CustomCommentDefinitions " autocmd CursorMoved * :call SetCommentString() augroup END +" Preemptive configuration for when languages are parsed using treesitter in +" the future +lua < to select the popup menu: + " Use instead of arrow keys to select the popup menu: inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" + inoremap pumvisible() ? '' : '' + inoremap pumvisible() ? '' : '' " Configure float-preview let g:float_preview#docked = 1 @@ -870,6 +893,17 @@ augroup NCM2 " C/C++ let g:ncm2_pyclang#library_path = '/usr/lib/libclang.so' autocmd FileType c,cpp nnoremap gd :call ncm2_pyclang#goto_declaration() + + " Rust + " Documented in https://github.com/ncm2/ncm2/pull/178 + au User Ncm2Plugin call ncm2#register_source({ + \ 'name' : 'Rust', + \ 'priority': 9, + \ 'scope': ['rust'], + \ 'mark': 'RLS', + \ 'complete_pattern': ['\.', ':'], + \ 'on_complete': 'ncm2#on_complete#lsp', + \ }) augroup END " VimTex {{ @@ -1305,7 +1339,7 @@ lua <ll", ':w :!cargo run ', { buffer = bufnr }) + vim.keymap.set("n", "ll", ":w :!cargo run 3>&2 2>&1 1>&3 | grep -o 'could not find `Cargo.toml`' > /dev/null && (rustc %:p && %:p:r)", { buffer = bufnr }) + end, + }, + tools = { + inlay_hints = { + auto = true, -- enable inlay_hints + }, + }, +}) +EOF +" }}} + +" Setup fidget +lua < max_filesize then + return true + end + end, + + -- 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, + }, +}) +EOF +