forked from zyedidia/dotvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
310 lines (255 loc) · 9.59 KB
/
init.vim
File metadata and controls
310 lines (255 loc) · 9.59 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
" Welcome to my vimrc
" Load the vimrc_example
source $VIMRUNTIME/vimrc_example.vim
" Load all the plugins
source ~/.config/nvim/plugins.vim
"--------------------------
"| Settings |
"--------------------------
set showmatch " Show matching braces
set mat=1 " Set the time to show matching braces to 1 second
set ignorecase " Ignore case on searches
set smartcase " Use case sensitive search if there is a capital letter in the search
set undolevels=1000 " Set the number of undos that are remembered
set number " Show line numbers
set tabstop=4 " Use 4 space tabs
set shiftwidth=4 " Use 4 space tabs
set guifont=Monaco:h13 " Use Menlo size 13 font
set incsearch " Incremental search: jump to the first occurrence of search while the user is still searching
set mouse=a " Enable the mouse
set showcmd " Show the current command in the bottom right
set autoindent " Use autoindentation
set splitbelow " Make horizontal splits below instead of above
set splitright " Make vertical splits on the right
set scrolloff=3 " Start scrolling when the cursor is 3 lines away from the bottom of the window
set wrap " Wrap long lines
set laststatus=2 " Always display the status line
set cursorline " Highlight the current line
set autoread " Automatically reload the file when it is changed from an outside program
set nohlsearch " Don't highlight search results
set expandtab " Use spaces instead of tabs
set omnifunc=syntaxcomplete#Complete " Enable omnicompletion
set tags=tags; " Look for tags files
filetype indent on " Use filetype indentation
filetype plugin indent on " Allow plugins to use filetype indentation
syntax on " Turn on syntax highlighting
set background=dark " Use a dark background
" colorscheme solarized " Use the solarized colorscheme
" let g:molokai_original = 1
colorscheme molokai " Use the molokai colorscheme
" Make an undo directory if it does not exist
if !isdirectory($HOME . "/.config/nvim/undo")
call mkdir($HOME . "/.config/nvim/undo", "p")
endif
set undodir=~/.config/nvim/undo " Set the undo directory
set undofile " Turn on persistent undo
set undoreload=10000
set backup
if !isdirectory($HOME . "/.config/nvim/backup")
call mkdir($HOME . "/.config/nvim/backup", "p")
endif
set backupdir=~/.config/nvim/backup
"--------------------------
"| Mappings |
"--------------------------
nnoremap <up> <C-w>k
nnoremap <down> <C-w>j
nnoremap <left> <C-w>h
nnoremap <right> <C-w>l
" Open the error that the cursor is on in the location list
nnoremap <CR> :execute "ll ".line('.')<CR>
" Split a line
nnoremap K i<Enter><Esc>
" Remap ctrl-c to esc
inoremap <C-c> <Esc>
nnoremap <C-c> <Esc>
nnoremap r<C-c> r<Esc>
nnoremap <C-w><C-c> <C-w><Esc>
" Make executing macros on selected lines easy by just pressing space
vnoremap <Space> :call ExecMacro()<CR>
" Remap ctrl-k and ctrl-j to go up and down in command-line-mode
cnoremap <C-k> <up>
cnoremap <C-j> <down>
" Remap 0 to ^ and ^ to 0
nnoremap 0 ^
nnoremap ^ 0
tnoremap <C-w> <C-\><C-n><C-w>
tnoremap <Esc> <C-\><C-n>
" Remap j and k to operate on visual lines
nnoremap j gj
nnoremap k gk
" Indent the cursor correctly when going into insert mode on an empty line
nnoremap <expr> i IndentWithI()
" Correctly indent the entire file
nnoremap <Leader>= :call IndentFile()<CR>
" Open nvimrc file
nnoremap <Leader>v :vsp ~/.config/nvim/init.vim<CR>
" Source nvimrc file
nnoremap <Leader>sv :source ~/.config/nvim/init.vim<CR>
" Run the current file
nnoremap <Leader>r :Run<CR>
" Lint the current file (syntax check)
nnoremap <Leader>s :SynCheck<CR>
" Fix any syntax highlighting glitches
nnoremap <Leader>l :syntax sync fromstart<CR>
" Open the NERDTree with \n
map <Leader>n :NERDTreeToggle<CR>
" Location list pre
nnoremap <M-[> :lpr<CR>
" Location list next
nnoremap <M-]> :lne<CR>
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 " Use a bar in insert mode and a block in normal mode
"------------------------------
"| Autocommands |
"------------------------------
autocmd BufEnter,BufRead *.lang set syn=java " Highlight Lang as Java
autocmd BufEnter,BufRead *.elm set syn=haskell " Highlight Elm as Haskell
autocmd BufEnter,BufRead term://* call EnterTerminal() " Go into insert mode when the buffer switches to a terminal
autocmd BufEnter,BufRead *.v set noexpandtab
autocmd! BufWritePost * SynCheck " Check for syntax errors on file write
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
"---------------------------------------
"| Plugin Customizations |
"---------------------------------------
set backspace=2
let delimitMate_expand_cr = 1 " Expand 1 line down on enter pressed
let g:go_fmt_command = "goimports" " Automatically run goimports on save
let loaded_matchparen = 1 " Don't source the match paren plugin
" Multiple cursors mappings to use Ctrl C instead of escape
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key='<C-n>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<C-c>'
let g:move_key_modifier = 'M' " Use alt hjkl to move blocks around
let g:ctrlp_show_hidden = 1 " Show hidden files when searching with ctrlp
" Using Ag for ctrlp will speed it up (ag is much faster than grep)
if executable("ag")
let g:ctrlp_user_command = 'ag %s -i --nocolor --nogroup --hidden
\ --ignore .git
\ --ignore .svn
\ --ignore .hg
\ --ignore .DS_Store
\ --ignore "**/*.pyc"
\ -g ""'
endif
" Use the ctrlp python matcher to speed up ctrlp (python is faster than
" vimscript)
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
" Set some options for the lightline
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], ['fugitive', 'relativepath', 'modified' ] ],
\ 'right': [ [ 'lineinfo'], ['percent'], ['filetype' ] ]
\ },
\ 'inactive': {
\ 'left': [ [ 'relativepath', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ], [ 'percent' ] ]
\ },
\ 'component': {
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}'
\ },
\ 'component_visible_condition': {
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ },
\ 'component_function': {
\ 'fugitive': 'LightLineFugitive',
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' }
\ }
" Use >> for errors and warnings in Neomake (with slightly different fonts)
let g:neomake_error_sign = {
\ 'text': '>>',
\ 'texthl': 'ErrorMsg',
\ }
let g:neomake_warning_sign = {
\ 'text': '>>',
\ 'texthl': 'WarningMsg',
\ }
" Some additional options for tidy so it only shows errors
let g:neomake_html_tidy_maker = {
\ 'args': ['-e', '-q', '--gnu-emacs', 'true', '--show-warnings', 'false'],
\ 'errorformat': '%A%f:%l:%c: %trror: %m',
\ }
let g:neomake_html_enabled_makers = ['tidy']
" Set the comment type for julia
call tcomment#DefineType('julia', '# %s')
" Set the comment type for lua
call tcomment#DefineType('lua', '-- %s')
call tcomment#DefineType('d', '// %s')
"------------------------------------
"| User commands |
"------------------------------------
command! SynCheck :call SynCheck() " Check for and report syntax errors
command! Vterm :vsp term://bash " Open a terminal in a vertical split
command! Hterm :sp term://bash " Open a terminal in a horizontal split
"---------------------------------------
"| Helper functions |
"---------------------------------------
" Put the cursor in the correct position when insert mode is activated
function! IndentWithI()
if len(Trim(getline('.'))) == 0
" cc will correctly indent the cursor and switch to insert mode
return "cc"
else
return "i"
endif
endfunction
" Trim a string
function! Trim(input_string)
return substitute(a:input_string, '^\s*\(.\{-}\)\s*$', '\1', '')
endfunction
" Put the cursor in the right place when it enters a terminal buffer
function EnterTerminal()
exec "norm! gg"
exec "startinsert"
endfunction
" Autoindent the file without moving the cursor
function! IndentFile()
execute "normal! mqHmwgg=G`wzt`q"
endfunction
" Open all the files in the current file's directory
function! OpenAll(ext)
execute "lcd %:p:h"
execute "args *." . a:ext
execute "tab all"
endfunction
" Check the file for syntax errors
function! SynCheck()
execute "w"
execute "Neomake"
endfunction
" Execute the last recorded macro (useful for using visual mode to execute
" macros)
function! ExecMacro()
execute "normal @q"
endfunction
" Open the current setup in MacVim
function! OpenInMacVim()
execute "mksession! ~/.session.vim"
execute "silent !mvim -S ~/.session.vim"
execute "wqa"
endfunction
" Increment a selection of numbers
function! Incr()
let a = line('.') - line("'<")
let c = virtcol("'<")
if a > 0
execute 'normal! '.c.'|'.a."\<C-a>"
endif
normal `<
endfunction
vnoremap <C-a> :call Incr()<CR>
" Show the branch in lightline
function! LightLineFugitive()
if exists("*fugitive#head")
let _ = fugitive#head()
return strlen(_) ? ' '._ : ''
endif
return ''
endfunction