Skip to content

Instantly share code, notes, and snippets.

@MindFlavor
Last active February 14, 2023 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MindFlavor/2467f53353595ebd3e10875f41bbc811 to your computer and use it in GitHub Desktop.
Save MindFlavor/2467f53353595ebd3e10875f41bbc811 to your computer and use it in GitHub Desktop.
" config based on awesome https://sharksforarms.dev/posts/neovim-rust/
syntax on
syntax enable
filetype plugin indent on
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.local/share/nvim/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
Plug 'simrat39/rust-tools.nvim'
Plug 'hrsh7th/vim-vsnip'
"Plug 'tpope/vim-sensible'
Plug 'scrooloose/nerdtree'
Plug 'rust-lang/rust.vim'
Plug 'godlygeek/tabular'
Plug 'tpope/vim-fugitive'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'ardagnir/united-front'
"Plug 'zah/nim.vim'
Plug 'nvim-lua/completion-nvim'
Plug 'ziglang/zig.vim'
Plug 'mhartington/oceanic-next'
call plug#end()
set background=dark
set undofile
set undodir=~/.vim/undo
" number of undo saved
set undolevels=100000
let mapleader = " "
" this will sync the unnamed register
" with the OS's clipboard
set clipboard=unnamedplus
augroup filetype_rust
autocmd!
autocmd BufReadPost *.rs setlocal filetype=rust
augroup END
let g:rustfmt_autosave = 1
let g:airline_theme = 'oceanicnext'
set number
map <C-t> :NERDTreeToggle<CR>
noremap <silent> <C-Left> :tabmove -1<CR>
noremap <silent> <C-Right> :tabmove +1<CR>
noremap <silent> <S-Right> :vertical resize +1<CR>
noremap <silent> <S-Left> :vertical resize -1<CR>
noremap <silent> <S-Down> :resize +1<CR>
noremap <silent> <S-Up> :resize -1<CR>
nnoremap <Right> <C-w>l
nnoremap <Left> <C-w>h
nnoremap <Up> <C-w>k
nnoremap <Down> <C-w>j
nnoremap <Tab> gt
nnoremap <S-Tab> gT
let g:airline_powerline_fonts = 1
set t_Co=256
if (has("termguicolors"))
set termguicolors
endif
let g:oceanic_next_terminal_bold = 1
let g:oceanic_next_terminal_italic = 1
colorscheme OceanicNext
" Set completeopt to have a better completion experience
" :help completeopt
" menuone: popup even when there's only one match
" noinsert: Do not insert text until a selection is made
" noselect: Do not select, force user to select one from the menu
set completeopt=menuone,noinsert,noselect
" Avoid showing extra messages when using completion
set shortmess+=c
" 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 nvim_lsp = require'lspconfig'
local opts = {
tools = { -- rust-tools options
autoSetHints = true,
hover_with_actions = true,
inlay_hints = {
show_parameter_hints = false,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {
-- on_attach is a callback called when the language server attachs to the buffer
-- on_attach = on_attach,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy on save
checkOnSave = {
command = "clippy"
},
cargo = {
features = "all"
},
}
}
},
}
require('rust-tools').setup(opts)
-- From https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#pylsp
-- Install using pipx install 'python-lsp-server[all]
require'lspconfig'.pylsp.setup{}
local lspconfig = require('lspconfig')
local on_attach = function(_, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
require('completion').on_attach()
end
local servers = {'zls'}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
}
end
EOF
" Setup Completion
" See https://github.com/hrsh7th/nvim-cmp#basic-configuration
lua <<EOF
local cmp = require'cmp'
cmp.setup({
-- Enable LSP snippets
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = 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.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
},
})
EOF
" 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>
" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
set updatetime=300
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.diagnostic.open_float(0, {scope="line"})
" 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>
" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes
com! FormatXML :%!python3 -c "import xml.dom.minidom, sys; print(xml.dom.minidom.parse(sys.stdin).toprettyxml())"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment