-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
247 lines (181 loc) · 6.31 KB
/
vimrc
File metadata and controls
247 lines (181 loc) · 6.31 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
" NOTE: LaunchPythonWithEnv() below has a hardcoded OneDrive path for
" activate_conda_environment.bat — update it if your username or OneDrive
" folder changes.
" Define tmp dir (for `directory` and `backupdir`
let s:vim_tmp = expand('~/tmp/vim')
" Check if directory exists, if not, create it
if !isdirectory(s:vim_tmp)
call mkdir(s:vim_tmp, 'p')
endif
let &directory = '.,' . s:vim_tmp
let &backupdir = s:vim_tmp
let &undodir = s:vim_tmp
set undofile
" vimwiki
let g:vimwiki_folding=1
" File-type detection
filetype plugin indent on
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,latin1
set fileencoding=utf-8
if has('gui_running')
set guifont=Consolas:h10
set lines=999 columns=82
endif
set colorcolumn=77
let g:is_kornshell=1
set wildmenu wildmode=longest:full
set diffopt=filler,horizontal
set hidden
set showcmd
"Look
colorscheme nokto
set guicursor=a:block-blinkon0
set helpheight=15
"ATT: * is a list item:
set formatlistpat=^\\s*\\(\\d\\\|[-*]\\)\\+[\\]:.)}\\t\ ]\\s*
"Syntax highlight and color
syntax enable
"Search
set hlsearch incsearch
"For :set list
set listchars=eol:$,tab:\|-
"Tabs
set tabstop=4
set shiftwidth=4
set expandtab
"numbering (3 cols)
set number
set numberwidth=3
"mark wrapped lines with a "+":
set showbreak=+
"indentation
set autoindent
set ruler
set laststatus=2
set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
"MAPS
function! s:ToggleNumber() abort
if &number
set nonumber showbreak=+
else
set number showbreak=
endif
endfunction
nnoremap <Leader>n :call <SID>ToggleNumber()<CR>
nnoremap <Space> <PageDown>
inoremap jj <Esc>
nnoremap <F9> :set hlsearch! hlsearch?<CR>
" PEP 350 codetags highlighted like TODO in comments (https://peps.python.org/pep-0350/)
augroup ExtraTodo
autocmd!
autocmd Syntax * syntax match ExtraTodo
\ /\C\(\<\(TODO\|MILESTONE\|MLSTN\|DONE\|YAGNI\|TBD\|TOBEDONE\|FIXME\|XXX\|DEBUG\|BROKEN\|REFACTOR\|REFACT\|RFCTR\|OOPS\|SMELL\|NEEDSWORK\|INSPECT\|RFE\|FEETCH\|NYI\|FR\|FTRQ\|FTR\|IDEA\|BUG\|BUGFIX\|NOBUG\|NOFIX\|WONTFIX\|DONTFIX\|NEVERFIX\|UNFIXABLE\|CANTFIX\|REQ\|REQUIREMENT\|STORY\|NOTE\|HELP\|QUESTION\|QUEST\|QSTN\|WTF\|ALERT\|HACK\|CLEVER\|MAGIC\|PORT\|PORTABILITY\|WKRD\|CAVEAT\|CAV\|CAVT\|WARNING\|CAUTION\|TODOC\|DOCDO\|DODOC\|NEEDSDOC\|EXPLAIN\|DOCUMENT\|FAQ\|GLOSS\|GLOSSARY\|SEE\|REF\|REFERENCE\|CRED\|CREDIT\|THANKS\|STAT\|STATUS\|RVD\|REVIEWED\|REVIEW\)\>\|???\|!!!\)/
\ containedin=.*Comment,.*Comment.*
autocmd Syntax * highlight default link ExtraTodo Todo
augroup END
"""""""""" PLUGINS (vim-plug)
" After adding a plugin, to activate run:
" :PlugInstall to install plugins
" :PlugUpdate to update plugins
" :PlugDiff to review the changes from the last update
" :PlugClean to remove plugins no longer in the list
" For more information, see https://github.com/junegunn/vim-plug
"
call plug#begin()
Plug 'tpope/vim-dotenv'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'jpalardy/vim-slime'
let g:slime_target = "vimterminal"
Plug 'tpope/vim-dadbod'
Plug 'kristijanhusak/vim-dadbod-ui'
Plug 'kristijanhusak/vim-dadbod-completion'
Plug 'lambdalisue/vim-fern'
Plug 'lambdalisue/vim-fern-git-status'
call plug#end()
"""""""" Fern
" Use <Leader>ee to choose a dir and set wd there
nnoremap <silent> <Leader>ee :<C-u>Fern <C-r>=<SID>smart_path()<CR><CR>
function! s:smart_path() abort
if !empty(&buftype) || bufname('%') =~# '^[^:]\+://'
return fnamemodify('.', ':p')
endif
return fnamemodify(expand('%'), ':p:h')
endfunction
"""""""" / Fern
" Define function to ask for a conda environment
function! LaunchPythonWithEnv()
let l:conda_json = system('conda env list --json')
if v:shell_error
echoerr "Failed to list Conda environments"
return
endif
let l:parsed = json_decode(l:conda_json)
let l:env_paths = get(l:parsed, 'envs', [])
if empty(l:env_paths)
echoerr "No Conda environments found"
return
endif
let l:env_names = map(copy(l:env_paths), { _, val -> fnamemodify(val, ':t') })
let l:numbered_envs = map(copy(l:env_names), { idx, val -> (idx + 1) . '. ' . val })
let l:choices = ['Select Conda environment:'] + l:numbered_envs
let l:selection = inputlist(l:choices)
if l:selection <= 0 || l:selection > len(l:env_names)
echo "No environment selected"
return
endif
let l:env = l:env_names[l:selection - 1]
let b:slime_vimterminal_cmd = 'C:\Users\Mongeau\OneDrive - Food and Agriculture Organization\Documents\activate_conda_environment.bat ' . l:env
echo "\nSelected Conda environment: " . l:env
" Trigger slime to open the terminal using the configured command
execute 'SlimeConfig'
endfunction
" Map \cc to launch conda environment selection
" NOTE: <C-\><C-n> to go normal mode in terminal
augroup PythonSlimeEnv
autocmd!
autocmd FileType python nnoremap <buffer> <leader>cc :call LaunchPythonWithEnv()<CR>
augroup END
" Config vars
let g:dbs = {}
let s:private_env = expand('~/vimfiles/private/env.vim')
if filereadable(s:private_env)
execute 'source ' . fnameescape(s:private_env)
endif
" / Config vars
" dadbod (database related)
let g:dadbod_shell = ''
let g:db_ui_execute_on_save = 0
if !empty($DB_MAIN_URL) && !empty($DB_ALT_URL)
let g:dbs = {
\ 'MAIN': getenv('DB_MAIN_URL'),
\ 'ALT': getenv('DB_ALT_URL'),
\ }
let g:db = g:dbs['MAIN']
else
echohl WarningMsg
echom "dadbod: DB_MAIN_URL or DB_ALT_URL is empty. Check ~/vimfiles/private/env"
echohl None
endif
function! DadbodPickDB(...) abort
if empty(get(g:, 'dbs', {}))
echoerr "No databases configured in g:dbs"
return
endif
let l:names = sort(keys(g:dbs))
let l:menu = ['Select database:'] + map(copy(l:names), {i,v -> printf('%d. %s', i+1, v)})
let l:default = index(l:names, get(a:, 1, 'MAIN')) + 1
if l:default <= 0 | let l:default = 1 | endif
let l:choice = inputlist(l:menu)
if l:choice <= 0 || l:choice > len(l:names)
echo "DB selection cancelled"
return
endif
let l:selected = l:names[l:choice - 1]
let g:db = g:dbs[l:selected]
execute 'DB' g:db
echo 'Connected to ' . l:selected
endfunction
command! -nargs=? DBPick call DadbodPickDB(<f-args>)
" /dadbod