1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
" ~/.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 " <Tab> displays as 4 spaces
set shiftwidth=4 " >> / << indent by 4 spaces
set softtabstop=4 " <Tab> 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 <buffer> gd <Cmd>LspGotoDefinition<CR>
nnoremap <buffer> gD <Cmd>LspGotoDeclaration<CR>
nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
nnoremap <buffer> gr <Cmd>LspShowReferences<CR>
nnoremap <buffer> gy <Cmd>LspGotoTypeDef<CR>
nnoremap <buffer> K <Cmd>LspHover<CR>
nnoremap <buffer> <leader>lr <Cmd>LspRename<CR>
nnoremap <buffer> <leader>la <Cmd>LspCodeAction<CR>
nnoremap <buffer> <leader>lf <Cmd>LspFormat<CR>
nnoremap <buffer> <leader>ld <Cmd>LspDiagShow<CR>
nnoremap <buffer> [d <Cmd>LspDiagPrev<CR>
nnoremap <buffer> ]d <Cmd>LspDiagNext<CR>
nnoremap <buffer> <leader>lo <Cmd>LspOutline<CR>
nnoremap <buffer> <leader>li <Cmd>LspInlayHints toggle<CR>
}
augroup END
" ── Search ────────────────────────────────────────────────────────────────────
nnoremap <Esc> <Cmd>nohlsearch<CR>
" ── Window navigation ──────────────────────────────────────────────────────────
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>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 <C-p> <Cmd>Files<CR>
nnoremap <C-b> <Cmd>Buffers<CR>
nnoremap <leader>rg <Cmd>Rg<CR>
nnoremap <leader>fg <Cmd>GFiles<CR>
nnoremap <leader>fl <Cmd>BLines<CR>
nnoremap <leader>fh <Cmd>History<CR>
nnoremap <leader>fc <Cmd>Commands<CR>
nnoremap <leader>fm <Cmd>Maps<CR>
" Word search under cursor
nnoremap <leader>fw <Cmd>execute 'Rg ' .. expand('<cword>')<CR>
|