-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
274 lines (223 loc) · 8.9 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
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
" Download vim-plug if it's not installed yet
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
auto VimEnter * PlugInstall
endif
if !empty(glob("~/.fzf/bin/fzf"))
if empty(glob("~/.fzf/bin/rg"))
silent !curl -fLo /tmp/rg.tar.gz
\ https://github.com/BurntSushi/ripgrep/releases/download/0.4.0/ripgrep-0.4.0-x86_64-unknown-linux-musl.tar.gz
silent !tar xzvf /tmp/rg.tar.gz --directory /tmp
silent !cp /tmp/ripgrep-0.4.0-x86_64-unknown-linux-musl/rg ~/.fzf/bin/rg
endif
endif
set history=700 " Sets how many lines vim has to remember
set autoread " Set to auto read when a file is changed from the outside
set ignorecase
set smartcase
set hidden
let mapleader="," " Leader is comma
set backspace=indent,eol,start
set confirm
set encoding=UTF-8
map Y yy
" :W sudo saves the file
" (useful for handling the permission-denied error)
command W w !sudo tee % > /dev/null
cnoreabbrev Q! q!
cnoreabbrev Qall! qall!
cnoreabbrev Wq wq
cnoreabbrev Wa wa
cnoreabbrev wQ wq
cnoreabbrev WQ wq
cnoreabbrev Q q
cnoreabbrev Qall qall
" Opens a tab edit command with the path of the currently edited file filled
noremap <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled
imap jj <Esc>
imap kk <Esc>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spaces & Tabs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tabstop=4 " Number of visual spaces per TAB
set softtabstop=4 " Number of spaces in tab when editing
set expandtab " Tabs are spaces
autocmd FileType javascript setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType php setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType yaml setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType yml setlocal tabstop=2 softtabstop=2 shiftwidth=2
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => UI
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set number " Add line numbers
set showcmd " Show command in bottom bar
set cursorline " Highlight current line
filetype indent on " Load filetype-specific indent files
set wildmenu " Visual autocomplete for command menu
set lazyredraw " Redraw only when needed
set showmatch " Highlight matching brackets
set foldcolumn=0 " Add a margin to the left
set laststatus=2 " Size for the status bar
set noshowmode " Hides the mode below the status line
" 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
" Colour correction or something
if (empty($TMUX))
if (has("nvim"))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
if (has("termguicolors"))
set termguicolors
endif
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable " Syntax theme
colorscheme dracula " awesome colorscheme
" Enable 256 colors palette in Gnome Terminal
if $COLORTERM == 'gnome-terminal'
set t_Co=256
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Searching
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set incsearch " Search as characters are typed
set hlsearch " Hightlight matches
" Turn off search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Visual mode pressing * or # searches for the current selection
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Movement
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Move vertically by visual line
nnoremap j gj
nnoremap k gk
" Move to beginning/end of line
nnoremap B ^
nnoremap E $
" $/^ doesn't do anything
" nnoremap $ <nop>
" nnoremap ^ <nop>
" 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
" Use tab to switch tabs
" nnoremap <Tab> gt
" Vmap for maintain Visual Mode after shifting > and <
vmap < <gv
vmap > >gv
" Split
noremap <Leader>h :<C-u>split<CR>
noremap <Leader>v :<C-u>vsplit<CR>
" Return to last edit position when opening files
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pasting shortcut
set pastetoggle=<F3>
" Toggle between number and relativenumber
function! ToggleNumber()
if(&relativenumber == 1)
set norelativenumber
set number
else
set relativenumber
endif
endfunc
" Strips trailing whitespace at the end of files. This
" is called on buffer write in the autogroup above.
function! <SID>StripTrailingWhitespaces()
" save last search & cursor position
let _s=@/
let l = line(".")
let c = col(".")
%s/\s\+$//e
let @/=_s
call cursor(l, c)
endfunction
autocmd VimEnter * call ToggleNumber()
let g:rg_command = '
\ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always"
\ -g "*.{ts,js,json,php,md,styl,pug,jade,html,config,py,cpp,c,go,hs,rb,conf,fa,lst}"
\ -g "!{.config,.git,**/node_modules,**/vendor,**/build,yarn.lock,*.sty,*.bst,*.coffee,**/dist,**/cordova}/*" '
command! -bang -nargs=* F call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1, <bang>0)
function! s:repeat_block(key) abort
if a:key ==# '.'
return get(s:, 'v_repeat_count', '').get(s:, 'v_repeat_key', '')
endif
let s:v_repeat_count = v:count1
let s:v_repeat_key = a:key
return a:key
endfunction
for k in ['w', 'W', 's', 'p', '[', ']', '(', ')', 'b', '<', '>', 't', '{', '}', 'B', '"', "'", '`']
execute printf('vnoremap <expr> a%s <sid>repeat_block(''a%s'')', k, k)
execute printf('vnoremap <expr> i%s <sid>repeat_block(''i%s'')', k, k)
endfor
unlet! k
vnoremap <expr> . <sid>repeat_block('.')
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/bundle')
" Workflow
Plug 'scrooloose/nerdtree' " A tree explorer plugin for vim
Plug 'tpope/vim-commentary' " Comment stuff
Plug 'Chiel92/vim-autoformat' " Autoformat
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Fuzy file finder
Plug 'junegunn/fzf.vim' " Fuzy file finder
Plug 'w0rp/ale' " Linter/formatter
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
Plug 'terryma/vim-expand-region' " Expand selection
"" Appearance
Plug 'itchyny/lightline.vim' " A light and configurable statusline/tabline plugin for Vim
Plug 'jistr/vim-nerdtree-tabs' " Nerdtree tabs
Plug 'sheerun/vim-polyglot' " Syntax pack
"" Snippets
Plug 'SirVer/ultisnips' " Snippet engine
Plug 'honza/vim-snippets' " General snippets
Plug 'isRuslan/vim-es6' " Snippets for ES6
"" Colorschemes
Plug 'dracula/vim', {'as': 'dracula'} " Dracula theme
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => Plugin Settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin on " Enable plugin
" nerdtree
map <C-n> :NERDTreeTabsToggle<CR>
let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__']
let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
" Open a NERDTree automatically if no file is specified
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" ALE settings
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['prettier', 'eslint'],
\}
" Snippet trigger key
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<S-Tab>"
let g:UltiSnipsEditSplit="vertical"
" FZF settings
nnoremap <C-b> :Buffers<CR>
nnoremap <C-g> :GFiles<CR>
nnoremap <leader><leader> :Commands<CR>
nnoremap <space> :PrettierAsync<CR>