Redid a lot of my vim config

This commit is contained in:
Nicholas Novak
2022-11-19 20:37:19 -08:00
parent 4e8b74416f
commit 0ee637d788
+166 -183
View File
@@ -1,62 +1,75 @@
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged') call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
" Add all the syntax for the languages I could ever need " Syntax Highlighting
" Add all the syntax highlighting for mostly everything
Plug 'sheerun/vim-polyglot' Plug 'sheerun/vim-polyglot'
" Java auto formatting " Uxntal
Plug 'karolbelina/uxntal.vim'
" Add maktaba and codefmt to the runtimepath. Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" (The latter must be installed before it can be used.)
" Javascript Syntax
"Plug 'pangloss/vim-javascript'
"Plug 'udalov/kotlin-vim'
" Additional Syntax
"Plug 'plasticboy/vim-markdown'
"Plug 'vim-python/python-syntax'
" Auto Formatting
" Google Java auto-format
Plug 'google/vim-maktaba' Plug 'google/vim-maktaba'
Plug 'google/vim-codefmt' Plug 'google/vim-codefmt'
" Also add Glaive, which is used to configure codefmt's maktaba flags. See
" `:help :Glaive` for usage.
Plug 'google/vim-glaive' Plug 'google/vim-glaive'
" Kotlin
Plug 'udalov/kotlin-vim'
" Go development
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" Formatter for Python " Formatter for Python
Plug 'psf/black' Plug 'psf/black'
" Development Packs
" Go
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" Rust
Plug 'rust-lang/rust.vim'
" Colorscheme " Colorscheme
Plug 'morhetz/gruvbox' Plug 'morhetz/gruvbox'
" Live preview for markdown " For previewing markdown in a web browser
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' } Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
" Snippets
Plug 'SirVer/ultisnips'
" Latex
Plug 'lervag/vimtex'
Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' }
" LSP Config
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/lsp_extensions.nvim'
Plug 'hrsh7th/cmp-nvim-lsp', {'branch': 'main'}
Plug 'hrsh7th/cmp-buffer', {'branch': 'main'}
Plug 'hrsh7th/cmp-path', {'branch': 'main'}
Plug 'hrsh7th/nvim-cmp', {'branch': 'main'}
Plug 'ray-x/lsp_signature.nvim'
" Autocompletion snippets " Autocompletion snippets
Plug 'hrsh7th/cmp-vsnip', {'branch': 'main'} Plug 'hrsh7th/cmp-vsnip', {'branch': 'main'}
Plug 'hrsh7th/vim-vsnip' Plug 'hrsh7th/vim-vsnip'
" More syntax " Latex
Plug 'rust-lang/rust.vim' Plug 'lervag/vimtex'
Plug 'plasticboy/vim-markdown' Plug 'KeitaNakamura/tex-conceal.vim'
Plug 'vim-python/python-syntax'
Plug 'karolbelina/uxntal.vim'
" Javascript Syntax " LSP Config
Plug 'pangloss/vim-javascript' Plug 'neovim/nvim-lspconfig'
Plug 'mxw/vim-jsx' Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" Snippets
Plug 'SirVer/ultisnips'
Plug 'quangnguyen30192/cmp-nvim-ultisnips'
"Plug 'nvim-lua/lsp_extensions.nvim'
"Plug 'ray-x/lsp_signature.nvim'
" Javascript LSPs " Javascript LSPs
Plug 'denoland/deno' Plug 'denoland/deno'
@@ -73,144 +86,53 @@ Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
call plug#end() call plug#end()
set autowrite " Better auto-completions
set completeopt=menuone,noinsert,noselect
" Go configuration " Use tree-sitter for Lua parsing to get around a bug with Vim's formatter
let g:go_highlight_fields = 1 " https://github.com/neovim/neovim/issues/20456
let g:go_highlight_functions = 1 lua <<EOF
let g:go_highlight_function_calls = 1 require('nvim-treesitter.configs').setup({
let g:go_highlight_extra_types = 1 ensure_installed = {"lua"},
let g:go_highlight_operators = 1 auto_install = true,
highlight = {
let g:go_auto_type_info = 1 enable = true,
},
" UltiSnips keybindings })
let g:UltiSnipsExpandTrigger="<tab>" EOF
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" Disable the scroll sync in the markdown preview
let g:mkdp_preview_options = {
\ 'disable_sync_scroll': 1,
\ }
" LaTeX shell escape
let g:vimtex_compiler_latexmk = {
\ 'options' : [
\ '-shell-escape',
\ '-verbose',
\ '-file-line-error',
\ '-synctex=1',
\ '-interaction=nonstopmode',
\ ],
\ }
" Run the Java formatter on save
augroup autoformat_settings
autocmd FileType java AutoFormatBuffer google-java-format
augroup END
" Run black formatter on save
autocmd BufWritePre *.py execute ':Black'
" Add custom syntax for files
au BufRead,BufNewFile *.asm set filetype=mips
autocmd FileType tex set spell
" Python syntax config
let g:python_highlight_all = 1
" Settings for markdown
let g:vim_markdown_new_list_item_indent = 0
let g:vim_markdown_auto_insert_bullets = 0
let g:vim_markdown_frontmatter = 1
" Vimtex configuration
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_mode=0
" Javascript Flow syntax support
let g:javascript_plugin_flow=1
" LSP configuration " LSP configuration
lua << END lua << EOF
local cmp = require'cmp'
local lspconfig = require'lspconfig' local cmp = require'cmp'
cmp.setup({ local lspconfig = require'lspconfig'
cmp.setup({
snippet = { snippet = {
-- REQUIRED by nvim-cmp. get rid of it once we can -- REQUIRED - you must specify a snippet engine
expand = function(args) expand = function(args)
vim.fn["vsnip#anonymous"](args.body) vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end, end,
}, },
mapping = { mapping = {
-- Tab immediately completes. C-n/C-p to select. ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<Tab>'] = cmp.mapping.confirm({ select = true }) ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}, },
sources = cmp.config.sources( sources = cmp.config.sources({
{
-- TODO: currently snippets from lsp end up getting prioritized -- stop that!
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
} { name = 'ultisnips' }, -- For ultisnips users.
-- Disable 'path' auto-completion }, {
--[[ { name = 'buffer' },
{ })
{ name = 'path' },
}
--]]
),
experimental = {
ghost_text = true,
},
})
-- Enable completing paths in :
--cmp.setup.cmdline(':', {
-- sources = cmp.config.sources({
-- { name = 'path' }
-- })
--})
-- Setup lspconfig.
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('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>r', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>a', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
-- Get signatures (and _only_ signatures) when in argument lists.
require "lsp_signature".on_attach({
doc_lines = 0,
handler_opts = {
border = "none"
},
}) })
end
local capabilities = require('cmp_nvim_lsp').default_capabilities() local capabilities = require('cmp_nvim_lsp').default_capabilities()
lspconfig.rust_analyzer.setup {
-- Rust language server
lspconfig.rust_analyzer.setup {
on_attach = on_attach, on_attach = on_attach,
flags = { flags = {
debounce_text_changes = 150, debounce_text_changes = 150,
@@ -228,41 +150,105 @@ lspconfig.rust_analyzer.setup {
}, },
}, },
capabilities = capabilities, capabilities = capabilities,
} }
lspconfig.java_language_server.setup{ -- Java language server
lspconfig.java_language_server.setup{
on_attach = on_attach, on_attach = on_attach,
cmd = {"/usr/share/java/java-language-server/lang_server_linux.sh"}, cmd = {"/usr/share/java/java-language-server/lang_server_linux.sh"},
} }
-- Required for the Deno Language Server -- Required for the Deno Language Server
vim.g.markdown_fenced_languages = { vim.g.markdown_fenced_languages = {
"ts=typescript" "ts=typescript"
} }
-- Deno Javascript Language Server -- Deno Javascript Language Server
--[[ lspconfig.denols.setup{
lspconfig.denols.setup{
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
} }
--]]
-- Flow Javascript Language Server --[[
lspconfig.flow.setup{ -- Flow Javascript Language Server
lspconfig.flow.setup{
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
cmd = {"flow", "lsp"} cmd = {"flow", "lsp"}
} }
--]]
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, { vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = true, virtual_text = true,
signs = true, signs = true,
update_in_insert = true, update_in_insert = true,
} }
) )
END EOF
" Auto-save buffers when they switch
" Probably not necessary, but helps if I forget to save
set autowrite
" Go development options
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_operators = 1
let g:go_auto_type_info = 1
" UltiSnips keybindings
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" Disable the scroll sync in the markdown preview
let g:mkdp_preview_options = {
\ 'disable_sync_scroll': 1,
\ }
" Vimtex configuration
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_mode=0
let g:vimtex_compiler_latexmk = {
\ 'options' : [
\ '-shell-escape',
\ '-verbose',
\ '-file-line-error',
\ '-synctex=1',
\ '-interaction=nonstopmode',
\ ],
\ }
" Turn on spell checking and concealing for Tex files automatically
autocmd FileType tex setlocal spell tw=80 colorcolumn=81 conceallevel=1
" Turn on text concealing in Tex files
let g:tex_conceal='abdmg'
hi Conceal ctermbg=none
" Auto-formatting
augroup autoformat_settings
autocmd FileType java AutoFormatBuffer google-java-format
autocmd BufWritePre *.py Black
augroup END
" Assume that all asm files are MIPS assembly syntax
au BufRead,BufNewFile *.asm set filetype=mips
" Python syntax config
let g:python_highlight_all = 1
" Settings for markdown
let g:vim_markdown_new_list_item_indent = 0
let g:vim_markdown_auto_insert_bullets = 0
let g:vim_markdown_frontmatter = 1
" Javascript Flow syntax support
let g:javascript_plugin_flow=1
" Enable type inlay hints " Enable type inlay hints
autocmd CursorHold,CursorHoldI *.rs :lua require'lsp_extensions'.inlay_hints{ only_current_line = true } autocmd CursorHold,CursorHoldI *.rs :lua require'lsp_extensions'.inlay_hints{ only_current_line = true }
@@ -276,10 +262,8 @@ let g:rustfmt_autosave = 1
let g:rustfmt_emit_files = 1 let g:rustfmt_emit_files = 1
let g:rustfmt_fail_silently = 0 let g:rustfmt_fail_silently = 0
" Better auto-completions
set completeopt=menuone,noinsert,noselect
" Prevent rust-analyzer from jumping the code around " Prevent the text from jumping around
set signcolumn=yes set signcolumn=yes
" Proper search " Proper search
@@ -292,8 +276,7 @@ set gdefault
set nofoldenable set nofoldenable
" Vertical bar at 80 characters " Vertical bar at 80 characters
set cc=80 set colorcolumn=80
set tw=792034
set background=dark set background=dark
set clipboard=unnamedplus set clipboard=unnamedplus