Last active 1755459560

hash's Avatar hash revised this gist 1755459559. Go to revision

1 file changed, 244 insertions

.vimrc(file created)

@@ -0,0 +1,244 @@
1 + if 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
5 + endif
6 +
7 + call plug#begin('~/.vim/plugged')
8 + Plug 'tpope/vim-vinegar'
9 + Plug 'tpope/vim-surround'
10 + Plug 'tpope/vim-commentary'
11 + Plug 'junegunn/fzf'
12 + Plug 'junegunn/fzf.vim'
13 + Plug 'prabirshrestha/vim-lsp'
14 + call plug#end()
15 +
16 + syntax enable
17 + filetype on
18 + filetype plugin on
19 + filetype indent on
20 +
21 + set ruler
22 + set encoding=utf-8 " utf8 by default for new files
23 + set nocompatible " it's not 1985
24 + set nobackup " don't create ~backup files
25 + set noswapfile " don't create .swp file
26 + set number " show line numbers
27 + set nowrap " disable wrapping
28 + set cursorline " highlight current line
29 + set ttyfast " improve scrolling speed
30 + set lazyredraw " improve draw speed
31 + set foldlevelstart=99 " unfold everything by default
32 + set noerrorbells " disable bell/flash
33 + set history=1000 " command history length
34 + set so=10 " horizontal scrollover
35 + set backspace=2 " make backspace work normally
36 + set nopaste " normal behavior for paste (don't try to indent)
37 + set tabpagemax=15 " max 15 tabs open
38 + set laststatus=2 " always display statusbar
39 + set previewheight=3 " maximum height for preview window
40 + set showmatch " highlight matching brace
41 + set updatetime=750 " improve latency for plugins
42 + set showcmd " show commands as they're being input
43 + set autoread " automatically reload when changed externally
44 + set hlsearch " highlight all search matches
45 + set incsearch " start searching before hitting 'enter'
46 + set ignorecase " perform case-insensitive search
47 + set smartcase " ...unless search term has a capital letter
48 + set hidden " hide buffers instead of closing them
49 + set wildmenu " autocomplete for command menu
50 + set modelines=1 " obey file modelines
51 + set timeoutlen=1000 " no key delays
52 + set ttimeoutlen=0 " no key delays
53 + set completeopt=menu,menuone,longest,preview
54 +
55 + set smartindent " autoindent
56 + set expandtab " replace hard tabs with spaces
57 + set shiftwidth=2 " tab width = 2 spaces
58 + set tabstop=2
59 + set softtabstop=2
60 + "set textwidth=80 " default max line length
61 + set colorcolumn=81 " display a marker 1 column after the text width
62 + " whitespace visibility
63 + set list listchars=tab:>-,nbsp:~,trail:X
64 +
65 + " Mappings {{{1
66 + " Leader {{{2
67 + let mapleader = ","
68 + let g:mapleader = ","
69 +
70 + " Fast saving {{{2
71 + nmap <leader>w :w!<cr>
72 +
73 + " Visual mode pressing * or # searches for the current selection
74 + " Super useful! From an idea by Michael Naumann
75 + vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
76 + vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
77 +
78 + " Search {{{2
79 + map <space> /
80 + map <c-space> ?
81 +
82 + " Disable highlight when <leader><cr> is pressed
83 + map <silent> <leader><cr> :noh<cr>
84 +
85 + " Windows {{{2
86 + noremap <leader>h <C-w>s
87 + noremap <leader>v <C-w>v
88 + map <C-j> <C-W>j
89 + map <C-k> <C-W>k
90 + map <C-h> <C-W>h
91 + map <C-l> <C-W>l
92 +
93 + " Buffers {{{2
94 + noremap <leader>bq :q<cr>
95 + map <leader>bd :Bclose<cr>
96 + map <leader>ba :bufdo bd<cr>
97 + map <leader>bo :only<cr>
98 +
99 + " Tabs {{{2
100 + map <leader>tn :tabnew<cr>
101 + map <leader>to :tabonly<cr>
102 + noremap <S-l> gt
103 + noremap <S-h> gT
104 + map <leader>tc :tabclose<cr>
105 + map <leader>tm :tabmove
106 + map <leader>t<leader> :tabnext
107 + let g:lasttab = 1
108 + nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
109 + au TabLeave * let g:lasttab = tabpagenr()
110 + map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
111 +
112 + " Switch CWD to the directory of the open buffer
113 + map <leader>cd :cd %:p:h<cr>:pwd<cr>
114 +
115 + " Remap VIM 0 to first non-blank character
116 + noremap 0 ^
117 + noremap ^ 0
118 +
119 +
120 + " Pressing ,ss will toggle and untoggle spell checking
121 + map <leader>ss :setlocal spell!<cr>
122 +
123 + " Shortcuts using <leader>
124 + map <leader>sn ]s
125 + map <leader>sp [s
126 + map <leader>sa zg
127 + map <leader>s? z=
128 +
129 +
130 + " Netrw {{{2
131 + let g:netrw_banner = 0
132 +
133 + " Plugin Config {{{1
134 + " FZF {{{2
135 + nmap <leader>fb :Buffers<cr>
136 + nmap <leader>ff :Files<cr>
137 + nnoremap <leader>fg :Rg<space>
138 + let $FZF_DEFAULT_COMMAND = 'rg --files'
139 +
140 + " LSP {{{2
141 +
142 + " Go {{{3
143 + if 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 + \ })
174 + endif
175 +
176 + " Python {{{3
177 + if 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 + \ })
184 + endif
185 +
186 + " Javascript/Typescript {{{3
187 + if 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 + \ })
205 + endif
206 +
207 + " Buffer setup {{{3
208 + function! 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
229 + endfunction
230 +
231 + augroup 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()
235 + augroup END
236 +
237 + " END {{{1
238 +
239 + colorscheme slate
240 + set notermguicolors
241 + hi Normal guibg=NONE ctermbg=NONE
242 + hi LineNr guibg=NONE ctermbg=NONE
243 +
244 + " vim:fdm=marker:fdl=1
Newer Older