summaryrefslogtreecommitdiff
path: root/vim/.vimrc
blob: 8b964e0ccc667e5c60328e4fcc7bb47cfed11ec6 (plain)
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

" ── 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
set signcolumn=yes
set updatetime=300
set hidden

set tabstop=4
set shiftwidth=4
set expandtab

set ignorecase
set smartcase
set incsearch
set hlsearch

set splitbelow
set splitright
set scrolloff=8

set clipboard=unnamedplus
set mouse=a

" ── 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) ────────────────────────────────────────────────────────
" g:LspOnSetup is called by the User LspSetup autocmd below.
" Variables must be defined and consumed inside the same function call —
" they cannot be captured by an inner autocmd in a def function.
def g:LspOnSetup()
  var lspServers = [
    {
      name: 'rust',
      filetype: ['rust'],
      path: 'rust-analyzer',
      syncInit: true,
    }
  ]

  g:LspAddServer(lspServers)
enddef

autocmd User LspSetup call g:LspOnSetup()

" LSP keymaps (only when LSP is active)
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> <space>r <Cmd>LspRename<CR>
  nnoremap <buffer> <space>a <Cmd>LspCodeAction<CR>
  nnoremap <buffer> <space>f <Cmd>LspFormat<CR>
  nnoremap <buffer> <space>d <Cmd>LspDiagShow<CR>
  nnoremap <buffer> [d       <Cmd>LspDiagPrev<CR>
  nnoremap <buffer> ]d       <Cmd>LspDiagNext<CR>
  nnoremap <buffer> <space>o <Cmd>LspOutline<CR>
  nnoremap <buffer> <space>i <Cmd>LspInlayHints toggle<CR>
}

" ── 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>