-
Notifications
You must be signed in to change notification settings - Fork 11
/
.vimrc
245 lines (203 loc) · 7.21 KB
/
.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
" Use vim-plug
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
endif
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'
Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install() }}
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround'
Plug 'easymotion/vim-easymotion'
Plug 'andymass/vim-matchup'
Plug 'tpope/vim-fugitive'
Plug 'kkoomen/vim-doge'
Plug 'mattn/emmet-vim'
Plug 'pangloss/vim-javascript'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'ap/vim-css-color'
" Themes
Plug 'patstockwell/vim-monokai-tasty'
"Plug 'joshdick/onedark.vim'
" Initialize plugin system
call plug#end()
syntax enable
set re=0 " Use new regular expression engine
set termguicolors
set background=dark
colorscheme vim-monokai-tasty
"colorscheme onedark
set encoding=utf-8
let mapleader=","
" NERDTree {
noremap <C-n> :NERDTreeToggle<CR>
let NERDTreeIgnore=['\.DS_Store', '\~$', '\.git', 'node_modules']
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
" Automatically quit vim if NERDTree and tagbar are the last and only buffers
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" }
" coc.nvim {
let g:coc_global_extensions = ['coc-tsserver', 'coc-json', 'coc-css', 'coc-prettier', 'coc-word']
" use <tab> for trigger completion and navigate to next complete item
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 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>')
else
call CocAction('doHover')
endif
endfunction
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gt <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Diagnostics navigate
nmap <silent> g] <Plug>(coc-diagnostic-next)
nmap <silent> g[ <Plug>(coc-diagnostic-prev)
nmap <silent> gj <Plug>(coc-diagnostic-next-error)
nmap <silent> gk <Plug>(coc-diagnostic-prev-error)
nmap <silent> <Leader>r <Plug>(coc-rename)
" coc-prettier
command! -nargs=0 Prettier :CocCommand prettier.formatFile
nmap <C-s> :Prettier<CR>
vmap <C-s> <Plug>(coc-format-selected)
" }
" fzf {
let $FZF_DEFAULT_COMMAND = 'ag -l --nocolor --hidden --ignore .git --ignore node_modules'
nmap <C-p> :Files<CR>
nmap <Leader>b :Buffers<CR>
nnoremap \ :Ag<CR>
command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}), <bang>0)
" }
" vim-doge {
" generate jsdoc for function under cursor
let g:doge_mapping='<Leader>d'
" }
" When editing a file, always jump to the last cursor position
function! ResCur()
if line("'\"") > 0 && line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
" END of restore cursor
" Cursor
let &t_SI="\<Esc>]50;CursorShape=1\x7"
let &t_SR="\<Esc>]50;CursorShape=2\x7"
let &t_EI="\<Esc>]50;CursorShape=0\x7"
" General settings {
set updatetime=300
set history=1000 " lines of history to remember
set clipboard+=unnamed " share with system clipboard
set viminfo+=! " make sure it can save viminfo
set report=0 " report when anything changed via :...
set noerrorbells " don't make noise
" }
" Indent Related {
set nosmartindent " smartindent (filetype indenting instead)
set softtabstop=2 " unify
set shiftwidth=2 " unify
set tabstop=2 " unify
set expandtab " use spaces instead of tab
set smarttab " be smart when using tabs
set copyindent " follow existing lines indent
" }
" Text Formatting/Layout {
set shiftround " when at 3 spaces, and hit > ... go to 4, not 5
"set nowrap " do not wrap line
set preserveindent " follow existing lines
set ignorecase " case insensitive by default
set smartcase " if there are caps, go case-sensitive
set completeopt=menu,longest,preview " improve the way autocomplete works
" }
" Folding {
set foldmethod=indent " fold on the marker
set foldlevel=1000 " don't autofold anything
" }
" UI {
set linespace=0 " space it out a little more (easier to read)
set wildmenu " turn on wild menu
set wildmode=list:longest " turn on wild menu in special format (long format)
set wildignore=*.pyc,*.pyo,*.dll,*.o,*.obj,*.exe,*.swo,*.swp,*.jpg,*.gif,*.png " ignore some formats,*.bak,
set number " turn on line numbers
set relativenumber
set numberwidth=4
set lazyredraw " do not redraw while running macros (much faster) (LazyRedraw)
set hidden " change buffer without saving
set backspace=indent,eol,start " make backspace work normal
set whichwrap+=<,>,h,l,[,] " keys wrap
set printoptions+=syntax:y " syntax when printing
"set mouse=a " use mouse everywhere
set showmatch " show matching brackets
set hlsearch
set incsearch " highlight as type
set scrolloff=5 " keep 5 lines (top/bottom) for scope
set sidescrolloff=5 " keep 5 lines at the side
set visualbell " blink instead beep
set laststatus=2 " always show the status line
"set statusline=%f%m%r%h%w\ %p%%\ %v:%l/%L%=%{&ft}\ %{coc#status()}\
set statusline=%f%m%r%h%w\ %{FugitiveStatusline()}\ %p%%\ %v:%l/%L%=%{&ft}\ %{coc#status()}\
" highlight the cursor current line in current window
autocmd WinEnter,BufEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
highlight CursorLine ctermbg=NONE cterm=NONE guibg=NONE
highlight CursorLineNr term=bold cterm=bold gui=bold
" respect the transparency settings in terminal, like iTerm2
highlight Normal guibg=NONE ctermbg=NONE
highlight NonText guibg=NONE ctermbg=NONE
set list listchars=tab:→\ ,trail:· " mark tab and trailing white space
match ErrorMsg '\s\+$' " mark trailing spaces as error
" }
" Remove trailing spaces
function! TrimTrailingSpaces()
%s/\s\+$//e
endfunction
" Mappings {
noremap <Leader>t :call TrimTrailingSpaces()<CR>
noremap <Leader>c :%s///gn<CR>
noremap <Leader>a ^
noremap <Leader>e $
noremap <Leader>s :w<CR>
noremap <Leader>z :q<CR>
noremap <Leader>g :e<CR>
noremap <Leader>f :NERDTreeFind<CR>
noremap <Leader>/ :nohlsearch<CR>
" Delete current visual selection and dump in black hole buffer before pasting
vnoremap <Leader>p "_dP
" Switch window
noremap <silent> <C-k> <C-W>k
noremap <silent> <C-j> <C-W>j
noremap <silent> <C-h> <C-W>h
noremap <silent> <C-l> <C-W>l
" Tab navigation
noremap <Leader>h :tabn<CR>
inoremap <Leader>h <esc>:tabn<CR><Insert>
noremap <Leader>l :tabprev<CR>
inoremap <Leader>l <ESC>tabprev<CR><Insert>
" Allows you to save files you opened without write permissions via sudo
cmap w!! w !sudo tee %
" }