Naposledy aktivní 1755459560

.vimrc Raw
1if empty(glob('~/.vim/autoload/plug.vim'))
2 silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
3 \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
4 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
5endif
6
7call plug#begin('~/.vim/plugged')
8Plug 'tpope/vim-vinegar'
9Plug 'tpope/vim-surround'
10Plug 'tpope/vim-commentary'
11Plug 'junegunn/fzf'
12Plug 'junegunn/fzf.vim'
13Plug 'prabirshrestha/vim-lsp'
14call plug#end()
15
16syntax enable
17filetype on
18filetype plugin on
19filetype indent on
20
21set ruler
22set encoding=utf-8 " utf8 by default for new files
23set nocompatible " it's not 1985
24set nobackup " don't create ~backup files
25set noswapfile " don't create .swp file
26set number " show line numbers
27set nowrap " disable wrapping
28set cursorline " highlight current line
29set ttyfast " improve scrolling speed
30set lazyredraw " improve draw speed
31set foldlevelstart=99 " unfold everything by default
32set noerrorbells " disable bell/flash
33set history=1000 " command history length
34set so=10 " horizontal scrollover
35set backspace=2 " make backspace work normally
36set nopaste " normal behavior for paste (don't try to indent)
37set tabpagemax=15 " max 15 tabs open
38set laststatus=2 " always display statusbar
39set previewheight=3 " maximum height for preview window
40set showmatch " highlight matching brace
41set updatetime=750 " improve latency for plugins
42set showcmd " show commands as they're being input
43set autoread " automatically reload when changed externally
44set hlsearch " highlight all search matches
45set incsearch " start searching before hitting 'enter'
46set ignorecase " perform case-insensitive search
47set smartcase " ...unless search term has a capital letter
48set hidden " hide buffers instead of closing them
49set wildmenu " autocomplete for command menu
50set modelines=1 " obey file modelines
51set timeoutlen=1000 " no key delays
52set ttimeoutlen=0 " no key delays
53set completeopt=menu,menuone,longest,preview
54
55set smartindent " autoindent
56set expandtab " replace hard tabs with spaces
57set shiftwidth=2 " tab width = 2 spaces
58set tabstop=2
59set softtabstop=2
60"set textwidth=80 " default max line length
61set colorcolumn=81 " display a marker 1 column after the text width
62" whitespace visibility
63set list listchars=tab:>-,nbsp:~,trail:X
64
65" Mappings {{{1
66" Leader {{{2
67let mapleader = ","
68let g:mapleader = ","
69
70" Fast saving {{{2
71nmap <leader>w :w!<cr>
72
73" Visual mode pressing * or # searches for the current selection
74" Super useful! From an idea by Michael Naumann
75vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
76vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
77
78" Search {{{2
79map <space> /
80map <c-space> ?
81
82" Disable highlight when <leader><cr> is pressed
83map <silent> <leader><cr> :noh<cr>
84
85" Windows {{{2
86noremap <leader>h <C-w>s
87noremap <leader>v <C-w>v
88map <C-j> <C-W>j
89map <C-k> <C-W>k
90map <C-h> <C-W>h
91map <C-l> <C-W>l
92
93" Buffers {{{2
94noremap <leader>bq :q<cr>
95map <leader>bd :Bclose<cr>
96map <leader>ba :bufdo bd<cr>
97map <leader>bo :only<cr>
98
99" Tabs {{{2
100map <leader>tn :tabnew<cr>
101map <leader>to :tabonly<cr>
102noremap <S-l> gt
103noremap <S-h> gT
104map <leader>tc :tabclose<cr>
105map <leader>tm :tabmove
106map <leader>t<leader> :tabnext
107let g:lasttab = 1
108nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
109au TabLeave * let g:lasttab = tabpagenr()
110map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
111
112" Switch CWD to the directory of the open buffer
113map <leader>cd :cd %:p:h<cr>:pwd<cr>
114
115" Remap VIM 0 to first non-blank character
116noremap 0 ^
117noremap ^ 0
118
119
120" Pressing ,ss will toggle and untoggle spell checking
121map <leader>ss :setlocal spell!<cr>
122
123" Shortcuts using <leader>
124map <leader>sn ]s
125map <leader>sp [s
126map <leader>sa zg
127map <leader>s? z=
128
129
130" Netrw {{{2
131let g:netrw_banner = 0
132
133" Plugin Config {{{1
134" FZF {{{2
135nmap <leader>fb :Buffers<cr>
136nmap <leader>ff :Files<cr>
137nnoremap <leader>fg :Rg<space>
138let $FZF_DEFAULT_COMMAND = 'rg --files'
139
140" LSP {{{2
141
142" Go {{{3
143if executable('gopls')
144 au User lsp_setup call lsp#register_server({
145 \ 'name': 'gopls',
146 \ 'cmd': {server_info->['gopls']},
147 \ 'initialization_options': {
148 \ 'completeUnimported': v:true,
149 \ 'matcher': 'fuzzy',
150 \ 'ui.inlayhint.hints': {
151 \ 'assignVariableTypes': v:true,
152 \ 'compositeLiteralFields': v:true,
153 \ 'compositeLiteralTypes': v:true,
154 \ 'constantValues': v:true,
155 \ 'functionTypeParameters': v:true,
156 \ 'parameterNames': v:true,
157 \ 'rangeVariableTypes': v:true,
158 \ },
159 \ 'codelenses': {
160 \ 'generate': v:true,
161 \ 'test': v:true,
162 \ 'run_vulncheck_exp': v:true,
163 \ },
164 \ },
165 \ 'capabilities': {
166 \ 'textDocument': {
167 \ 'documentSymbol': {
168 \ 'hierarchicalDocumentSymbolSupport': v:true,
169 \ },
170 \ },
171 \ },
172 \ 'allowlist': ['go', 'gomod'],
173 \ })
174endif
175
176" Python {{{3
177if executable('pylsp')
178 " pip install python-lsp-server
179 au User lsp_setup call lsp#register_server({
180 \ 'name': 'pylsp',
181 \ 'cmd': {server_info->['pylsp']},
182 \ 'allowlist': ['python'],
183 \ })
184endif
185
186" Javascript/Typescript {{{3
187if executable('typescript-language-server')
188 " npm --global install python-lsp-server
189 au User lsp_setup call lsp#register_server({
190 \ 'name': 'typescript-language-server',
191 \ 'cmd': {server_info->['typescript-language-server', '--stdio']},
192 \ 'initialization_options': {
193 \ 'preferences': {
194 \ 'includeInlayParameterNameHintsWhenArgumentMatchesName': v:true,
195 \ 'includeInlayParameterNameHints': 'all',
196 \ 'includeInlayVariableTypeHints': v:true,
197 \ 'includeInlayPropertyDeclarationTypeHints': v:true,
198 \ 'includeInlayFunctionParameterTypeHints': v:true,
199 \ 'includeInlayEnumMemberValueHints': v:true,
200 \ 'includeInlayFunctionLikeReturnTypeHints': v:true
201 \ },
202 \ },
203 \ 'allowlist': ['javascript', 'javascriptreact', 'typescript', 'typescriptreact'],
204 \ })
205endif
206
207" Buffer setup {{{3
208function! s:on_lsp_buffer_enabled() abort
209 setlocal omnifunc=lsp#complete
210 setlocal signcolumn=yes
211 if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
212 nmap <buffer> gd <plug>(lsp-definition)
213 nmap <buffer> gs <plug>(lsp-document-symbol-search)
214 nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
215 nmap <buffer> gr <plug>(lsp-references)
216 nmap <buffer> gi <plug>(lsp-implementation)
217 nmap <buffer> gt <plug>(lsp-type-definition)
218 nmap <buffer> <leader>rn <plug>(lsp-rename)
219 nmap <buffer> [g <plug>(lsp-previous-diagnostic)
220 nmap <buffer> ]g <plug>(lsp-next-diagnostic)
221 nmap <buffer> K <plug>(lsp-hover)
222 nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
223 nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
224
225 let g:lsp_format_sync_timeout = 1000
226 autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
227
228 " refer to doc to add more commands
229endfunction
230
231augroup lsp_install
232 au!
233 " call s:on_lsp_buffer_enabled only for languages that has the server registered.
234 autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
235augroup END
236
237" END {{{1
238
239colorscheme slate
240set notermguicolors
241hi Normal guibg=NONE ctermbg=NONE
242hi LineNr guibg=NONE ctermbg=NONE
243
244" vim:fdm=marker:fdl=1
245