-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
297 lines (238 loc) · 9.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
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
" Overview of which map command works in which mode. More details below.
" --------------------------------------------------------------------------
" COMMANDS MODES ~
" :map :noremap :unmap Normal, Visual, Select, Operator-pending
" :nmap :nnoremap :nunmap Normal
" :vmap :vnoremap :vunmap Visual and Select
" :smap :snoremap :sunmap Select
" :xmap :xnoremap :xunmap Visual
" :omap :onoremap :ounmap Operator-pending
" :map! :noremap! :unmap! Insert and Command-line
" :imap :inoremap :iunmap Insert
" :lmap :lnoremap :lunmap Insert, Command-line, Lang-Arg
" :cmap :cnoremap :cunmap Command-line
" --------------------------------------------------------------------------
" :map j gg
" :map Q j
" :noremap W j
" j will be mapped to gg.
" Q will also be mapped to gg, because j will be expanded for the recursive mapping.
" W will be mapped to j (and not to gg) because j will not be expanded for the non-recursive mapping.
"
" *****************************************************************************
" These options are being used in Vim 7.4. If using an earlier version of VIM
" please note that some of them (such as colorcolumn and undofile) won't work
" *****************************************************************************
" MUST BE AT TOP FOR VUNDLE
set nocompatible " be iMproved, required
filetype off " required
" auto install vim-plug
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" vim-plug plugins https://github.com/junegunn/vim-plug
" Install with PlugInstall
" Update with PlugUpdate
" https://github.com/junegunn/vim-plug#commands
call plug#begin()
Plug 'https://github.com/tpope/vim-commentary'
Plug 'https://github.com/ctrlpvim/ctrlp.vim'
Plug 'https://github.com/tpope/vim-fugitive'
Plug 'leafgarland/typescript-vim'
Plug 'https://tpope.io/vim/commentary.git'
call plug#end()
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
"https://stackoverflow.com/questions/18321538/vim-error-e474-invalid-argument-listchars-tab-trail
set encoding=utf8
"Turns on highlighting of syntax
syntax on
"Set custom leader from \ to "
let mapleader='"'
"Sets shift ('<' and '>') column width
set shiftwidth=2
"Allows switching to buffer without saving changes in current buffer
set hidden
"Converts tabs to spaces
set expandtab
"Sets number of columns a tab equals (hitting tab in insert mode)
set softtabstop=2
"Keep same spacing on newline
set autoindent
" set cindent pretty sure this is what is adding tabs after pressing 'o' in commit messages
"How many columns the \t stands for when reading files
set tabstop=4
"Open files default without folding
" zM (fold-all) zR (unfold-all) zo (unfold current) zc (close) za (toggle)
set foldlevel=99
"Color that is easier to see with dark background
"https://raw.githubusercontent.com/changyuheng/color-scheme-holokai-for-vim/master/colors/holokai.vim
"colorscheme holokai
colorscheme molokai
"Adds a column marker at 80 characters wide
set colorcolumn=140
"Set default textwidth to unlimited, change default for file types elsewhere
set textwidth=140
"Set colorcolumn color
highlight colorcolumn ctermbg=red
"Highlight search
set hlsearch
"Adds line number marker
set number
"Sets 'gutter' column indent to 3 spaces
set numberwidth=3
"Allow backspace in insert mode
set backspace=indent,eol,start
"Shows incomplete cmds at bottom right while in visual mode
set showcmd
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
" Set up swap, backup, and undo folders and enable persistent undo
if has('persistent_undo')
let swapdir = expand("~/.vim/.swap")
let bakdir = expand("~/.vim/.backup")
let undodir = expand("~/.vim/.undo")
if !isdirectory($HOME."/.vim")
call mkdir($HOME."/.vim", "", 0770)
endif
if !isdirectory(swapdir)
call mkdir(swapdir)
endif
if !isdirectory(bakdir)
call mkdir(bakdir)
endif
if !isdirectory(undodir)
call mkdir(undodir)
endif
"Set directory for all swap files to specific directory
set directory=~/.vim/.swap//
"Set directory for all backup files to specific directory
set backupdir=~/.vim/.backup//
"Sets permanent undo directory
set undodir=~/.vim/.undo//
"Turns on permanent undo history
set undofile
endif
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"Enables auto completion
set wildmenu
"First <Tab> will complete longest common string and invoke wildmenu, next
"tab will complete the first alternative and then will start to cycle through
"set wildmode=longest:full,full
set wildmode=list:longest,full
"Show line and column number as status text in bottom right
set ruler
"%s/#INSERT_FILE_NAME#/\=expand('%r')/
"bottomright right aligned with %=): col: # row: # (%) [filename]
set rulerformat=%50(%=col:\ %c\ row:\ %l\ \(%p%%\)\ [%f]%)
"New keybindings for moving around with different screens
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
"Open new split panes to right and bottom, which feels more natural than Vim’s default:
set splitbelow
set splitright
" FUNCTIONS AND COMMANDS BELOW "
"Carriage return creates a newline, shift CR creates a new line after
nnoremap <CR> O<Esc>
nnoremap <S-CR> o<Esc>
"Use comma to repeat macro
nnoremap , @@
"Function to strip all trailing whitespace from files -- called automatically
"on save
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
retab
call cursor(l, c)
endfun
autocmd FileType * autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
"HERE FOR REFERENCE INSERTING TEXT FROM FILE
"This function will insert a custom header text for a cpp file
"The contents of the file in ~/class/cs161/.header will be inserted at the top of the file you're in, and will
"automatically insert the filename and the date in the format: January 01, 1900
"A list of format options are found here: http://linux.die.net/man/3/strftime
" *****NOTE variable names are hardcored in the .header file for seach and replace*****
"function! InsertCPPHeader()
" 0r~/class/cs162/.header
" %s/#INSERT_FILE_NAME#/\=expand('%r')/
" %s/#INSERT_DATE#/\=strftime('%B %d, %Y')/
" normal G
"endfunction
"Create command called Header to insert Header information at top of file
"command! Header execute InsertCPPHeader()
"Function to insert function headers for cpp files at current cursor location
"function! InsertCPPFunctionHeader()
" normal O
" r~/class/cs162/.function
"endfunction
"Command to call InsertCPPFunctionHeader()
"command! Function execute InsertCPPFunctionHeader()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Start pathogen manager on startup
" execute pathogen#infect()
"Enables filetype plugin to allow extension spedific overrides
"e.g. ~/.vim/after/ftplugin/cpp.vim
"in cpp.vim: setlocal textwidth=80
filetype plugin on
"au BufNewFile,BufRead,BufEnter *.cpp,*.hpp set omnifunc=omni#cpp#complete#Main
"set omnifunc=syntaxcomplete#Complete
autocmd BufNewFile,BufRead * setlocal formatoptions-=r
"don't wrap text
autocmd BufNewFile,BufRead * setlocal formatoptions-=t
autocmd BufNewFile,BufRead .gitignore set filetype=zsh
autocmd BufNewFile,BufRead .aliasrc set filetype=zsh
autocmd BufNewFile,BufRead .envrc set filetype=zsh
autocmd BufNewFile,BufRead .direnvrc set filetype=zsh
autocmd BufNewFile,BufRead .eslintrc set filetype=javascript
autocmd BufNewFile,BufRead *.yaml,*.yml setf yaml
autocmd BufNewFile,BufRead Dockerfile,dockerfile setf Dockerfile
autocmd BufNewFile,BufRead Gruntfile.js setf Gruntfile.js
autocmd FileType make set noexpandtab shiftwidth=4 softtabstop=8
autocmd Filetype gitcommit setlocal spell textwidth=80
autocmd FileType sql set filetype=mysql
"Remaps for working with tabs
nnoremap tt :tabnext<CR>
nnoremap th :tabfirst<CR>
nnoremap tl :tablast<CR>
nnoremap tp :tabp<CR>
nnoremap tn :tabnew<CR>
"Toggle line numbers
nnoremap <C-n> :set invnumber<CR>
"Min number of characters for completion YCM
let g:ycm_min_num_of_chars_for_completion=1
"Disable YCM by default
let g:ycm_auto_trigger=0
"turn off YCM
nnoremap <leader>y :let g:ycm_auto_trigger=0<CR>
"turn on YCM
nnoremap <leader>Y :let g:ycm_auto_trigger=1<CR>
fun! ToggleYCM()
:let g:ycm_auto_trigger=1
endfun
map <leader>q :call ToggleYCM()<CR>
"Keep at least # lines above/below
set scrolloff=10
"hi! CursorColumn ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold
hi! cursorcolumn cterm=NONE ctermbg=darkred ctermfg=white
hi! cursorline cterm=NONE ctermbg=darkred ctermfg=white
nnoremap H :set cursorline! cursorcolumn!<CR>
nnoremap C :set cursorcolumn!<CR>
runtime macros/matchit.vim
"Any of these folders will be ignored by ctrlp, notice the '\|' to escape the OR
let g:ctrlp_custom_ignore = 'node_modules\|bower_components'
"Place a .ctrlp in any folder to make that the 'root' folder for which ctrlp won't search above
let g:ctrlp_root_markers = ['.ctrlp']
" :set list
set listchars=eol:$,tab:>.,trail:~,extends:>,precedes:<,nbsp:␣
" .INIT template insertion with space+t
nnoremap <space>i :-1read $HOME/.vim/templates/script-init.sh<CR>/[<CR><o><esc>
nnoremap n nzt
nnoremap N Nzt
xnoremap n nzt
xnoremap N Nzt