-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
472 lines (391 loc) · 15.1 KB
/
vimrc
File metadata and controls
472 lines (391 loc) · 15.1 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
set nocompatible " Don't be compatible with vi
lan en_US.UTF-8
filetype off
" run to install :PluginInstall
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-scripts/Mark'
Plugin 'tpope/vim-fugitive'
Plugin 'shumphrey/fugitive-gitlab.vim'
Plugin 'junegunn/gv.vim'
Plugin 'tpope/vim-markdown'
Plugin 'tpope/vim-unimpaired'
if !exists('g:use_neo_tree') || !g:use_neo_tree
Plugin 'preservim/nerdtree'
Plugin 'vsushkov/nerdtree-ack'
endif
Plugin 'sudar/vim-arduino-syntax'
Plugin 'romank0/vim-bookmarks'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'Vimjas/vim-python-pep8-indent'
Plugin 'will133/vim-dirdiff'
Plugin 'leafgarland/typescript-vim'
Bundle 'yssl/QFEnter'
Plugin 'tpope/vim-dispatch'
"Plugin 'janko-m/vim-test'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'eshion/vim-sync'
Plugin 'alfredodeza/pytest.vim'
Plugin 'fratajczak/one-monokai-vim'
"Plugin 'sansyrox/vim-python-virtualenv'
Plugin 'jmcantrell/vim-virtualenv'
"Plugin 'psf/black'
Plugin 'dense-analysis/ale'
Plugin 'mbbill/undotree'
"Plugin 'joshbohde/vim-curl'
Plugin 'puremourning/vimspector'
" Plugin 'rafikdraoui/jj-diffconflicts'
" Plugin 'neoclide/coc.nvim', {'branch': 'release'}
if !has('nvim') && v:version >= 900
Plugin 'bfrg/vim-qf-diagnostics'
endif
" All of your Plugins must be added before the following line
call vundle#end() " required
let mapleader="," " change the leader to be a comma vs slash
let maplocalleader = "\\"
syntax on " syntax highlighing
filetype on " try to detect filetypes
filetype plugin indent on " enable loading indent file for filetype
set number " Display line numbers
set numberwidth=1 " using only 1 column (and 1 space) while possible
set background=dark " We are using dark background in vim
set title " show title in console title bar
set wildmenu " Menu completion in command mode on <Tab>
set autoindent " always set autoindenting on
set smartindent " use smart indent if there is no indent file
set tabstop=4 " <tab> inserts 4 spaces
set shiftwidth=4 " indent level is 4 spaces wide.
set softtabstop=4 " <BS> over an autoindent deletes both spaces.
set expandtab " Use spaces, not tabs, for autoindent/tab key.
set backspace=2 " Allow backspacing over autoindent, EOL, and BOL
set showmatch " Briefly jump to a paren once it's balanced
set ruler " show the cursor position all the time
set nostartofline " Avoid moving cursor to BOL when jumping around
set virtualedit=block " Let cursor move past the last char in <C-v> mode
set shiftround " rounds indent to a multiple of shiftwidth
set matchpairs+=<:> " show matching <> (html mainly) as well
set foldmethod=indent " allow us to fold on indents
set foldlevel=99 " don't fold by default
set secure
set exrc
set clipboard=unnamed
set scrolloff=8
" colorscheme one-monokai
colorscheme default
"colorscheme solarized
set background=dark
set termguicolors
" enable if terminal does not support truecolor
" set t_Co=256
set wildmode=longest,list
" Ignore these files when completing
set wildignore+=*.o,*.obj,.git,*.pyc,*.jar,*.class
set wildignore+=eggs/**
set wildignore+=*.egg-info/**
set wildignore+=.git/**
set wildignore+=.idea/**
set wildignore+=.envs/**
set wildignore+=tags*
" Folds
" set foldcolumn=1
highlight FoldColumn guibg=grey21
highlight Folded guibg=grey21
function! FoldHelp()
echo "FoldByExpr"
echo "let &foldexpr='getline(v:lnum)=~''BasicBinder'''"
endfunction
command FoldByExpr :set foldmethod=expr foldexpr foldlevel=0
" set foldmethod=expr foldexpr foldlevel=0
" let &foldexpr='getline(v:lnum)=~''BasicBinder'''
"""" Messages, Info, Status
set vb t_vb= " Disable all bells. I hate ringing/flashing.
set confirm " Y-N-C prompt if closing with unsaved changes.
set showcmd " Show incomplete normal mode commands as I type.
set report=0 " : commands always print changed line count.
set shortmess+=a " Use [+]/[RO]/[w] for modified/readonly/written.
set ruler " Show some info, even without statuslines.
set laststatus=2 " Always show statusline, even if only 1 window.
"let &stl="%F%m%r%h%w\ [%{&ff}]\ [%Y]\ %P\ %=\ [a=\%03.3b]\ [h=\%02.2B]\ [%l,%v]"
let &stl="%F%m%r%h%w\ [%{&ff}]\ [%Y]\ %P\ %=%{fugitive#statusline()}\ [a=\%03.3b]\ [h=\%02.2B]\ [%l,%v]"
"""" Reading/Writing
set noautowrite " Never write a file unless I request it.
set noautowriteall " NEVER.
set noautoread " Don't automatically re-read changed files.
set modeline " Allow vim options to be embedded in files;
set modelines=5 " they must be within the first or last 5 lines.
set ffs=unix,dos,mac " Try recognizing dos, unix, and mac line endings.
" backup options
set nobackup
set backupdir=~/.backup
set viminfo=%100,'100,/100,h,\"500,:100
set history=10000
if !has('nvim')
set viminfo+=n~/.viminfo
else
set viminfo+=n~/.shada
endif
" undo options
set undolevels=10000
if has('persistent_undo')
if has('nvim')
set undodir=$HOME/.vimundo-nvim
else
set undodir=$HOME/.vimundo
endif
set undofile
endif
map <Leader>u :UndotreeToggle<CR>
" displays tabs with :set list & displays when a line runs off-screen
set listchars=tab:>-,eol:$,trail:-,precedes:<,extends:>
"set list
""" Searching and Patterns
set ignorecase " Default to using case insensitive searches,
set smartcase " unless uppercase letters are used in the regex.
set smarttab " Handle tabs more intelligently
set hlsearch " Highlight searches by default.
set incsearch " Incrementally search while typing a /regex
set diffopt=filler,iwhite " ignore all whitespace and sync
map <Leader>d "_d
map <Leader>s :%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>
map <Leader>6 <C-^>
map [op :set paste<CR>
map ]op :set nopaste<CR>
if !exists('g:use_neo_tree') || !g:use_neo_tree
" NERDTree
let g:NERDChristmasTree = 1
let g:NERDTreeWinPos = "left"
let g:NERDTreeWinSize = 60
let g:NERDTreeCaseSensitiveSort = 1
let g:NERDTreeChDirMode = 2
let NERDTreeIgnore = ['\.pyc$', '__pycache__']
map <Leader>t :NERDTreeToggle <cr>
map <Leader>f :NERDTreeFind <cr>
endif
" Fugitive
map <leader>gs :Git<cr>
map <leader>gw :Git write<cr>
map <leader>gd :Gdiff<cr>
map <leader>gc :Git commit<cr>
map <leader>gb :Git blame<cr>
map <leader>gl :Git log
" JJ
map <leader>jd :Jdiff<cr>
map <leader>js :J status<cr>
map <leader>jl :J<cr>
map <leader>jj :J<cr>
" Fugitive-Gitlab
let g:fugitive_gitlab_domains = ['https://newrepo.jikotech.com/']
" vim-test
"let test#strategy = "dispatch"
"map <Leader>xt :TestFile<cr>
"map <Leader>xr :TestLast<cr>
"
" pytest
map <Leader>xt :Pytest project verbose<cr>
map <Leader>xn :Pytest next<cr>
" Python
" let g:black_use_virtualenv = 'true'
" augroup PythonBlack
" autocmd BufWritePre *.py execute ':Black'
" augroup END
"
function! RuffAll(buffer) abort
" Use ALE's root if available; fall back to the file's dir
let l:root = getbufvar(a:buffer, 'ale_root', expand('#'.a:buffer.':p:h'))
let l:ruff = shellescape(get(g:, 'ale_python_ruff_executable', 'ruff'))
return {
\ 'command': 'cd ' . fnameescape(l:root)
\ . ' && ' . l:ruff . ' check --fix %t'
\ . ' ; ' . l:ruff . ' format %t',
\ 'read_temporary_file': 1,
\}
endfunction
let g:ale_fixers = {'python': [function('RuffAll'), 'trim_whitespace']}
let g:ale_linters = {
\ 'python': ['ruff'],
\}
" let g:ale_python_ruff_options = '--select I,F,E,W,C90,N,UP,YTT,S,BLE,B,A,COM,C4,DTZ,ISC,ICN,G,PIE,T20,PYI,PT,Q,RSE,RET,SLF,SIM,TID,ARG,PD,PL,TRY,NPY,RUF'
let g:ale_python_ruff_options = ''
let g:ale_python_ruff_format_options = ''
let g:ale_fix_on_save = 1
nmap ]of :let g:ale_fix_on_save = 0<CR>
nmap [of :let g:ale_fix_on_save = 1<CR>
"au BufRead *.py compiler nose
"au FileType python set omnifunc=pythoncomplete#Complete
"au FileType python setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4 smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class,with
au BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
" Don't let pyflakes use the quickfix window
let g:pyflakes_use_quickfix = 0
let python_highlight_all = 1
nmap <Leader>sb Obreakpoint()<Esc>:w<CR>
function ConcealPath()
syntax match ConcealedPath /^\([^|]*|\)\{2,2}/ conceal cchar=↭
setlocal conceallevel=2
setlocal concealcursor=nvic
setlocal nowrap
endfunction
function UnconcealPath()
setlocal conceallevel=0
setlocal wrap
endfunction
nmap <Leader>oqc :copen<CR>:call ConcealPath()<CR>
nmap <Leader>oqu :copen<CR>:call UnconcealPath()<CR>
augroup qf-diagnostics-user
autocmd!
autocmd QuickfixCmdPost make DiagnosticsPlace
autocmd QuickfixCmdPost lmake LDiagnosticsPlace
augroup END
au FileType coffee setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4 smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class,with
au FileType javascript setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 smartindent cinwords=if,elif,else,for,while,try,except,finally errorformat=%.%#\ at\ %.%#(%f:%l:%c),%-G%.%#
au FileType sh setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 smartindent
au BufRead *.md set filetype=markdown
au BufRead *.cpp,*.c,*.h set cindent
au FileType markdown set tw=79
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorcolumn
au WinLeave * setlocal nocursorcolumn
"disabled in favour of term2 cursor guide
"au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
"au WinLeave * setlocal nocursorline
augroup END
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
nmap <Leader>or :set invrnu<CR>
" Add the virtualenv's site-packages to vim path
if has('python')
python << EOF
import os
import subprocess
if "VIRTUAL_ENV" in os.environ:
project_base_dir = os.environ["VIRTUAL_ENV"]
script = os.path.join(project_base_dir, "bin/activate")
pipe = subprocess.Popen(". %s; env" % script, stdout=subprocess.PIPE, shell=True)
output = pipe.communicate()[0].decode('utf8').splitlines()
env = dict((line.split("=", 1) for line in output))
os.environ.update(env)
EOF
endif
if exists("&colorcolumn")
au FileType python set colorcolumn=89
au FileType markdown set colorcolumn=80
au FileType java set colorcolumn=121
endif
" jump to last line edited in a given file (based on .viminfo)
autocmd BufReadPost *
\ if line("'\"") > 0|
\ if line("'\"") <= line("$")|
\ exe("norm '\"")|
\ else|
\ exe "norm $"|
\ endif|
\ endif
" Bookmarks
let g:bookmark_no_default_key_mappings = 1
let g:bookmark_highlight_lines = 1
nmap <Leader><Leader> <Plug>BookmarkToggle
nmap <Leader>bi <Plug>BookmarkAnnotate
nmap <Leader>ba <Plug>BookmarkShowAll
nmap <Leader>bj <Plug>BookmarkNext
nmap <Leader>bk <Plug>BookmarkPrev
nmap <Leader>bc <Plug>BookmarkClear
" Filename
if has("mac") || has("gui_macvim") || has("gui_mac")
" relative path (src/foo.txt)
nnoremap <leader>cfr :let @*=expand("%")<CR>
" relative path with line (src/foo.txt:23)
nnoremap <leader>cfl :let @*=expand("%") . ":" . line(".")<CR>
" absolute path (/something/src/foo.txt)
nnoremap <leader>cfa :let @*=expand("%:p")<CR>
" filename (foo.txt)
nnoremap <leader>cff :let @*=expand("%:t")<CR>
" directory name (/something/src)
nnoremap <leader>cfd :let @*=expand("%:p:h")<CR>
endif
" HP42
autocmd BufRead,BufNewFile *.41,*.42 :source ~/.vim/syntax/hp41.vim
autocmd BufRead,BufNewFile *.41,*.42 :source ~/.vim/ftplugin/hp41.vim
" Airline
let g:airline#extensions#tabline#enabled = 1
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V',
\ '' : 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ }
let g:airline_section_y='%P'
let g:airline_section_x='chr:%b[0x%B]'
let g:airline_section_a=''
let g:airline_section_z='%l/%L,%v'
let g:airline#parts#ffenc#skip_expected_string='utf-8[unix]'
let g:airline#extensions#wordcount#filetypes='[]'
if executable('rg')
" set grepprg=rg\ -n\ --no-heading\ --color=never\ --hidden
set grepprg=rg\ --vimgrep\ --smart-case\ --hidden\ --glob\ '!.git/*'
set grepformat=%f:%l:%c:%m
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
let g:ctrlp_cmd = 'CtrlPMRUFiles'
" nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
set langmap=ёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕHГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ;`qwertyuiop[]asdfghjkl\\;'zxcvbnm\\,.~QWERTYUIOP{}ASDFGHJKL:\\"ZXCVBNM<>
function! CallChatGPTAPI(instructions) abort
let l:API_KEY = $CHAT_GPT_API_KEY
let l:API_URL = "https://api.openai.com/v1/completions"
let l:current_selection = getline("'<", "'>")
let l:prompt = a:instructions . "\n" . join(l:current_selection, "\n")
let l:headers = {
\ 'Content-Type': 'application/json',
\ 'Authorization': 'Bearer ' . l:API_KEY
\ }
" let l:response = json_decode(curl#request('POST', l:API_URL, json_encode(l:data), l:headers))
" let l:result = l:response['choices'][0]['text']
" let l:response = py3eval("vim.call('ch_open', ['https://api.openai.com/v4/engines/davinci-codex/completions', 'block', {'headers': vim.eval('l:headers'), 'method': 'POST', 'payload': vim.eval('json_encode(l:data)') }])")
" let l:result = json_decode(l:response)['choices'][0]['text']
python3 << EOF
import vim
import json
import http.client
import urllib.parse
from io import StringIO
headers = vim.eval('l:headers')
prompt = vim.eval('l:prompt')
data = json.dumps({
'model': 'text-davinci-003',
'prompt': prompt,
'max_tokens': 300,
'temperature': 0.5,
}).encode('utf-8')
url = vim.eval('l:API_URL')
parsed_url = urllib.parse.urlparse(url)
ssl = False if parsed_url.scheme == 'http' else True
connection = http.client.HTTPSConnection(parsed_url.netloc) if ssl else http.client.HTTPConnection(parsed_url.netloc)
connection.request('POST', parsed_url.path, body=data, headers=headers)
response = connection.getresponse()
response_text = response.read().decode('utf-8')
response_json = json.loads(response_text)
result = response_json['choices'][0]['text']
vim.command("new")
vim.current.buffer.append(result.split('\n'), 0)
EOF
endfunction
" vimspector
let g:vimspector_enable_mappings = 'HUMAN'
command! -nargs=1 ChatGPT :call CallChatGPTAPI(<q-args>)