diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 43be28d..2554e12 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -1,62 +1,75 @@ 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' -" Java auto formatting +" Uxntal +Plug 'karolbelina/uxntal.vim' -" Add maktaba and codefmt to the runtimepath. -" (The latter must be installed before it can be used.) +Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} + +" 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-codefmt' -" Also add Glaive, which is used to configure codefmt's maktaba flags. See -" `:help :Glaive` for usage. Plug 'google/vim-glaive' -" Kotlin -Plug 'udalov/kotlin-vim' - -" Go development -Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } - " Formatter for Python Plug 'psf/black' + +" Development Packs + + +" Go +Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } + +" Rust +Plug 'rust-lang/rust.vim' + " Colorscheme Plug 'morhetz/gruvbox' -" Live preview for markdown +" For previewing markdown in a web browser 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 Plug 'hrsh7th/cmp-vsnip', {'branch': 'main'} Plug 'hrsh7th/vim-vsnip' -" More syntax -Plug 'rust-lang/rust.vim' -Plug 'plasticboy/vim-markdown' -Plug 'vim-python/python-syntax' -Plug 'karolbelina/uxntal.vim' +" Latex +Plug 'lervag/vimtex' +Plug 'KeitaNakamura/tex-conceal.vim' -" Javascript Syntax -Plug 'pangloss/vim-javascript' -Plug 'mxw/vim-jsx' +" LSP Config +Plug 'neovim/nvim-lspconfig' +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 Plug 'denoland/deno' @@ -73,15 +86,117 @@ Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } call plug#end() +" Better auto-completions +set completeopt=menuone,noinsert,noselect + +" Use tree-sitter for Lua parsing to get around a bug with Vim's formatter +" https://github.com/neovim/neovim/issues/20456 +lua <'] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'ultisnips' }, -- For ultisnips users. + }, { + { name = 'buffer' }, + }) + }) + + local capabilities = require('cmp_nvim_lsp').default_capabilities() + + -- Rust language server + lspconfig.rust_analyzer.setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }, + settings = { + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + }, + completion = { + postfix = { + enable = false, + }, + }, + }, + }, + capabilities = capabilities, + } + + -- Java language server + lspconfig.java_language_server.setup{ + on_attach = on_attach, + cmd = {"/usr/share/java/java-language-server/lang_server_linux.sh"}, + } + + -- Required for the Deno Language Server + vim.g.markdown_fenced_languages = { + "ts=typescript" + } + + -- Deno Javascript Language Server + lspconfig.denols.setup{ + on_attach = on_attach, + flags = lsp_flags, + } + + --[[ + -- Flow Javascript Language Server + lspconfig.flow.setup{ + on_attach = on_attach, + flags = lsp_flags, + cmd = {"flow", "lsp"} + } + --]] + + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = true, + signs = true, + update_in_insert = true, + } + ) +EOF + +" Auto-save buffers when they switch +" Probably not necessary, but helps if I forget to save set autowrite -" Go configuration +" 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 @@ -94,7 +209,10 @@ let g:mkdp_preview_options = { \ 'disable_sync_scroll': 1, \ } -" LaTeX shell escape + +" Vimtex configuration +let g:vimtex_view_method = 'zathura' +let g:vimtex_quickfix_mode=0 let g:vimtex_compiler_latexmk = { \ 'options' : [ \ '-shell-escape', @@ -105,19 +223,22 @@ let g:vimtex_compiler_latexmk = { \ ], \ } -" Run the Java formatter on save +" 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 -" Run black formatter on save -autocmd BufWritePre *.py execute ':Black' - -" Add custom syntax for files +" Assume that all asm files are MIPS assembly syntax au BufRead,BufNewFile *.asm set filetype=mips -autocmd FileType tex set spell - " Python syntax config let g:python_highlight_all = 1 @@ -126,144 +247,9 @@ 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 -lua << END -local cmp = require'cmp' - -local lspconfig = require'lspconfig' -cmp.setup({ - snippet = { - -- REQUIRED by nvim-cmp. get rid of it once we can - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - mapping = { - -- Tab immediately completes. C-n/C-p to select. - [''] = cmp.mapping.confirm({ select = true }) - }, - sources = cmp.config.sources( - { - -- TODO: currently snippets from lsp end up getting prioritized -- stop that! - { name = 'nvim_lsp' }, - } - -- Disable 'path' auto-completion - --[[ - { - { 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 - 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', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'r', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'a', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) - buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'q', 'lua vim.diagnostic.set_loclist()', opts) - buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", 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() -lspconfig.rust_analyzer.setup { - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - }, - settings = { - ["rust-analyzer"] = { - cargo = { - allFeatures = true, - }, - completion = { - postfix = { - enable = false, - }, - }, - }, - }, - capabilities = capabilities, -} - -lspconfig.java_language_server.setup{ - on_attach = on_attach, - cmd = {"/usr/share/java/java-language-server/lang_server_linux.sh"}, -} - --- Required for the Deno Language Server -vim.g.markdown_fenced_languages = { - "ts=typescript" -} - --- Deno Javascript Language Server ---[[ -lspconfig.denols.setup{ - on_attach = on_attach, - flags = lsp_flags, -} ---]] - --- Flow Javascript Language Server -lspconfig.flow.setup{ - on_attach = on_attach, - flags = lsp_flags, - cmd = {"flow", "lsp"} -} - -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = true, - signs = true, - update_in_insert = true, - } -) -END - " Enable type inlay hints 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_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 " Proper search @@ -292,8 +276,7 @@ set gdefault set nofoldenable " Vertical bar at 80 characters -set cc=80 -set tw=792034 +set colorcolumn=80 set background=dark set clipboard=unnamedplus