" ~/.vimrc — Vim 9 configuration " Requires: vim-plug, rust-analyzer in PATH, fzf binary let mapleader = ' ' " ── Bootstrap vim-plug ──────────────────────────────────────────────────────── let s:plug_path = expand('~/.vim/autoload/plug.vim') if !filereadable(s:plug_path) silent execute '!curl -fLo ' .. s:plug_path .. ' --create-dirs ' \ .. 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif " ── Plugins ─────────────────────────────────────────────────────────────────── call plug#begin() Plug 'yegappan/lsp' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' Plug 'ghifarit53/tokyonight-vim' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' call plug#end() " ── General settings ────────────────────────────────────────────────────────── filetype plugin indent on syntax enable set number " show line numbers set signcolumn=yes " always show sign column; prevents layout shift from LSP diagnostics set updatetime=300 " ms before swap write / CursorHold fires; speeds up LSP diagnostics set hidden " allow switching away from a modified buffer without saving set tabstop=4 " displays as 4 spaces set shiftwidth=4 " >> / << indent by 4 spaces set softtabstop=4 " in insert mode inserts/deletes 4 spaces set expandtab " insert spaces instead of tab characters set ignorecase " case-insensitive search by default set smartcase " override ignorecase when pattern contains uppercase set incsearch " highlight matches while typing search pattern set hlsearch " highlight all matches after search set splitbelow " :split opens new window below set splitright " :vsplit opens new window to the right set scrolloff=8 " keep 8 lines of context above/below cursor when scrolling set clipboard=unnamedplus " yank/put use the system clipboard automatically set mouse=a " enable mouse support in all modes " ── File clutter ─────────────────────────────────────────────────────────────── set nobackup set nowritebackup let &directory = expand('~/.vim/swap//') silent! call mkdir(expand('~/.vim/swap'), 'p', 0700) set undofile let &undodir = expand('~/.vim/undo//') silent! call mkdir(expand('~/.vim/undo'), 'p', 0700) " ── Colors ──────────────────────────────────────────────────────────────────── set termguicolors let g:tokyonight_style = 'night' colorscheme tokyonight " ── LSP (yegappan/lsp) ──────────────────────────────────────────────────────── def g:LspOnSetup() var lspServers = [ { name: 'rust', filetype: ['rust'], path: 'rust-analyzer', syncInit: true, } ] g:LspAddServer(lspServers) enddef augroup MyLsp autocmd! autocmd User LspSetup call g:LspOnSetup() autocmd FileType rust { nnoremap gd LspGotoDefinition nnoremap gD LspGotoDeclaration nnoremap gi LspGotoImpl nnoremap gr LspShowReferences nnoremap gy LspGotoTypeDef nnoremap K LspHover nnoremap lr LspRename nnoremap la LspCodeAction nnoremap lf LspFormat nnoremap ld LspDiagShow nnoremap [d LspDiagPrev nnoremap ]d LspDiagNext nnoremap lo LspOutline nnoremap li LspInlayHints toggle } augroup END " ── Search ──────────────────────────────────────────────────────────────────── nnoremap nohlsearch " ── Window navigation ────────────────────────────────────────────────────────── nnoremap h nnoremap j nnoremap k nnoremap l " ── Airline ─────────────────────────────────────────────────────────────────── let g:airline_theme = 'tokyonight' let g:airline_powerline_fonts = 0 " set to 1 if you have a Nerd Font let g:airline#extensions#lsp#enabled = 1 " ── FZF ─────────────────────────────────────────────────────────────────────── " Use ripgrep for :Files if available if executable('rg') set grepprg=rg\ --vimgrep\ --smart-case set grepformat=%f:%l:%c:%m endif " Layout let g:fzf_layout = { 'down': '40%' } let g:fzf_preview_window = ['right:50%:hidden', 'ctrl-/'] " FZF keymaps nnoremap Files nnoremap Buffers nnoremap rg Rg nnoremap fg GFiles nnoremap fl BLines nnoremap fh History nnoremap fc Commands nnoremap fm Maps " Word search under cursor nnoremap fw execute 'Rg ' .. expand('')