-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvimrc
executable file
·279 lines (259 loc) · 11.6 KB
/
nvimrc
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
call plug#begin()
source $HOME/.nvim.plugins
call plug#end()
map <F4> :NERDTreeToggle<CR>
nnoremap <F5> :GundoToggle<CR>
let &colorcolumn=join(range(81,999),",")
highlight ColorColumn ctermbg=235 guibg=#2c2d27
"let &colorcolumn="80,".join(range(120,999),",")
syntax enable
set background=dark
colorscheme gruvbox
autocmd! BufWritePost * Neomake
let g:deoplete#enable_at_startup = 1
filetype plugin indent on " detect file plugin+indent
syntax on " syntax highlighting
augroup FileTypeRules
autocmd!
autocmd BufNewFile,BufRead *.md set ft=markdown tw=79
autocmd BufNewFile,BufRead *.tex set ft=tex tw=79
autocmd BufNewFile,BufRead *.txt set ft=sh tw=79
augroup END
set cursorline " hilight cursor line
set more " ---more--- like less
set number " line numbers
set scrolloff=3 " lines above/below cursor
set showcmd " show cmds being typed
set title " window title
set vb t_vb= " disable beep and flashing
set wildignore=*.a,*.o,*.so,*.pyc,*.jpg,
\*.jpeg,*.png,*.gif,*.pdf,*.git,
\*.swp,*.swo " tab completion ignores
set wildmenu " better auto complete
set wildmode=longest,list " bash-like auto complete
set hidden " buffer change, more undo
set history=1000 " default 20
set iskeyword+=_,$,@,%,# " not word dividers
set laststatus=2 " always show statusline
set linebreak " don't cut words on wrap
set listchars=tab:>\ " > to highlight <tab>
set list " displaying listchars
set mouse= " disable mouse
set noshowmode " hide mode cmd line
set noexrc " don't use other .*rc(s)
set nostartofline " keep cursor column pos
set nowrap " don't wrap lines
set numberwidth=5 " 99999 lines
set shortmess+=I " disable startup message
set splitbelow " splits go below w/focus
set splitright " vsplits go right w/focus
set foldcolumn=0 " hide folding column
set foldmethod=indent " folds using indent
set foldnestmax=10 " max 10 nested folds
set foldlevelstart=99 " folds open by default
set gdefault " default s//g (global)
set incsearch " "live"-search
set matchtime=2 " time to blink match {}
set matchpairs+=<:> " for ci< or ci>
set showmatch " tmpjump to match-bracket
augroup LastPosition
autocmd! BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
set autochdir " always use curr. dir.
set autoread " refresh if changed
set confirm " confirm changed files
set noautowrite " never autowrite
set nobackup " disable backups
""" Persistent undo. Requires Vim 7.3 {{{
if has('persistent_undo') && exists("&undodir")
set undodir=$HOME/.config/nvim/undo " where to store undofiles
set undofile " enable undofile
set undolevels=500 " max undos stored
set undoreload=10000 " buffer stored undos
endif
""" }}}
""" Swap files, unless vim is invoked using sudo. Inspired by tejr's vimrc
""" https://github.com/tejr/dotfiles/blob/master/vim/vimrc {{{
if !strlen($SUDO_USER)
set directory^=$HOME/.config/nvim/swap// " default cwd, // full path
set swapfile " enable swap files
set updatecount=50 " update swp after 50chars
""" Don't swap tmp, mount or network dirs {{{
augroup SwapIgnore
autocmd! BufNewFile,BufReadPre /tmp/*,/mnt/*,/media/*
\ setlocal noswapfile
augroup END
""" }}}
else
set noswapfile " dont swap sudo'ed files
endif
""" }}}
""" }}}
""" Text formatting {{{
set autoindent " preserve indentation
set backspace=indent,eol,start " smart backspace
set cinkeys-=0# " don't force # indentation
set expandtab " no real tabs
set ignorecase " by default ignore case
set nrformats+=alpha " incr/decr letters C-a/-x
set shiftround " be clever with tabs
set shiftwidth=4 " default 8
set smartcase " sensitive with uppercase
set smarttab " tab to 0,4,8 etc.
set softtabstop=4 " "tab" feels like <tab>
set tabstop=4 " replace <TAB> w/4 spaces
""" Only auto-comment newline for block comments {{{
augroup AutoBlockComment
autocmd! FileType c,cpp setlocal comments -=:// comments +=f://
augroup END
""" }}}
""" Take comment leaders into account when joining lines, :h fo-table
""" http://ftp.vim.org/pub/vim/patches/7.3/7.3.541 {{{
if has("patch-7.3.541")
set formatoptions+=j
endif
""" }}}
""" }}}
""" Keybindings {{{
""" General {{{
" Remap <leader>
let mapleader=","
" Quickly edit/source .vimrc
" Yank(copy) to system clipboard
noremap <leader>y "+y
" Toggle folding
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
" Bubbling (bracket matching)
nmap <C-up> [e
nmap <C-down> ]e
vmap <C-up> [egv
vmap <C-down> ]egv
" Scroll up/down lines from 'scroll' option, default half a screen
map <C-j> <C-d>
map <C-k> <C-u>
" Treat wrapped lines as normal lines
nnoremap j gj
nnoremap k gk
" We don't need any help!
inoremap <F1> <nop>
nnoremap <F1> <nop>
vnoremap <F1> <nop>
" Disable annoying ex mode (Q)
map Q <nop>
" Buffers, preferred over tabs now with bufferline.
nnoremap gn :bnext<CR>
nnoremap gN :bprevious<CR>
nnoremap gd :bdelete<CR>
nnoremap gf <C-^>
""" }}}
""" Functions and/or fancy keybinds {{{{
""" Vim motion on next found object like ci", but for ([{< etc
""" - http://stackoverflow.com/a/14651443/1076493
""" Based on gist by @AndrewRadev
""" - https://gist.github.com/AndrewRadev/1171559
""" For a crazier version with directions, more objects etc. see
""" - https://bitbucket.org/sjl/dotfiles/src/default/vim/vimrc {{{
function! s:NextTextObject(motion)
echo
let c = nr2char(getchar())
exe "normal! f".c."v".a:motion.c
endfunction
onoremap a :<C-u>call <SID>NextTextObject('a')<CR>
xnoremap a :<C-u>call <SID>NextTextObject('a')<CR>
onoremap i :<C-u>call <SID>NextTextObject('i')<CR>
xnoremap i :<C-u>call <SID>NextTextObject('i')<CR>
""" }}}
""" Toggle syntax highlighting {{{
function! ToggleSyntaxHighlighthing()
if exists("g:syntax_on")
syntax off
else
syntax on
call CustomHighlighting()
endif
endfunction
nnoremap <leader>s :call ToggleSyntaxHighlighthing()<CR>
""" }}}
""" Highlight characters past 79, toggle with <leader>h
""" You might want to override this function and its variables with
""" your own in .vimrc.last which might set for example colorcolumn or
""" even the textwidth. See https://github.com/timss/vimconf/pull/4 {{{
let g:overlength_enabled = 0
highlight OverLength ctermbg=238 guibg=#444444
function! ToggleOverLength()
if g:overlength_enabled == 0
match OverLength /\%79v.*/
let g:overlength_enabled = 1
echo 'OverLength highlighting turned on'
else
match
let g:overlength_enabled = 0
echo 'OverLength highlighting turned off'
endif
endfunction
nnoremap <leader>h :call ToggleOverLength()<CR>
""" }}}
""" Toggle relativenumber using <leader>r {{{
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunction
nnoremap <leader>r :call NumberToggle()<CR>
""" }}}
""" Toggle text wrapping, wrap on whole words
""" For more info see: http://stackoverflow.com/a/2470885/1076493 {{{
function! WrapToggle()
if &wrap
set list
set nowrap
else
set nolist
set wrap
endif
endfunction
nnoremap <leader>w :call WrapToggle()<CR>
""" }}}
""" Remove multiple empty lines {{{
function! DeleteMultipleEmptyLines()
g/^\_$\n\_^$/d
endfunction
nnoremap <leader>ld :call DeleteMultipleEmptyLines()<CR>
""" }}}
""" Split to relative header/source {{{
function! SplitRelSrc()
let s:fname = expand("%:t:r")
if expand("%:e") == "h"
set nosplitright
exe "vsplit" fnameescape(s:fname . ".cpp")
set splitright
elseif expand("%:e") == "cpp"
exe "vsplit" fnameescape(s:fname . ".h")
endif
endfunction
nnoremap <leader>le :call SplitRelSrc()<CR>
""" }}}
""" Strip trailing whitespace, return to cursor at save {{{
function! <SID>StripTrailingWhitespace()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfunction
augroup StripTrailingWhitespace
autocmd!
autocmd FileType c,cpp,cfg,conf,css,html,perl,python,sh,tex
\ autocmd BufWritePre <buffer> :call
\ <SID>StripTrailingWhitespace()
augroup END
set pastetoggle=<F3>
""" }}}
""" Plugin settings {{{
" Startify, the fancy start page
let g:ctrlp_reuse_window = 'startify' " don't split in startify