forked from mdumitru/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
240 lines (197 loc) · 7.53 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
set backupdir=~/.vim/.backup/,/tmp//
set directory=~/.vim/.swap/,/tmp//
set undodir=~/.vim/.undo/,/tmp//
" Vim wants _vim or something similar on windows.
set runtimepath^=~/.vim
set runtimepath+=~/.vim/after
"------ General ------
colorscheme vandy
set foldlevel=9999 " unfold everything when opening a file
set foldmethod=indent " define folds by indentation
set nohidden " unload buffer when closing window
set history=9999 " remember these many commands and searches
set mouse=a " enable mouse in normal, visual, insert, command-line
set noerrorbells " never trigger an error sound
set novisualbell " never trigger an error flash
set splitbelow " a new horizontal split is placed below, not above
set splitright " a new vertical split is placed to the right, not left
set timeoutlen=500 " wait these many milliseconds between a map's keys
autocmd BufEnter,FocusGained * :checktime
"
"------ Encoding settings ------
set encoding=utf-8
set fileencodings=utf-8,utf-16le
set nofixendofline
" Set the clipboard to the system clipboard.
silent! if has('clipboard')
set clipboard=unnamed,unnamedplus
endif
" Enable filetype detection, scripts and indent-scripts.
filetype plugin indent on
"------ Indents and tabs ------
set autoindent " indent a newline using the current one's level
set cindent " use c-like indenting
" Tabs are replaced with spaces, indentation is 4 characters.
set expandtab
set smarttab
set tabstop=4
set softtabstop=4
set shiftwidth=4
"------ Console UI & Text display ------
set showcmd " show partial command in the bot-right
set scrolloff=8 " start scrolling when within these many lines of edge
set report=0 " always report how many lines were changed
set shortmess=filmnrxI " make sure exactly these options are set
silent! set shortmess+=F
set list " display whitespaces
set listchars=tab:»\ ,trail:· " symbols for whitespaces
set wildmenu " enable cycling through tab completion options
set wildmode=list:longest,full
set wildignorecase " ignore case when autocompleting
set laststatus=0
set ruler
" Ignore these files when autocompleting.
set wildignore=*.obj,*.o,*~,*.pyc
set wildignore+=__pycache__
set wildignore+=*.so,*.a,*.dll
set wildignore+=*.out,*.exe,*.com
set wildignore+=*DS_Store*
set wildignore+=.git/*,.hg/*,.svn/*
" Nvim terminal settings.
if has('nvim')
let g:terminal_scrollback_buffer_size=100000
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | exe 'terminal' | endif
endif
"------ Text editing and searching behavior ------
" Turn on syntax highlighting, keeping current settings.
if !exists("g:syntax_on")
syntax enable
endif
set incsearch " search as we type
set ignorecase " make search case-insensitive
set smartcase " make search case-sensitive if it contains upper-case chars
set hlsearch " highlight search results
set showmatch " highlight matching bracket
set matchtime=2 " tenths of a second to show the matching bracket
set textwidth=80
set formatoptions=croqnj
" Allow backspace to delete indents, newlines and characters past insert-start.
set backspace=indent,eol,start
"------ Plugins config ------
" We need to set the map leader before the plugins & their settings are loaded.
" let mapleader="\<space>"
" Load all plugins.
let plugins_path=expand($HOME . "/.vim/plugins.vim")
if filereadable(plugins_path)
exe 'source' plugins_path
endif
"------ User shortcuts, commands ------
cnoremap w!! SudoWrite sudo:%
set wildcharm=<tab>
cnoremap <c-space> %:p:h/<tab>
" vup: C-a visual all, C-q increment
nnoremap <silent> <c-a> gg0VG$
nnoremap <silent> <c-q> <c-a>
" Make typing commands easier. We still keep the functionality of the semicolon.
noremap ; :
noremap \ ;
" Treat visually wrapped lines as multiple lines.
noremap j gj
noremap k gk
" Swap functionalities with above.
noremap gj j
noremap gk k
command! Ev tabedit $MYVIMRC
command! Sv source $MYVIMRC
" Pressing * or # in visual mode searches for the current selection.
vnoremap * y/<c-r>"<cr>
vnoremap # y?<c-r>"<cr>
" Sometimes the color column is annoying.
function! _ToggleColorColumn()
if &colorcolumn == ""
if exists('b:__old_colorcolumn')
let &colorcolumn=b:__old_colorcolumn
else
if &textwidth != 0
let &colorcolumn=&textwidth+1
else
let &colorcolumn=81
endif
endif
else
let b:__old_colorcolumn=&colorcolumn
let &colorcolumn=""
endif
endfunction
command! -complete=command ToggleColorColumn call _ToggleColorColumn()
nnoremap <silent> <f3> :ToggleColorColumn<cr>
"------ Global shortcuts ------
" Uniform mappings that can be used from neovim's terminal.
" Make it easy to close stuff (remember that 'hidden' is set).
noremap <silent> <a-q> :q<cr>
noremap <silent> <a-backspace> :lclose<cr>:bdelete<cr>
noremap <silent> <leader><backspace> :lclose<cr>:bdelete<cr>
" Note that :Bdelete is provided by a plugin.
noremap <silent> <a-n> :tabedit<cr>
" Both <f1> opening terminal help and highlighting are annoying.
noremap <silent> <f1> <esc>:nohlsearch<cr>
" Toggle the line numbers of all windows in the current tab.
" On first use, it will turn them on.
" This is useful when debugging from a terminal split and you want to see line
" numbers in all visible source files.
function! _ToggleTabLineNumbers()
if !exists('t:__old_linenumbers')
let t:__old_linenumbers=0
endif
" Toggle numbers in modifiable, non-terminal windows.
Windo if &modifiable && &buftype !~ "terminal" |
\ let &number=!t:__old_linenumbers |
\ endif
let t:__old_linenumbers=!t:__old_linenumbers
endfunction
command! -complete=command ToggleTabLineNumbers call _ToggleTabLineNumbers()
nnoremap <silent> <f4> :ToggleTabLineNumbers<cr><esc>
" Fold all toggle
noremap <f5> zi
if has('nvim')
" Normal escape in terminal. Ctrl+Alt+e to send an Escape through.
tnoremap <esc> <c-\><c-n>
tnoremap <c-a-e> <esc>
" Always start insert when entering a terminal buffer.
autocmd BufEnter * if &buftype == "terminal" | startinsert | endif
command! Tsplit split | terminal
command! Tvsplit vsplit | terminal
command! Ttabedit tabedit | terminal
noremap <a-t> :Ttabedit<cr>
tnoremap <a-t> <c-\><c-n>:Ttabedit<cr>
tnoremap <a-n> <c-\><c-n>:tabedit<cr>
tnoremap <a-q> <c-\><c-n>:q<cr>
tnoremap <silent> <f1> <c-\><c-n>:nohlsearch<cr>gi
" The BufEnter event is triggered, no need to return to insert explicitly.
tnoremap <silent> <f4> <c-\><c-n>:ToggleTabLineNumbers<cr>
endif
" The following mappings help with moving between splits & tabs and moving tabs
" with the same shortcuts for regular and terminal buffers (if using nvim).
noremap <a-h> <c-w>h
noremap <a-j> <c-w>j
noremap <a-k> <c-w>k
noremap <a-l> <c-w>l
noremap <a-i> gT
noremap <a-o> gt
noremap <silent> <c-a-i> :execute "tabmove" tabpagenr() - 2<cr>
noremap <silent> <c-a-o> :execute "tabmove" tabpagenr() + 1<cr>
if has('nvim')
tnoremap <a-h> <c-\><c-n><c-w>h
tnoremap <a-j> <c-\><c-n><c-w>j
tnoremap <a-k> <c-\><c-n><c-w>k
tnoremap <a-l> <c-\><c-n><c-w>l
tnoremap <a-i> <c-\><c-n>gT
tnoremap <a-o> <c-\><c-n>gt
tnoremap <silent> <c-a-i> <c-\><c-n>:execute "tabmove" tabpagenr() - 2<cr>
tnoremap <silent> <c-a-o> <c-\><c-n>:execute "tabmove" tabpagenr() + 1<cr>
endif
"------ Load .localvimrc ------
let localvimrc_path=expand($HOME . "/.lvimrc")
if filereadable(localvimrc_path)
exe 'source' localvimrc_path
endif