-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc-base.vim
277 lines (221 loc) · 7.64 KB
/
vimrc-base.vim
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
set nocompatible
"-----------------------------------------------------------------------------
" General
"-----------------------------------------------------------------------------
" Necessary to show unicode glyphs
set encoding=utf-8
" Enable mouse support
set mouse=a
" Display line numbers
set number
" Enable syntax highlighting detection
syntax on
" Better command-line completion
set wildmenu
" shell style completion
" set wildmode=list:longest
" Ignore intermediates and source control in wildcard searches
set wildignore+=*.o,*.obj,*.d,.git,CVS,.svn,_darcs,*.hi,.tox
" Enable backup, persistent undo, and persistent views
set backup " Backups are nice ...
if has('persistent_undo')
set undofile " So is persistent undo ...
set undolevels=1000 " Maximum number of changes that can be undone
set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
endif
set viewoptions=folds,options,cursor,unix,slash
" disable using alt modifier for accessing window menus
set winaltkeys=no
" smarter searching. ignores case if all letters same case
set ignorecase
set smartcase
set incsearch
" automatically reload file if written outside
set autoread
" remap leader
let mapleader = " "
" sets the title of the shell to the curretly opened file
set title
" most of the time wrapping is annoying
set nowrap
" if we do wrap, split on words rather than characters
set linebreak
" cursor position
set ruler
" Show partial commands in the last line of the screen
set showcmd
" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2
" Set the status line the way i like it (disabled now because of powerline)
" set stl=%f\ %m\ %r\ Line:%l/%L[%p%%]\ Col:%c\ Buf:%n\ [%b][0x%B]
" tell VIM to always put a status line in, even if there is only one window
set laststatus=2
" Toggle between 'paste' and 'nopaste' using F2
set pastetoggle=<F2>
" Highlight when searching
set hlsearch
" enable omnicompletion
set ofu=syntaxcomplete#Complete
set completeopt=longest,menuone
" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
nnoremap <leader>hc :nohl<CR><C-L>
" keep longer history
set history=1000
" enable extended % matching
runtime macros/matchit.vim
" Keep buffer open even if not visible
" prevents prompts to save file when opening new ones
set hidden
" Show matching bracket when cursor is on it
set showmatch
" Folding settings
set foldmethod=syntax
set foldnestmax=2
set foldlevelstart=99
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker
augroup END
" Handle mouse events better through ssh/tmux
if !has('nvim')
set ttymouse=xterm2
endif
set runtimepath+=/usr/share/vim/vimfiles
"-----------------------------------------------------------------------------
" Tag preferences
"-----------------------------------------------------------------------------
" Add any global tags (for libraries)
let global_tags_dir='~/dotfiles/.global-tags'
let &tags = join(split(globpath(global_tags_dir, '**/tags'), '\n'), ',')
" default tags
set tags+=./tags;/
" Show list of possible tags if more than one,
" otherwise jump directly
" nnoremap <C-]> g<C-]>
"-----------------------------------------------------------------------------
" Movement preferences
"-----------------------------------------------------------------------------
" Window movement command mapping
"nnoremap <C-k> <C-w>k
"nnoremap <C-j> <C-w>j
"nnoremap <C-h> <C-w>h
"nnoremap <C-l> <C-w>l
"
"" Ctrl-{hjkl} for navigating out of terminal panes
"if has('nvim')
" tnoremap <C-h> <C-\><C-n><C-w>h
" tnoremap <C-j> <C-\><C-n><C-w>j
" tnoremap <C-k> <C-\><C-n><C-w>k
" tnoremap <C-l> <C-\><C-n><C-w>l
"endif
" Keep selection after indenting
vnoremap > >gv
vnoremap < <gv
" Movement default gj and gk
nnoremap j gj
nnoremap k gk
" slightly faster scrolling
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" scroll with the cursor if its within 3 lines of the edge
set scrolloff=3
" swap tilde and apostrophe, for better mark navigation
nnoremap ' `
nnoremap ` '
" Virtual Editing mode
set virtualedit=block
"-----------------------------------------------------------------------------
" Indentation
"-----------------------------------------------------------------------------
set autoindent
set smartindent
set expandtab
set tabstop=2
set softtabstop=2
set shiftwidth=2
set cino=N-s
set cino=i0
filetype indent plugin on
" Shortcut to rapidly Toggle Whitespace - `set list` for looking at indentation
nmap <leader>tw :set list!<CR>
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start
"-----------------------------------------------------------------------------
" Line Endings
"-----------------------------------------------------------------------------
" Prefer dos line endings on cygwin in windows
if has('win32unix')
set fileformats=dos,unix
endif
"-----------------------------------------------------------------------------
" Custom command mappings
"-----------------------------------------------------------------------------
" Find Uses
nmap <leader>fu yiw:vimgrep /"/ ./**/*.c
vmap <leader>fu y:vimgrep /"/ ./**/*.c
" Quick replace
nmap <leader>r yiw:%s/"//g<Left><Left>
vmap <leader>r y:%s/"//g<Left><Left>
" Visually selected text also yanked into clipboard
if has("clipboard")
vnoremap y ygv"+y
vnoremap Y Ygv"+Y
endif
" Search for selected text, forwards or backwards.
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
"-----------------------------------------------------------------------------
" Set up autocommands
"-----------------------------------------------------------------------------
if has("autocmd")
" Source the vimrc file after saving it
autocmd! bufwritepost .vimrc source $MYVIMRC
" OpenCL filetype detection
autocmd! BufRead,BufNewFile *.cl set filetype=opencl
" SConstruct filetype detection
autocmd! BufRead,BufNewFile SConstruct set filetype=python
endif
"-----------------------------------------------------------------------------
" Functions
"-----------------------------------------------------------------------------
" Store swap/backup files in fixed location, not current directory.
" Adapted from https://github.com/spf13/spf13-vim/blob/3.0/.vimrc
function! InitializeDirectories()
let dir_list = {
\ 'backup': 'backupdir',
\ 'views': 'viewdir',
\ 'swap': 'directory' }
if has('persistent_undo')
let dir_list['undo'] = 'undodir'
endif
let parent = $HOME
let common_dir = parent . '/.vim'
for [dirname, settingname] in items(dir_list)
let directory = common_dir . dirname . '/'
if exists("*mkdir")
if !isdirectory(directory)
call mkdir(directory)
endif
endif
if !isdirectory(directory)
echo "Warning: Unable to create backup directory: " . directory
echo "Try: mkdir -p " . directory
else
let directory = substitute(directory, " ", "\\\\ ", "g")
exec "set " . settingname . "=" . directory
endif
endfor
endfunction
call InitializeDirectories()