-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.vimrc
More file actions
356 lines (300 loc) · 11.2 KB
/
.vimrc
File metadata and controls
356 lines (300 loc) · 11.2 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
" mloliee vimrc
set nocompatible " be iMproved, required
filetype off " required
filetype plugin indent on " required
" -----------------------------------------------------------
" Global
" -----------------------------------------------------------
set autowrite " Automatically :write before running commands
set clipboard=unnamed " For OSX clipboard
set encoding=utf-8 " UTF-8 is the encoding you want for your files
set hidden " Handle multiple buffers better.
set history=1000 " Store lots of :cmdline history
set hlsearch " Highlight search results
set incsearch " Makes search act like in modern browsers
set lazyredraw " Redraw only when we need to.
set laststatus=2 " Always display the status line
set novisualbell "
set noerrorbells " No error bells
set showmode " Show mode -- INSERT --
set showcmd " Show commands
set showmatch " Highlight matching [{()}]
set ttimeout " Fast VIM
set ttimeoutlen=100
set ttyfast
set undofile " Persistent undo
set undolevels=1000 " Increase undo levels
set undoreload=1000 " Maximum number of lines to save for undo on buffer reload
set undodir=~/.vim/undofiles " Do not add ~un files everywhere I go
set wildmode=list:longest " Complete files like a shell.
set wildmenu " Enhanced command line completion.
set spelllang=en " Check all regions of English.
syntax enable
" Disable modelines for security reasons
set modelines=0
set nomodeline
" Store swap files in fixed location, not current directory.
"
" The '//' at the end ensure the swap file name will be built from the complete
" path to the file with all path separators substituted to percent '%' signs.
"
" This will ensure file name uniqueness in the preserve directory.
set dir=~/.vimswap//,/var/tmp//,/tmp//,.
" -----------------------------------------------------------
" Style
" -----------------------------------------------------------
set termguicolors " True color support
set background=dark " Dark bg
set cursorline " Highlight current line
set ruler " Display ruler
set relativenumber " Set relative number for fast dd/yy
set number " Display line number for current line
" Set default colorscheme
colorscheme slate
" Patatetoy colors
let s:comment = "#6c6d6c"
let s:bg = "#292b2d"
let s:fg = "#c9cac0"
let s:bg_visual = "#525151"
let s:bg_cursor_line = "#3a3939"
let s:blue = "#5eb1dd"
let s:blue_bright = "#73b8dc"
let s:black = "#3a3939"
let s:purple = "#a3adfc"
let s:orange = "#fac159"
let s:cyan = "#7ec6eb"
let s:green = "#82c476"
let s:magenta = "#ff875f"
let s:red = "#f0522a"
let s:white = "#c9cac0"
let s:yellow = "#fbce4d"
" Global
execute 'highlight Normal guibg=' . s:bg . ' guifg=' . s:fg
execute 'highlight Comment guifg=' . s:comment
execute 'highlight Visual guibg=' . s:bg_visual . ' guifg=' . s:yellow . ' gui=bold'
execute 'highlight CursorLineNr guifg=' . s:yellow . ' gui=bold'
execute 'highlight Added guifg=' . s:green
execute 'highlight Error guifg=' . s:red
execute 'highlight Removed guifg=' . s:red
execute 'highlight ExtraWhitespace guibg=' . s:red
execute 'highlight ErrorMsg guifg=' . s:red
execute 'highlight Debug guifg=' . s:yellow
execute 'highlight WarningMsg guifg=' . s:yellow
execute 'highlight Title guifg=' . s:blue
execute 'highlight Search guibg=' . s:yellow . ' guifg=' . s:bg
execute 'highlight IncSearch guibg=' . s:yellow . ' guifg=' . s:bg
" Status
execute 'highlight StatusLine guifg=' . s:fg . ' guibg=' . s:bg
execute 'highlight StatusLineNC guifg=' . s:fg . ' guibg=' . s:bg
" Code
execute 'highlight Constant guifg=' . s:magenta
execute 'highlight String guifg=' . s:green
execute 'highlight Character guifg=' . s:green
execute 'highlight Number guifg=' . s:magenta
execute 'highlight Identifier guifg=' . s:yellow
execute 'highlight Function guifg=' . s:blue
execute 'highlight PreProc guifg=' . s:blue
execute 'highlight Statement guifg=' . s:magenta
execute 'highlight Special guifg=' . s:blue
execute 'highlight Type guifg=' . s:blue
" Set the terminal's title
if &term == 'screen'
set t_ts=k
set t_fs=\
elseif &term == 'screen' || &term == 'xterm'
set title
endif
" -----------------------------------------------------------
" Indent - Tabs/Spaces
" -----------------------------------------------------------
set nowrap " don't wrap lines
set tabstop=2 shiftwidth=2 " a tab is two spaces (or set this to 4)
set expandtab " use spaces, not tabs (optional)
set smarttab
set backspace=indent,eol,start " backspace through everything in insert mode
set autoindent " match indentation of previous line
set listchars=tab:▸\ ,eol:¬,trail:·,extends:>,precedes:<
" -----------------------------------------------------------
" Auto Commands
" -----------------------------------------------------------
augroup vimrcEx
autocmd!
autocmd BufRead *.aliases* setlocal ft=sh
autocmd BufRead *Jenkinsfile setlocal ft=groovy
autocmd BufRead ~/.dnsmasq.d/* setlocal ft=dnsmasq
autocmd BufRead *nginx/*.conf setlocal ft=nginx
autocmd BufRead *httpd/*.conf setlocal ft=apache
" When editing a file, always jump to the last known cursor position.
" Don't do it for commit messages, when the position is invalid, or when
" inside an event handler (happens when dropping a file on gvim).
" https://github.com/thoughtbot/dotfiles/blob/master/vimrc#L34-L40
autocmd BufReadPost *
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Crontab http://calebthompson.io/crontab-and-vim-sitting-in-a-tree/
autocmd filetype crontab setlocal nobackup nowritebackup
" Let's tell Vim to automatically use absolute line numbers when we're in
" insert mode and relative numbers when we're in normal mode
autocmd InsertEnter * :set number
autocmd InsertLeave * :set relativenumber
" https://vim.fandom.com/wiki/Highlight_unwanted_spaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
augroup END
" -----------------------------------------------------------
" Configure Explorer
" -----------------------------------------------------------
let g:netrw_banner = 0
let g:netrw_winsize = 15
let g:netrw_preview = 1
let g:netrw_altv = 1
let g:netrw_fastbrowse = 2
let g:netrw_keepdir = 0
let g:netrw_retmap = 1
let g:netrw_silent = 1
let g:netrw_special_syntax = 1
" -----------------------------------------------------------
" Bindings, command key send <Char-0x0254> value
" -----------------------------------------------------------
" Define , as leader key
let mapleader = ","
" Save with Cmd-s
nnoremap <Char-0x0254>s :w<CR>
inoremap <Char-0x0254>s <ESC>:w<CR>l
cnoremap <Char-0x0254>s <C-c>:w<CR>l
vnoremap <Char-0x0254>s <ESC>:w<CR>l
" Undo
nnoremap <Char-0x0254>u u
inoremap <Char-0x0254>u <ESC>u
vnoremap <Char-0x0254>u <ESC>u
" Do things right, use hjkl instead of arrows
nnoremap j gj
nnoremap k gk
" Command mode nav
cnoremap <C-e> <End>
cnoremap <C-k> <Up>
cnoremap <C-j> <Down>
cnoremap <C-h> <Left>
cnoremap <C-l> <Right>
" Fast visual 2 search
vnoremap // y/\V<C-R>"<CR>
" like nvim buffer lines search
noremap <leader>i /
" delete without yanking
nnoremap <leader>d "_d
vnoremap <leader>d "_d
" replace currently selected text with default register without yanking it
vnoremap <leader>p "_dP
" Remove help
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" Open on new window
nnoremap <Char-0x0254>& <C-w>v<C-w>l
inoremap <Char-0x0254>& <Esc><C-w>v<C-w>l
cnoremap <Char-0x0254>& <Esc><C-w>v<C-w>l
vnoremap <Char-0x0254>& <Esc><C-w>v<C-w>l
" Tab management
nnoremap <Char-0x0254>@ :tabnew<CR>
inoremap <Char-0x0254>@ <Esc>:tabnew<CR>
vnoremap <Char-0x0254>@ <Esc>:tabnew<CR>
cnoremap <Char-0x0254>@ <Esc>:tabnew<CR>
nnoremap <Char-0x0254>n :tabnext<CR>
inoremap <Char-0x0254>n <Esc>:tabnext<CR>
vnoremap <Char-0x0254>n <Esc>:tabnext<CR>
cnoremap <Char-0x0254>n <Esc>:tabnext<CR>
nnoremap <Char-0x0254>p :tabprevious<CR>
inoremap <Char-0x0254>p <Esc>:tabprevious<CR>
vnoremap <Char-0x0254>p <Esc>:tabprevious<CR>
nnoremap <Char-0x0254>p <Esc>:tabprevious<CR>
" Close vim
nnoremap <leader>q :wq!<CR>
" Exit with ! and close tab and buffer
nnoremap <Char-0x0254>q :bd!<CR>
inoremap <Char-0x0254>q <Esc>:bd!<CR>
" Remap window moves
nnoremap <left> <C-w>h
nnoremap <down> <C-w>j
nnoremap <up> <C-w>k
nnoremap <right> <C-w>l
" Indent line
nmap <S-Tab> <<
nmap <Tab> >>
vmap <S-Tab> <gv
vmap <Tab> >gv
" Move visual selection with Alt-j / Alt-k
vnoremap Ï :m '>+1<CR>gv=gv
vnoremap È :m '<-2<CR>gv=gv
" Insert new empty lines with Alt-o / Alt-O
nmap œ o<Esc>k
nmap Œ O<Esc>j
" Force sudo write
cmap w!! w !sudo tee > /dev/null %
" Yank all lines
nmap <leader>ya :%y+<CR>
" Paste toggle
set pastetoggle=<leader>°
" Display invisible chars
nmap <leader>l :set list!<CR>
" Turn off search highlight and previous matches
nnoremap <leader><space> :nohlsearch<CR>:call clearmatches()<CR>
" Enable/Disable spell checking
nnoremap <silent> <leader>gs :set spell!<CR>
" Center window vertically on next/previous search match
noremap n nzz
noremap N Nzz
" -----------------------------------------------------------
" Ensure directories exists
" -----------------------------------------------------------
if !isdirectory(&undodir)
call mkdir(expand(&undodir), 'p', '0700')
endif
" -----------------------------------------------------------
" Functions
" -----------------------------------------------------------
" Command alias, redraw window
command! -nargs=1 Silent
\ execute ':silent !clear'
\ | execute ':silent '.<q-args>
\ | execute ':redraw!'
" Return current filename or current directory
function! GetSmartWd()
let dir = expand('%:p')
if dir != ""
return dir
else
return expand('%:p:h')
endif
endfunction
" Highlight when yanking (copying) text
augroup highlight-yank
autocmd!
autocmd TextYankPost * call s:HighlightYank()
augroup END
function! s:HighlightYank()
let l:match_id = matchadd('IncSearch', '\%'.line("'[").'l\%'.col("'[").'c\_.*\%'.line("']").'l\%'.col("']").'c')
call timer_start(150, {-> matchdelete(l:match_id)})
endfunction
" OSC52 Yank
function! s:osc52_send(text) abort
" Base64-encode without newlines
if exists('*base64encode')
let l:b64 = substitute(base64encode(a:text), '\n', '', 'g')
else
let l:b64 = system('base64 | tr -d "\r\n"', a:text)
endif
let l:seq = printf("\x1b]52;c;%s\x07", l:b64)
" Write directly to the terminal for this pane
call system('cat >/dev/tty', l:seq)
endfunction
if has('unix') && !has('mac') && !has('macunix')
augroup Osc52Yank
autocmd!
autocmd TextYankPost * call s:osc52_send(join(v:event.regcontents, "\n"))
augroup END
endif