This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vimrc
456 lines (393 loc) · 10.7 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
set encoding=utf-8
function! InstallPlug()
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
silent !mkdir -p ~/vimfiles/autoload
silent !cp ~/.vim/autoload/plug.vim ~/vimfiles/autoload/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endfunction
command! InstallPlug call InstallPlug()
if filereadable(expand('~/.vim/autoload/plug.vim')) || filereadable(expand('~/vimfiles/autoload/plug.vim'))
call plug#begin('~/.vim/plugged')
Plug 'kien/ctrlp.vim'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
"Plug 'scrooloose/syntastic'
Plug 'w0rp/ale'
Plug 'othree/html5.vim'
Plug 'tpope/vim-commentary'
Plug 'elzr/vim-json'
Plug 'shime/vim-livedown'
Plug 'PProvost/vim-ps1'
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'OrangeT/vim-csharp'
Plug 'groenewege/vim-less'
Plug 'digitaltoad/vim-pug'
Plug 'mxw/vim-jsx'
"Plug 'valloric/youcompleteme'
Plug 'tomasr/molokai'
call plug#end()
let g:plug_timeout = 300
endif
filetype plugin indent on
behave xterm
set statusline=
set statusline +=%1*\ %n\%* "buffer number
set statusline +=%4*\ %<%F%* "full path
set statusline +=%2*%m%* "modified flag
set statusline +=%3*\ [%{&ff}]%* "file format
set statusline +=%5*\ [%{g:colmak?'colmak':'qwerty'}]%* "colmak/qwerty
set statusline +=%1*%=%5l%* "current line
set statusline +=%2*/%L%* "total lines
set statusline +=%1*%4v\ %* "virtual column number
set statusline +=%2*U+%04B\ %* "character under cursor
if has("gui_running")
"remove highlight on escape (doesn't work in terminal)
nmap <Esc> :noh<CR>
colorscheme desert
hi User1 guifg=#eea040 guibg=#222222
hi User2 guifg=#dd3333 guibg=#222222
hi User3 guifg=#ff66ff guibg=#222222
hi User4 guifg=#a0ee40 guibg=#222222
hi User5 guifg=#eea040 guibg=#222222
else
if (filereadable(expand('~/.vim/plugged/molokai/colors/molokai.vim')) || filereadable(expand('~/vimfiles/plugged/molokai/colors/molokai.vim'))) && &t_Co > 255
let g:molokai_original = 1
colorscheme molokai
hi User1 ctermfg=118 ctermbg=234
hi User2 ctermfg=135 ctermbg=234
hi User3 ctermfg=81 ctermbg=234
hi User4 ctermfg=161 ctermbg=234
hi User5 ctermfg=208 ctermbg=234
if has("win32") " wsl terminal on windows doesn't support bold
hi User4 ctermfg=161 ctermbg=234
else
hi User4 ctermfg=161 ctermbg=234 cterm=bold
endif
else
colorscheme desert
hi User1 ctermfg=4 ctermbg=0
hi User2 ctermfg=2 ctermbg=0
hi User3 ctermfg=3 ctermbg=0
hi User4 ctermfg=5 ctermbg=0
hi User5 ctermfg=4 ctermbg=0
endif
endif
set ttymouse=sgr
set mouse=a
if !exists("syntax_on")
syntax on
endif
"set shell=bash
"set shellxquote=\"
"set shellslash
"set shell=\"C:\Program\ Files\Git\bin\bash.exe\"
"set shellcmdflag=--login\ -c
"set comments to visible colour on linux
"hi comment ctermfg=cyan
function! SaveVariable(var, file)
call writefile([string(a:var)], a:file)
endfunction
function! ReadVariable(file)
let recover = readfile(a:file)[0]
execute "let result = " . recover
return result
endfunction
let s:colmakFile = expand("~/.vim-colmak")
if !filereadable(s:colmakFile)
call writefile([0], s:colmakFile)
endif
let g:colmak = ReadVariable(s:colmakFile)
"set cursorline
set number
set completeopt=longest,menuone
"let g:ctrlp_custom_ignore = 'v[/].(git|hg|svn)$'
"let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files --exclude-standard -co | grep -E "\.(cs|ts|less|config|cshtml)$"']
let g:ctrlp_custom_ignore = 'node_modules\|bundles\|_site'
"Had to turn off ale for typescrypt because ycm was doing it also and they conflicted.
"Will leave it on for now but might need to investigate
let g:ale_linters = {'typescript': []}
let g:vim_json_syntax_conceal = 0
let g:netrw_banner = 0
let g:netrw_browse_split = 2
let g:netrw_winsize=15
let g:netrw_liststyle=3
set nowrap
set linebreak "if we do wrap, wrap on words not characters
set display+=lastline
set diffexpr = ""
set backspace=indent,eol,start
set gdefault "global replace as default
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set incsearch
set hlsearch
set ignorecase smartcase
let mapleader = " "
set listchars=tab:>-
nnoremap <leader>es :set list!<CR>
nnoremap <leader>no :noh<CR>
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x
" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y
" CTRL-V and SHIFT-Insert are Paste
noremap <C-V> "+p
noremap <S-Insert> "+p
inoremap <C-V> <C-R>+
inoremap <S-Insert> <C-R>+
cnoremap <C-V> <C-R>+
cnoremap <S-Insert> <C-R>+
" Also CTRL-B to do what CTRL-V used to do (for visual studio)
noremap <C-B> <C-V>
" minus to work as command (for colmak)
nnoremap - :
vnoremap - :
"select all
nnoremap <C-A> ggVG
"find and replace
nnoremap <C-H> :%s/
vnoremap <C-H> :s/
"find current selection
vnoremap * y/<C-R>"<CR>
vnoremap // y/<C-R>"<CR>
"map C-Backspace to delete previous word
inoremap <C-BS> <C-W>
"run macro
nnoremap <S-Z> @z
nnoremap <S-X> @x
"switch buffer
noremap <C-Tab> :b#<CR>
"bring up most recently used file in ctrl-p
noremap <C-K> :CtrlPMRU<CR>
"open vimrc
nnoremap <silent> <leader>v :call OpenVimRc()<CR>
"open bashrc
nnoremap <silent> <leader>b :call OpenBashRc()<CR>
"do diff
nnoremap <leader>d :windo diffthis<CR>
"open split
nnoremap <leader>o :vnew<CR>
"open history of file
nnoremap <leader>hi :!start "C:\Program Files (x86)\GitExtensions\gitex.cmd" filehistory "%:p"<CR>
"paste timestamp
"nnoremap <leader>ts "=strftime("%c")<CR>p
nnoremap <leader>ts :r! date<CR>kdd
"set directory to current file
nnoremap <leader>cd :cd %:p:h<CR>
"format json/xml
nnoremap <F4> :execute "%! ".$HOME."/tools/formatter/formatter/bin/debug/formatter.exe"<CR>
"sytax xml (after pasting)
nnoremap <silent> <F5> :call RotateSyntax()<CR>
nnoremap <silent> <S-F5> :call ReverseRotateSyntax()<CR>
"enable horizontal scrollbar
nnoremap <F6> :set guioptions+=b<CR>
"turn on livedown (markdown) server
nnoremap <F7> :LivedownToggle<CR>
"home
noremap <S-H> ^
"end
noremap <S-L> $
"page up
noremap <S-K> 4k
"page down
noremap <S-J> 4j
"join line
nnoremap <Backspace> J
"join line for visual studio
nnoremap gj J
"indent/outdent
vnoremap <S-Tab> <gv
vnoremap <Tab> >gv
nnoremap <Tab> V>
nnoremap <S-Tab> V<
"ctrl click - select word
noremap <C-LeftMouse> <LeftMouse>viw
"middle mouse - repeat last action
noremap <MiddleMouse> <LeftMouse>.
"Navigate around windows
noremap <leader>h <C-w>h
noremap <leader>n <C-w>j
noremap <leader>e <C-w>k
noremap <leader>i <C-w>l
"Resize windows
noremap <C-Left> 10<C-w><
noremap <C-Down> 2<C-w>-
noremap <C-Up> 2<C-w>+
noremap <C-Right> 10<C-w>>
noremap <silent> <leader>g :call GitTag()<CR>A
set foldmethod=syntax
set foldlevel=99 "open files unfolded by default
"always show status line
set laststatus=2
let javaScript_fold=1 " JavaScript
let sh_fold_enabled=1 " sh
let vimsyn_folding='af' " Vim script
let xml_syntax_folding=1 " XML
function! GitTag()
set shell=/usr/bin/bash
let a = system('git log -n 1 --pretty=format:%s | sed "s/^\(.*: [A-Z]\{2\}-[0-9]\{4\} \).*/\1/"')
delete
put! =a
endfunction
function! RotateSyntax()
if &syntax == ""
set syntax=xml
echo "xml"
elseif &syntax == "text"
set syntax=xml
echo "xml"
elseif &syntax == "xml"
set syntax=json
echo "json"
elseif &syntax == "json"
set syntax=cs
echo "cs"
elseif &syntax == "cs"
set syntax=typescript
echo "typescript"
elseif &syntax == "typescript"
set syntax=javascript
echo "javascript"
elseif &syntax == "javascript"
set syntax=xml
echo "xml"
endif
endfunction
function! ReverseRotateSyntax()
if &syntax == ""
set syntax=xml
echo "xml"
elseif &syntax == "text"
set syntax=xml
echo "xml"
elseif &syntax == "xml"
set syntax=javascript
echo "javascript"
elseif &syntax == "json"
set syntax=xml
echo "xml"
elseif &syntax == "cs"
set syntax=json
echo "json"
elseif &syntax == "typescript"
set syntax=cs
echo "cs"
elseif &syntax == "javascript"
set syntax=typescript
echo "typescript"
endif
endfunction
function! OpenVimRc()
if filereadable(expand("~/tools/config/vimrc/_vimrc"))
edit ~/tools/config/vimrc/_vimrc
else
edit ~/tools/vimrc/_vimrc
endif
endfunction
function! OpenBashRc()
if filereadable(expand("~/tools/config/.bashrc"))
edit ~/tools/config/.bashrc
else
edit ~/.bashrc
endif
endfunction
"function! RunNode()
" let stdin = join(getline(1, '$'), "\n")
" let a = system('node', stdin)
" put =a
"endfunction
"
"autocmd FileType javascript inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
"autocmd FileType javascript nnoremap <leader><F5> :call RunNode()<CR>
if !exists("*SetupExecuteWindow")
function! SetupExecuteWindow()
execute "w"
if &filetype == 'vim'
source %:p
return
endif
if has("win32")
let filetype_to_command = {
\ 'javascript': 'node',
\ 'python': 'python',
\ 'html': 'C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe',
\ 'sh': 'bash',
\ 'bash': 'bash',
\ 'cs': '"C:\Program Files (x86)\MSBuild\14.0\Bin\csi.exe"'
\ }
else
let filetype_to_command = {
\ 'javascript': 'node',
\ 'python': 'python',
\ 'html': 'chromium-browser',
\ 'sh': 'bash',
\ 'bash': 'bash',
\ }
endif
let cmd=get(filetype_to_command, &filetype, &filetype)
execute "silent !chmod +x %:p"
execute "silent! bdelete! !" . cmd
execute "terminal " . cmd . " %:p"
"this is the old way, by running the compiler as a shell command instead of a terminal
"execute "silent !" . cmd . " %:p > " . $HOME . "/.vim/output.txt 2>&1"
"these wierd commands stop the original window from scrolling: http://stackoverflow.com/questions/3932810/vim-open-preview-window-without-moving-text-in-main-window/3933547#3933547
"normal! Hmx``
"xecute "belowright pedit ~/.vim/output.txt"
"ormal! `xzt``
endfunction
endif
nnoremap <F8> :call SetupExecuteWindow()<CR>
function! Curl()
execute "e ~/tools/vimrc/curl-template.sh"
execute "sav! ~/.vim/curl-temp.sh"
execute "normal! /insert-url-here/\<cr>vi\""
endfunction
command! Curl call Curl()
function! Html()
execute "e ~/tools/vimrc/html-template.html"
execute "sav! ~/.vim/html-temp.html"
execute "normal! /insert-content-here/\<cr>viW"
endfunction
command! Html call Html()
function! ToggleColmak()
if g:colmak
let g:colmak = 0
unmap n
unmap N
unmap e
unmap E
unmap i
unmap I
unmap l
unmap L
unmap k
unmap K
unmap j
unmap J
else
let g:colmak = 1
noremap n j
noremap N 4j
noremap e k
noremap E 4k
noremap i l
noremap I $
noremap l i
noremap L I
noremap k n
noremap K N
noremap j e
noremap J E
endif
call SaveVariable(g:colmak, s:colmakFile)
endfunction
nnoremap <leader>q :call ToggleColmak()<CR>
if g:colmak
let g:colmak = 0
call ToggleColmak()
endif