-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.vimrc
243 lines (198 loc) · 6.46 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
" Vanilla (neo)vim configurations are here.
" Plugin configurations are in .vim/plugins.vim
set nocompatible
set runtimepath+=$DOTFILES_PATH/.vim
set background=dark
colorscheme mylokai
scriptencoding utf-8
" Enable some nvim features.
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set termguicolors
" Figure out the system Python for Neovim.
if exists("$VIRTUAL_ENV")
let g:python3_host_prog=$VIRTUAL_ENV . "/bin/python3"
if substitute(system("which python | xargs readlink"), "\n", '', 'g') == "python2"
let g:python2_host_prog=substitute(system("which -a python | head -n2 | tail -n1"), "\n", '', 'g')
endif
endif
" Enable plugins
source $DOTFILES_PATH/.vim/plugins.vim
" Keep all temporary and backup files in ~/.vim
set viminfo='10,\"100,:20,%,n~/.vim/viminfo
set backup
set backupdir=~/.vim/backup " Backup
set directory=~/.vim/tmp " Swap
if has('persistent_undo')
set undofile
set undodir=~/.vim/undo " Undo
set undolevels=100 " Maximum number of changes that can be undone
set undoreload=1000 " Maximum number lines to save for undo on a buffer reload
endif
" General settings
"set t_Co=256 " Enable 256 colors for terminals
set mouse=nicr " Enable mouse in terminals
set encoding=utf-8
set termencoding=utf-8
set tabstop=4 " Tab
set shiftwidth=4 " Indent
set softtabstop=4 " Tab/Backspace
set expandtab " Convert tabs to spaces
set autoindent
set ruler " Position at the bottom of the screen
set shortmess=atI " Avoid 'press a key' prompt
set history=1000
set hidden " Allow buffer switching without saving
set number
set nowrap
set nostartofline " Maintain cursor column position across rows
" Search
set hlsearch
set incsearch
set ignorecase
" Tags
set tags=./tags,tags;$HOME
" Autocomplete
set wildmode=list:longest
set wildignore+=.*,*.o,*.obj,*.pyc
" Highlight content beyond col79
if exists('+colorcolumn')
set colorcolumn=80
endif
" Split, place cursor in newly-split pane
set splitbelow
set splitright
" General mappings
nnoremap <leader>\ :noh<return> " Turn off highlighting
nnoremap <silent><leader>w :call search('\u', 'W')<CR> " Jump TitleCase words
nnoremap <leader>so :so $MYVIMRC<return> " Reload source
vmap > >gv " Retain visual select when indenting
vmap < <gv " Retain visual select when indenting
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]' " Reselect paste.
command! W write " Write on :W, too.
command! E edit " Edit on :E, too.
"" Navigation
""" Panes
nnoremap <M-right> <C-w>l " (alt-right)
nnoremap <M-left> <C-w>h " (alt-left)
nnoremap <M-down> <C-w>j " (alt-down)
nnoremap <M-up> <C-w>k " (alt-up)
if has("nvim")
tnoremap <M-right> <C-w>l " (alt-right)
tnoremap <M-left> <C-w>h " (alt-left)
tnoremap <M-down> <C-w>j " (alt-down)
tnoremap <M-up> <C-w>k " (alt-up)
endif
nnoremap <M-l> :topleft split<CR> " Horizontal split (alt-l)
nnoremap <M-k> :topleft vsplit<CR> " Vertical split (alt-k)
nnoremap <M-;> :close<CR> " Close split (alt-/)
nnoremap <M-h> <C-w>t<C-w>K " Convert vertical to horizontal split (alt-h)
nnoremap <M-j> <C-w>t<C-w>H " Convert horizontal to vertical split (alt-j)
nnoremap <M->> <C-w>> " Resize width
nnoremap <M-<> <C-w>< " Resize width
nnoremap <M-_> <C-w>- " Resize height
nnoremap <M-+> <C-w>+ " Resize height
""" Buffers
nnoremap <M-.> :bnext<CR>
nnoremap <M-,> :bprev<CR>
nnoremap <M-/> :bdelete<CR>
""" Tabs
nnoremap <M-]> :tabnext<CR>
nnoremap <M-[> :tabprev<CR>
nnoremap <M-}> :tabmove +1<CR>
nnoremap <M-{> :tabmove -1<CR>
nnoremap <M-w> :tabclose<CR>
nnoremap <M-t> :tabnew %<CR>
nnoremap <M-T> :call PaneToTab()<CR>
""" Quickfix
nnoremap <M-n> :cnext<CR>
nnoremap <M-p> :cprev<CR>
" Keep vim's directory context same as the current buffer
if exists('+autochdir')
set autochdir
else
autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ /
endif
" Reveal rogue spaces
set list listchars=tab:>\ ,trail:.,extends:$,nbsp:_
set fillchars=fold:-
" Evaporate rogue spaces
function! StripWhitespace()
exec ':%s/\s*$//g'
endfunction
noremap <leader><space> :call StripWhitespace()<CR>
" Find the nearest Makefile and run it
function! MakeUp()
let makefile = findfile("Makefile", ".;")
if makefile != ""
silent exe "NeomakeSh make -C " . fnamemodify(makefile, ':p:h')
endif
endfunc
autocmd BufWritePost *.scss call MakeUp()
" Open the current pane in a tab and close the pane
function! PaneToTab()
silent exe "close | tabnew +" . line(".") . " " . expand("%:p")
endfunc
" Ignore Noun-y words when spell checking
function! IgnoreNounSpell()
syn match myExCapitalWords +\<\w*[A-Z]\S*\>+ contains=@NoSpell
"syn match CamelCase /\<[A-Z][a-z]\+[A-Z].\{-}\>/ contains=@NoSpell transparent
"syn cluster Spell add=CamelCase
endfunc
" Set tab width
function! SetTab(width)
let &tabstop=a:width
let &softtabstop=a:width
let &shiftwidth=a:width
endfunc
" Save/Load macro
" Borrowed from https://github.com/junegunn/dotfiles/blob/master/vimrc
function! s:save_macro(name, file)
let content = eval('@'.a:name)
if !empty(content)
call writefile(split(content, "\n"), a:file)
echom len(content) . " bytes save to ". a:file
endif
endfunction
command! -nargs=* SaveMacro call <SID>save_macro(<f-args>)
function! s:load_macro(file, name)
let data = join(readfile(a:file), "\n")
call setreg(a:name, data, 'c')
echom "Macro loaded to @". a:name
endfunction
command! -nargs=* LoadMacro call <SID>load_macro(<f-args>)
" Open FILENAME:LINE:COL
" Borrowed from https://github.com/junegunn/dotfiles/blob/master/vimrc
function! s:goto_line()
let tokens = split(expand('%'), ':')
if len(tokens) <= 1 || !filereadable(tokens[0])
return
endif
let file = tokens[0]
let rest = map(tokens[1:], 'str2nr(v:val)')
let line = get(rest, 0, 1)
let col = get(rest, 1, 1)
bd!
silent execute 'e' file
execute printf('normal! %dG%d|', line, col)
endfunction
autocmd BufNewFile * nested call s:goto_line()
" Extra:
"" Detect RFC files
autocmd FileType text if expand('%:t') =~? 'rfc\d\+' | set filetype=rfc | endif
"" .ract files for ractive
autocmd BufNewFile,BufRead *.ract set filetype=mustache
"" .make files for Makefiles
autocmd BufNewFile,BufRead *.make set filetype=Makefile
"" Move the quickfix window to the very bottom.
autocmd FileType qf wincmd J
" Load gvimrc if it wasn't loaded already.
if has('gui_running') && !exists("g:gvimrc_init")
source $DOTFILES_PATH/.gvimrc
endif
"" Detect readonly buffers (neovim-only)
hi! ReadOnlyNormal ctermbg=0
if exists('+winhighlight')
autocmd BufReadPost * if &readonly
\| set winhighlight=Normal:ReadOnlyNormal
\| endif
endif