-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_vimrc
327 lines (254 loc) · 9.26 KB
/
dot_vimrc
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
" Set compatibility to Vim only.
set nocompatible
" show special characters
set list
" Set relative line numbers
set rnu
" set noesckeys disabled for nvim
" Helps force plug-ins to load correctly when it is turned back on below.
filetype off
" Turn on syntax highlighting.
syntax on
" For plug-ins to load correctly.
filetype plugin indent on
" Turn off modelines
set modelines=0
" show invisible characters
set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
" Automatically wrap text that extends beyond the screen length.
set nowrap
" When closing an unsaved file move it to a buffer
set hidden
" Draw a line at the 100th character of every line
set colorcolumn=100
" Uncomment below to set the max textwidth. Use a value corresponding to the width of your screen.
set textwidth=100
set formatoptions=tcqrn1
set tabstop=2
set shiftwidth=2
set nospell
set softtabstop=2
set expandtab
set noshiftround
set noerrorbells
set smartindent
set noswapfile
set nobackup
" set up undoing behaviour
set undodir=~/.vim/undodir
set undofile
set undolevels=10000
" copy indentation from current line to the new line. Really useful for end in ruby
set autoindent
" set indentation level based on filetype
filetype plugin indent on
" Display 5 lines above/below the cursor when scrolling with a mouse.
set scrolloff=5
" Fixes common backspace problems
set backspace=indent,eol,start
" Speed up scrolling in Vim
set ttyfast
" enable hardtime mode. Stop repeating keys
" let g:hardtime_default_on = 1
" allow jj but not jjj
" let g:hardtime_maxcount = 2
" Status bar
set laststatus=2
" Display options
set showmode
set showcmd
" Highlight matching pairs of brackets. Use the '%' character to jump between them.
set matchpairs+=<:>
" Show line numbers
set number
" Set status line display
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ [BUFFER=%n]\ %{strftime('%c')}
" Encoding
set encoding=utf-8
" Highlight matching search patterns
set hlsearch
" Enable incremental search
set incsearch
" Include matching uppercase words with lowercase search term
set ignorecase
" Include only uppercase words with uppercase search term
set smartcase
set foldmethod=syntax
set nofoldenable
set updatetime=750
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" Store info from no more than 100 files at a time, 9999 lines of text, 100kb of data. Useful for copying large amounts of data between files.
set viminfo='100,<9999,s100
set re=2
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
"
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
let mapleader = " "
noremap <leader>w :w<cr>
noremap <leader>p :GFiles<cr>
noremap <leader>b :Buffers<cr>
noremap <leader>r :Rails<cr>
noremap <leader>v :execute 'Ag ' . expand('<cword>')<cr>
command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)
nnoremap <c-l> :let @*=expand("%")<CR>
nnoremap <c-n> :let @*=fnamemodify(expand("%"), ":~:.") . ":" . line(".")<CR>
" Fuzzy search the whole project
noremap <leader>f :Ag<cr>
map <Leader>l :BLines<CR>
" Open a split vertical split pane
noremap <silent> vv <C-w>v
" Disable the search hightlight with hotkey. Useful to stop typing :noh
nnoremap <C-h> :set hlsearch!<CR>
" Auto center the buffer when moving vertically
nnoremap <C-d> <C-d>zz
nnoremap <C-u> <C-u>zz
" Auto format with Coc projects
noremap <leader>g :Format <cr>
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
let g:fzf_layout = { 'down': '~60%' }
if empty(glob('~/.vim/autoload/plug.vim'))
silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'https://github.com/adelarsq/vim-matchit'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'leafgarland/typescript-vim' " TypeScript syntax
Plug 'maxmellon/vim-jsx-pretty'
Plug 'neoclide/coc.nvim' , { 'branch' : 'release' }
Plug 'pangloss/vim-javascript' " JavaScript support
Plug 'preservim/nerdtree'
Plug 'shime/vim-livedown'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'vim-ruby/vim-ruby'
Plug 'kana/vim-textobj-user'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'vim-airline/vim-airline'
Plug 'preservim/nerdtree'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-rails'
Plug 'joshdick/onedark.vim'
Plug 'sheerun/vim-polyglot'
Plug 'ThePrimeagen/vim-be-good'
Plug 'mrjones2014/dash.nvim', { 'do': 'make install' }
" write css selector and expand using <c-y>,
Plug 'mattn/emmet-vim'
call plug#end()
" Adds true color support in neovim
set termguicolors
colorscheme onedark
inoremap <silent><expr> <c-space> coc#refresh()
map <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" select last paste in visual mode
nnoremap <expr> gb '`[' . strpart(getregtype(), 0, 1) . '`]'
" remap the esc keybinding in terminal mode
tnoremap jk <C-\><C-n>
tnoremap kj <C-\><C-n>
"" autocmd CursorHold * silent call CocActionAsync('highlight')
" rename the symbol
nmap <leader>rn <Plug>(coc-rename)
" Applying code actions to the selected code block.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for apply code actions at the cursor position.
nmap <leader>ac <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer.
nmap <leader>as <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
let g:coc_global_extensions = [ 'coc-tsserver']
" sets the max number of autocomplete elements
:set pumheight=8
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)
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
"" fix for large files syntax hightlighting
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
"" Use CTRL-S for selections ranges.
"" " Requires 'textDocument/selectionRange' support of language server.
"nmap <silent> <C-s> <Plug>(coc-range-select)
"xmap <silent> <C-s> <Plug>(coc-range-select)
"" Mappings for CoCList
"" Show all diagnostics.
"nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
"" Manage extensions.
"nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
"" Show commands.
"nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
"" Find symbol of current document.
"nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
"" Search workspace symbols.
"nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
"" go markdown shorthand for markdown edit
"nmap gm :LivedownToggle
nnoremap <leader>h :wincmd h<CR>
nnoremap <leader>j :wincmd j<CR>
nnoremap <leader>k :wincmd k<CR>
nnoremap <leader>l :wincmd l<CR>
"" NERDTree plugin remaps
nnoremap <C-t> :NERDTreeFind<CR>
"" Exit Vim if NERDTree is the only window left.
"autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
" \ quit | endif
" Autocomplete HTML tags
autocmd FileType html,jsx,tsx,eruby set omnifunc=htmlcomplete#CompleteTags
inoremap jk <esc>
inoremap kj <esc>
packadd! matchit
silent! helptags ALL
" Enable % to be used in every ruby keyword
runtime macros/matchit.vim
"" Rename current file
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>rf :call RenameFile()<cr>
"" fix tailwind autocomplete
au FileType html let b:coc_root_patterns = ['.git', '.env', 'config/tailwind.config.js', 'tailwind.config.cjs']
"" Automatically apply the dotfiles conf when modifying a file
autocmd BufWritePost ~/.local/share/chezmoi/* ! chezmoi apply --source-path "%"