-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_vimrc
More file actions
736 lines (581 loc) · 20.9 KB
/
dot_vimrc
File metadata and controls
736 lines (581 loc) · 20.9 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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer:
" Nicholas Chiang — @nicholaschiang
"
" Installation:
" Get this config and all my other dotfiles!
"
" Install from:
"
" https://github.com/nicholaschiang/dotfiles
"
" Sections:
" -> Plugins via vim-plug
" -> General
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Text, tab and indent related
" -> Visual mode related
" -> Moving around, tabs and buffers
" -> Status line
" -> Editing mappings
" -> Searching (w/ FZF and NERDTree)
" -> Spell checking and code linting
" -> Misc
" -> Helper functions
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins via vim-plug
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Auto-install vim-plug
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin()
" Solarized theming for Vim
Plug 'craftzdog/solarized-osaka.nvim'
" Search for (and open) files directly from Vim
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
" Show project structure w/ NERDTree
Plug 'scrooloose/nerdtree'
" Epic status line w/ Vim Airline
Plug 'bling/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Epic status line for Tmux too
Plug 'edkolev/tmuxline.vim'
" Easy block commenting
Plug 'scrooloose/nerdcommenter'
" Syntax highlighting
Plug 'sheerun/vim-polyglot'
Plug 'alampros/vim-styled-jsx'
Plug 'pantharshit00/vim-prisma'
Plug 'leafOfTree/vim-svelte-plugin'
Plug 'terrastruct/d2-vim'
Plug 'evanleck/vim-svelte'
Plug 'NoahTheDuke/vim-just'
Plug 'wuelnerdotexe/vim-astro'
Plug 'benknoble/vim-racket'
Plug 'kaarmu/typst.vim'
" Automatic code linting w/ ALE
Plug 'dense-analysis/ale'
" Use git from w/in Vim
Plug 'tpope/vim-fugitive'
" Use Conquer of Completion for VSCode-like features
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'pappasam/coc-jedi', { 'do': 'yarn install --frozen-lockfile && yarn build', 'branch': 'main' }
" :CocInstall coc-tsserver
" :CocInstall coc-highlight
" :CocInstall coc-jedi
" :CocInstall coc-flutter
" LLMs (because 'good luck with your career if you don't use em' —CA).
"Plug 'github/copilot.vim'
"Plug 'Exafunction/codeium.vim', { 'branch': 'main' }
" Initialize plugin system
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=500
" Enable filetype plugins
filetype plugin on
filetype indent on
" Use the 'sh' filetype for all .env files
autocmd BufNewFile,BufRead .env.* set filetype=sh
" Use the `just` filetype for all Justfile files
autocmd BufNewFile,BufRead Justfile set filetype=just
" Set to auto read when a file is changed from the outside
set autoread
au FocusGained,BufEnter * checktime
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ','
" Fast saving
nmap <leader>w :w!<cr>
" Use system clipboard as default register
set clipboard+=unnamedplus
" Use ,sw to show hidden characters (line endings, tabs, etc)
nmap <leader>sw :set list!<cr>
set listchars=tab:▸\ ,eol:¬
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Vim user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Avoid garbled characters in Chinese language windows OS
let $LANG='en'
set langmenu=en
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" Turn on the Wild menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=.git\*,.hg\*,.svn\*
else
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
endif
"Always show current position
set ruler
" Always show line numbers
set nu
" Height of the command bar
set cmdheight=1
" A buffer becomes hidden when it is abandoned
set hid
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Properly disable sound on errors on MacVim
if has("gui_macvim")
autocmd GUIEnter * set vb t_vb=
endif
" Add a bit extra margin to the left
set foldcolumn=1
" Preview find and replace results during search
" set inccommand=nosplit
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
" Enable Svelte TypeScript support
let g:svelte_preprocessors = ['typescript']
" Enable Typescript syntax highlighting
" See: https://github.com/leafOfTree/vim-svelte-plugin?tab=readme-ov-file
let g:vim_svelte_plugin_use_typescript = 1
" Enable Rhombus/Shplait language highlighting
" See: https://github.com/benknoble/vim-racket/issues/13
" See: https://docs.racket-lang.org/shplait/index.html
" See: https://docs.racket-lang.org/rhombus-guide/index.html
au BufRead,BufNewFile *.rhm set filetype=shplait
" Enable Astro TypeScript highlighting
let g:astro_typescript = 'enable'
" Prevent redraw time exceptions with TypeScript
" See: https://jameschambers.co.uk/vim-typescript-slow
set re=0
" Use Solarized dark as color scheme
colorscheme solarized-osaka
set background=dark
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git etc. anyway...
set nobackup
set nowb
set noswapfile
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 2 spaces
set shiftwidth=2
set tabstop=2
" Linebreak on 500 characters
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
" Show marker line at 80 characters
set colorcolumn=80
" Wrap text at 80 characters for these filetypes
au BufRead,BufNewFile *.rs,*.txt setlocal textwidth=80
" Don't auto indent in LaTex or Markdown files
autocmd FileType tex setlocal noai nocin nosi inde=
autocmd FileType markdown setlocal noai nocin nosi inde=
""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Pressing ,+ and ,- resizes width of vsplits
nnoremap <silent> <Leader>+ :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "vertical resize " . (winwidth(0) * 2/3)<CR>
" Close the current buffer
map <leader>bd :Bclose<cr>:tabclose<cr>gT
" Close all the buffers
map <leader>ba :bufdo bd<cr>
map <leader>l :bnext<cr>
map <leader>h :bprevious<cr>
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tt :tabnext<cr>
map <leader>tm :tabmove
map <leader>t :tabnext
" Let 'o' toggle between this and the last accessed buffer
let g:lastbuf = 1
nmap <Leader>o :exe "b ".g:lastbuf<CR>
au BufLeave * let g:lastbuf = bufnr()
" Let 'tl' toggle between this and the last accessed tab
let g:lasttab = 1
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <C-r>=expand("%:p:h")<cr>/
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
""""""""""""""""""""""""""""""
" => Status line w/ Airline
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Properly install powerline fonts (see https://bit.ly/341asOl)
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.space = "\ua0"
let g:airline_powerline_fonts=1
" Use Solarized Airline theme
let g:airline_theme='solarized'
let g:airline_solarized_gb='dark'
" Enable Airline's smarter tab line
let g:airline#extensions#tabline#enabled = 1
" Enable Airline ALE error display
let g:airline#extensions#ale#enabled = 1
" Enable Airline Coc error display
let g:airline#extensions#coc#enabled = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remap VIM 0 to first non-blank character
map 0 ^
" Delete trailing white space on save, useful for some filetypes ;)
fun! CleanExtraSpaces()
let save_cursor = getpos(".")
let old_query = getreg('/')
silent! %s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfun
if has("autocmd")
autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
endif
""""""""""""""""""""""""""""""
" => Vim Fugitive
""""""""""""""""""""""""""""""
" Use ,g to use git w/in Vim
map <leader>g :Git
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Searching (w/ FZF and NERDTree)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
map <space> /
map <C-space> ?
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
""""""""""""""""""""""""""""""
" => FZF
""""""""""""""""""""""""""""""
" Pressing Ctrl-f searches for files w/ FZF (see https://bit.ly/3axGFzb)
nnoremap <C-f> :FZF<cr>
" Window using a Vim command (see https://git.io/Jim5u)
let g:fzf_layout = { 'down': '25%' }
""""""""""""""""""""""""""""""
" => NERDTree
""""""""""""""""""""""""""""""
" Useful shortcuts for NERDTree
nnoremap <leader>nn :NERDTreeToggle<cr>
nnoremap <leader>nb :NERDTreeFromBookmark<Space>
nnoremap <leader>nf :NERDTreeFind<cr>
" Configure NERDTree position
let g:NERDTreeWinPos="left"
let NERDTreeShowHidden=0
let NERDTreeIgnore = ['\.pyc$']
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking and code linting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
" Turn on spellcheck automatically for these filetypes
autocmd FileType rst,text,tex,md,markdown,gitcommit setlocal spell
" Shortcuts using <leader>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
" Fix underlining (see https://bit.ly/3bDZyRe)
set t_Cs=
""""""""""""""""""""""""""""""
" => LLMs
""""""""""""""""""""""""""""""
" Use Ctrl-J to trigger Copilot autocomplete instead of <Tab>
" For now, I find the autocomplete provided by Coc to be more useful and faster
"imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
"let g:copilot_no_tab_map = v:true
"autocmd BufNewFile,BufRead * Copilot disable
" Do not look for a package.json as monorepos will have multiple deeply nested.
"let g:codeium_workspace_root_hints = ['.bzr','.git','.hg','.svn','_FOSSIL_']
"let g:codeium_disable_bindings = v:true
"inoremap <script><silent><nowait><expr> <C-j> codeium#Accept()
" I don't want an LLM to write documentation for me.
"let g:codeium_filetypes = {
"\ "markdown": v:false,
"\ }
""""""""""""""""""""""""""""""
" => coc.nvim
""""""""""""""""""""""""""""""
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use ctrl-space to trigger Coc completion (tab is already used by Copilot).
" NOTE: Use command ':verbose imap <c-space>' to make sure <c-space> is not
"inoremap <silent><expr> <C-space> coc#pum#visible() ? coc#pum#confirm() : "\<C-space>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Store global Coc config in the ~/.vim directory
let g:coc_config_home = '~/.vim'
""""""""""""""""""""""""""""""
" => Flutter auto-reload
""""""""""""""""""""""""""""""
" Add shortcuts to hot reload
" https://github.com/iamcco/coc-flutter?tab=readme-ov-file#commands
nnoremap <leader>r :CocCommand flutter.run -d linux<cr>
nnoremap <leader>fl :edit output:///flutter-dev<cr>
nnoremap <leader>fq :CocCommand flutter.dev.quit<cr>
nnoremap <leader>fr :CocCommand flutter.dev.hotReload<cr>
nnoremap <leader>R :CocCommand flutter.dev.hotRestart<cr>
nnoremap <leader>fD :CocCommand flutter.dev.openProfiler<cr>
"""""""""""""""""""""""""""""
" => ALE code linting
""""""""""""""""""""""""""""""
" Always show error sign column
set signcolumn=yes
let g:ale_sign_column_always = 1
" Only use ESLint for Typescript files
let g:ale_linters_ignore = { 'typescriptreact': ['deno'], 'typescript': ['deno'], 'javascript': ['deno'] }
" Use Coc for autocompletion instead of ALE
let g:ale_disable_lsp = 1
" Don't show errors in virtual text (it becomes overwhelming when editing)
let g:ale_virtualtext_cursor = 0
" Disable continuous linting (CPU can't handle it)
"let g:ale_lint_on_text_changed = 'never'
"let g:ale_lint_on_insert_leave = 0
"let g:ale_lint_on_enter = 0
" Autofix and format (using ESLint and Prettier) current buffer
xmap <leader>f :ALEFix<cr>
nmap <leader>f :ALEFix<cr>
" Use locally installed Yarn PnP linters
let g:ale_completion_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {
\ 'sql': ['pgformatter', 'sqlformat'],
\ 'html': ['prettier'],
\ 'svelte': ['eslint', 'prettier'],
\ 'javascript': ['eslint', 'prettier'],
\ 'typescript': ['eslint', 'prettier'],
\ 'typescriptreact': ['eslint', 'prettier'],
\ 'python': ['black'],
\ 'json': ['prettier'],
\ 'dart': ['dart-format'],
\ 'java': ['google_java_format'],
\ 'cpp': ['astyle'],
\ 'c': ['astyle'],
\ 'css': ['prettier'],
\ }
let g:ale_linters = {
\ 'svelte': ['eslint', 'svelteserver'],
\ 'javascript': ['eslint', 'flow-language-server'],
\ 'typescript': ['eslint', 'tsserver'],
\ 'typescriptreact': ['eslint', 'tsserver'],
\ 'python': ['black', 'flake8', 'mypy'],
\ 'java': [],
\ }
let s:sdks = finddir('.yarn/sdks', ';')
if !empty(s:sdks)
let g:ale_typescript_eslint_use_global = 1
let g:ale_typescript_eslint_executable = s:sdks . '/eslint/bin/eslint.js'
let g:ale_typescript_flow_ls_use_global = 1
let g:ale_typescript_flow_ls_executable = s:sdks . '/flow-bin/cli.js'
let g:ale_typescript_prettier_use_global = 1
let g:ale_typescript_prettier_executable = s:sdks . '/prettier/index.js'
let g:ale_typescript_tsserver_use_global = 1
let g:ale_typescript_tsserver_executable = s:sdks . '/typescript/bin/tsserver'
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Quickly open a buffer for scribble
map <leader>q :e ~/buffer<cr>
" Quickly open a markdown buffer for scribble
map <leader>x :e ~/buffer.md<cr>
" Toggle paste mode on and off
map <leader>pp :setlocal paste!<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Replace all instances of utf problem characters with their ascii
" equivalents (see https://stackoverflow.com/a/17311352 for details).
function! ReplaceUTF() abort
let l:patterns = {}
let l:patterns['\%u2013'] = '-'
let l:patterns['\%u2014'] = '-'
let l:patterns['\%u2015'] = '-'
let l:patterns['\%u2017'] = '_'
let l:patterns['\%u2018'] = "'"
let l:patterns['\%u2019'] = "'"
let l:patterns['\%u201a'] = ','
let l:patterns['\%u201b'] = "'"
let l:patterns['\%u201c'] = '"'
let l:patterns['\%u201d'] = '"'
let l:patterns['\%u201e'] = '"'
let l:patterns['\%u201f'] = '"'
let l:patterns['\%u2026'] = '...'
let l:patterns['\%u2032'] = "'"
let l:patterns['\%u2033'] = '"'
" for each 'key' pattern, replace all instances with the 'value' value.
for [l:key, l:value] in items(l:patterns)
exec ':keepmarks %s/'. l:key .'/'. l:value .'/ge'
endfor
endfunction
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
endif
return ''
endfunction
" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
function! CmdLine(str)
call feedkeys(":" . a:str)
endfunction
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'gv'
call CmdLine("Ack '" . l:pattern . "' " )
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction