-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc.vim
1433 lines (1228 loc) · 43.2 KB
/
vimrc.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
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"VIMRC FILE "Sarat Maharjan "[email protected] "2015.07.03
"For Ultisnips: Python 2.7.9
"{{{ Initial Setting - need to be at start
let mapleader="," "leader is comma
let g:mapleader = ","
if has('mouse') "Enable Mouse
set mouse=a
endif
"}}}
"{{{ OTHER SOURCES
let hostname = substitute(system('hostname'), '\n', '', '')
let user = substitute(system('whoami'),'\n','','')
if hostname == "ansys2"
source C:/Users/maharjan/Dropbox/VIM/pathANDfontAnakon.vim
elseif hostname == "Smaharjan"
source E:/SM/VIM/pathANDfontAnakon.vim
else
source C:/Users/Sarat/Dropbox/VIM/pathANDfontHome.vim
endif
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
source $VIMRUNTIME/macros/matchit.vim
behave mswin
"exe 'source ' .expand(pathColor)
exe 'set rtp+=' .expand(pathRTP)
"Zoom Functions
exe 'so ' .expand(pathRTP)."/zoom.vim"
exe 'so ' .expand(pathRTP)."/highlights.vim"
exe 'set undodir=' .expand(pathWork)
"}}} Sources
"{{{ Language and Encoding
"set langmenu=en_US
set langmenu=de_DE
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set encoding=utf-8
set fileencoding=utf-8
:scriptencoding utf-8
"set encoding=latin1
"set keymap=german
"}}} Language and Encoding
"{{{ VUNDLE
"{{{Installing vundle
"IN COMMAND LINE
"cd %USERPROFILE%
"cd D:/VIM
"git clone https://github.com/gmarik/Vundle.vim.git vimfiles/bundle/Vundle.vim
"gvim _vimrc
"}}}Installing vundle
"Use Vim settings, rather than Vi settings (much better!). This must be first, because it changes other options as a side effect.
set nocompatible "be iMproved, required
filetype off "required
"set the runtime path to include Vundle and initialize
exe 'set rtp+=' .expand(pathRTP) . '/bundle/Vundle.vim'
"pass a path where Vundle should install plugins
call vundle#begin(expand(pathRTP) . '/bundle')
"let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
"The following are examples of different formats supported. Keep Plugin commands between vundle#begin/end.
"plugin on GitHub repo
"Plugin 'tpope/vim-fugitive'
"Plugin 'mileszs/ack.vim'
"plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
"Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
Plugin 'https://github.com/scrooloose/nerdtree.git'
"Plugin 'https://github.com/amix/vimrc.git'
"Plugin 'https://github.com/tpope/vim-pathogen.git'
Plugin 'https://github.com/vim-scripts/peaksea.git'
Plugin 'https://github.com/sjl/badwolf.git'
"Plugin 'https://github.com/sjl/gundo.vim.git'
"Plugin 'https://github.com/ggreer/the_silver_searcher.git'
Plugin 'https://github.com/rking/ag.vim.git'
Plugin 'https://github.com/kien/ctrlp.vim.git'
"Plugin 'https://github.com/kchmck/vim-coffee-script.git'
"Plugin 'https://github.com/tpope/vim-commentary.git'
Plugin 'https://github.com/scrooloose/nerdcommenter.git'
Plugin 'https://github.com/jlanzarotta/bufexplorer.git'
Plugin 'https://github.com/jeffkreeftmeijer/vim-numbertoggle.git'
Plugin 'https://github.com/nathanaelkane/vim-indent-guides.git'
Plugin 'https://github.com/tpope/vim-abolish.git'
"Plugin 'https://github.com/mkitt/tabline.vim.git'
"Plugin 'https://github.com/msanders/snipmate.vim.git'
Plugin 'https://github.com/MattesGroeger/vim-bookmarks.git'
Plugin 'https://github.com/vim-syntastic/syntastic.git'
"if hostname != "ansys2"
"Plugin 'https://github.com/SirVer/ultisnips.git'
"endif
Plugin 'https://github.com/bling/vim-airline.git'
"Plugin 'https://github.com/Valloric/YouCompleteMe.git'
Plugin 'https://github.com/yegappan/grep.git'
"Plugin 'https://github.com/vim-scripts/TabLineSet.vim.git'
Plugin 'https://github.com/tpope/vim-fugitive.git'
Plugin 'https://github.com/rosenfeld/rgrep.vim.git'
"Plugin 'https://github.com/chrisbra/BackgroundColor.vim.git'
Plugin 'https://github.com/elzr/vim-json.git'
"git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
"The sparkup vim script is in a subdirectory of this repo called vim.
"Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim'}
Plugin 'https://github.com/godlygeek/tabular.git'
"Avoid a name conflict with L9
"Plugin 'saratmaharjan/L9', {'name': 'saratmaharjan'}
"All of your Plugins must be added before the following line
call vundle#end() "required
"To ignore plugin indent changes, instead use:
"filetype plugin on
"
"Brief help
":PluginList - lists configured plugins
":PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
":PluginSearch foo - searches for foo; append `!` to refresh local cache
":PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
"see :h vundle for more details or wiki for FAQ
"Put your non-Plugin stuff after this line
"}}} VUNDLE
"{{{ KEY MAPPINGS
"map or remap is recursive and expanded, noremap is not expanded:::::: vmap and vnoremap for visual mode ....... nmap,
"nnoremap for normal mode and so on........................
nnoremap <C-F1> :if &go=~#'m'<Bar>set go-=m<Bar>else<Bar>set go+=m<Bar>endif<CR>
nnoremap <C-F2> :if &go=~#'T'<Bar>set go-=T<Bar>else<Bar>set go+=T<Bar>endif<CR>
nnoremap <C-F3> :if &go=~#'r'<Bar>set go-=r<Bar>else<Bar>set go+=r<Bar>endif<CR>
nnoremap <space>nh :nohlsearch<CR> "Key. ,Space "turn off search highlight
nnoremap <leader>q :mksession<CR> "save session
"nnoremap <leader>a :Ag "open ag.vim
nnoremap le `[v`] "highlight last inserted text : last edit
"noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm "Remove the Windows ^M - when the encodings gets messed up
inoremap jk <esc> "jk is escape
"CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
nnoremap <leader>w :w!<cr> "Fast saving
"Inserting New Line
nnoremap <S-Enter> O<Esc>j
nnoremap <CR> o<Esc>k
"noremap <leader>q :e ~/buffer<cr> "Quickly open a buffer for scribble
"noremap <leader>x :e ~/buffer.md<cr> "Quickly open a markdown buffer for scribble
"noremap <leader>pp :setlocal paste!<cr> "Toggle paste mode on and off
"noremap <silent> <leader><cr> :noh<cr> "Disable highlight when <leader><cr> is pressed
"noremap <leader>bd :Bclose<cr> "Close the current buffer
"noremap <leader>ba :1,1000 bd!<cr> "Close all the buffers
"noremap <leader>cd :cd %:p:h<cr>:pwd<cr> "Switch CWD to the directory of the open buffer
"Opens a new tab with the current buffer's path : Super useful when editing files in the same directory
"noremap <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
noremap 0 ^ "Remap VIM 0 to first non-blank character
noremap Q gq "Don't use Ex mode, use Q for formatting
"Useful mappings for managing tabs
"noremap <leader>tn :tabnew<cr>
"noremap <leader>to :tabonly<cr>
"noremap <leader>tc :tabclose<cr>
"noremap <leader>tm :tabmove
"noremap <leader>t<leader> :tabnext
"F7 to check if file is changed outside VIM
noremap <F7> :checktime<CR>
noremap! <F7> <C-O>:checktime<CR>
"Visual mode pressing * or # searches for the current selection, Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f', '')<CR>
vnoremap <silent> # :call VisualSelection('b', '')<CR>
"move vertically by visual line i.e. Dont skip wrapped lines
nnoremap j gj
nnoremap k gk
"move to beginning/end of line
nnoremap B ^
nnoremap E $
"$/^ doesn't do anything
nnoremap $ <nop>
nnoremap ^ <nop>
"edit vimrc/zshrc and load vimrc bindings - These are shortcuts to edit and source vimrc and zshrc.
" nnoremap <leader>ev :vsp $MYVIMRC<CR>
" nnoremap <leader>ez :vsp ~/.zshrc<CR>
" nnoremap <leader>sv :source $MYVIMRC<CR>
"Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
noremap <space>s /
noremap <s-space> ?
"}}} KEY MAPPINGS
"{{{ GUI OPTIONS
:set guioptions-=m "remove menu bar
:set guioptions-=T "remove toolbar
":set guioptions-=r "remove right-hand scroll bar
":set guioptions-=L "remove left-hand scroll bar
"TO START MAXIMIZED
"Use ~x on an English Windows version or ~n for French.
au GUIEnter * simalt ~x
"{{{Setting Color Scheme and Appearance
set background=dark
"colorscheme peaksea
"colorscheme desert
colorscheme deserts
"colorscheme badwolf "awesome colorscheme
"colorscheme apprentice
"Enable syntax highlighting
syntax enable
"Set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T
set guioptions-=e
set t_Co=256
"set guitablabel=%M\ %t
endif
"}}}
"{{{ Status Bar
"Always show the status line
set laststatus=2
"Format the status line
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ WD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
"}}}
"{{{Tabs Setting
set tabstop=2 "number of visual spaces per TAB
"set softtabstop=4 "number of spaces in tab when editing
"set smarttab "Be smart when using tabs ;)
set shiftwidth=2 "1 tab == 4 spaces
"}}}
"{{{Line Numbers
set number "show line numbers
set relativenumber
"}}}
"}}} GUI OPTIONS
"{{{ Working Directory Setting
exe 'cd ' . expand(pathWork)
set autochdir "Set file directory as Working Directory
"}}} Working Directory Setting
"{{{ file TABS and or Buffer setting
":tab all "open all files as tab
":bufdo tab split "Change all files to TABS
"map ,bt :bufdo tab split<CR>
set tabpagemax=50
"{{{if TABS used
"CTRL-Tab is next tab
noremap <C-Tab> :<C-U>tabnext<CR>
inoremap <C-Tab> <C-\><C-N>:tabnext<CR>
cnoremap <C-Tab> <C-C>:tabnext<CR>
"CTRL-SHIFT-Tab is previous tab
noremap <C-S-Tab> :<C-U>tabprevious<CR>
inoremap <C-S-Tab> <C-\><C-N>:tabprevious<CR>
cnoremap <C-S-Tab> <C-C>:tabprevious<CR>
"Let 'tl' toggle between this and the last accessed tab
let g:lasttab = 1
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
"}}}
"{{{ option 1 - not working
"set showtabline=2 "always show tabs in gvim, but not vim
""set up tab labels with tab number, buffer name, number of windows
"function! GuiTabLabel()
"let label = ''
"let bufnrlist = tabpagebuflist(v:lnum)
""Add '+' if one of the buffers in the tab page is modified
"for bufnr in bufnrlist
"if getbufvar(bufnr, "&modified")
"let label = '+'
"break
"endif
"endfor
""Append the tab number
"let label .= v:lnum.': '
""Append the buffer name
"let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
"if name == ''
""give a name to no-name documents
"if &buftype=='quickfix'
"let name = '[Quickfix List]'
"else
"let name = '[No Name]'
"endif
"else
""get only the file name
"let name = fnamemodify(name,":t")
"endif
"let label .= name
""Append the number of windows in the tab page
"let wincount = tabpagewinnr(v:lnum, '$')
"return label . ' [' . wincount . ']'
"endfunction
"set guitablabel=%{GuiTabLabel()}
"}}}
"{{{ tool tip Not Working
"set up tab tooltips with every buffer name
"function! GuiTabToolTip()
"let tip = ''
"let bufnrlist = tabpagebuflist(v:lnum)
"for bufnr in bufnrlist
""separate buffer entries
"if tip!=''
"let tip .= "\n "
"endif
""Add name of buffer
"let name=bufname(bufnr)
"if name == ''
""give a name to no name documents
"if getbufvar(bufnr,'&buftype')=='quickfix'
"let name = '[Quickfix List]'
"else
"let name = '[No Name]'
"endif
"endif
"let tip.=name
""add modified/modifiable flags
"if getbufvar(bufnr, "&modified")
"let tip .= ' [+]'
"endif
"if getbufvar(bufnr, "&modifiable")==0
"let tip .= ' [-]'
"endif
"endfor
"return tip
"endfunction
"set guitabtooltip=%{GuiTabToolTip()}
"}}}
"{{{ Tab headings not working either
"function GuiTabLabel()
"let label = ''
"let bufnrlist = tabpagebuflist(v:lnum)
""Add '+' if one of the buffers in the tab page is modified
"for bufnr in bufnrlist
"if getbufvar(bufnr, "&modified")
"let label = '+'
"break
"endif
"endfor
""Append the number of windows in the tab page if more than one
"let wincount = tabpagewinnr(v:lnum, '$')
"if wincount > 1
"let label .= wincount
"endif
"if label != ''
"let label .= ' '
"endif
""Append the buffer name (not full path)
"return label . "%t"
"endfunction
"set guitablabel=%!GuiTabLabel()
"}}}
"{{{ New one
"set tabline=%!MyTabLine() "custom tab pages line
"function MyTabLine()
"let s = '' "complete tabline goes here
""loop through each tab page
"for t in range(tabpagenr('$'))
""set highlight
"if t + 1 == tabpagenr()
"let s .= '%#TabLineSel#'
"else
"let s .= '%#TabLine#'
"endif
""set the tab page number (for mouse clicks)
"let s .= '%' . (t + 1) . 'T'
"let s .= ' '
""set page number string
"let s .= t + 1 . ' '
""get buffer names and statuses
"let n = '' "temp string for buffer names while we loop and check buftype
"let m = 0 "&modified counter
"let bc = len(tabpagebuflist(t + 1)) "counter to avoid last ' '
""loop through each buffer in a tab
"for b in tabpagebuflist(t + 1)
""buffer types: quickfix gets a [Q], help gets [H]{base fname}
""others get 1dir/2dir/3dir/fname shortened to 1/2/3/fname
"if getbufvar( b, "&buftype") == 'help'
"let n .= '[H]' . fnamemodify( bufname(b), ':t:s/.txt$//' )
"elseif getbufvar( b, "&buftype") == 'quickfix'
"let n .= '[Q]'
"else
"let n .= pathshorten(bufname(b))
"endif
""check and ++ tab's &modified count
"if getbufvar( b, "&modified")
"let m += 1
"endif
""no final ' ' added...formatting looks better done later
"if bc > 1
"let n .= ' '
"endif
"let bc -= 1
"endfor
""add modified label [n+] where n pages in tab are modified
"if m > 0
"let s .= '[' . m . '+]'
"endif
""select the highlighting for the buffer names
""my default highlighting only underlines the active tab
""buffer names.
"if t + 1 == tabpagenr()
"let s .= '%#TabLineSel#'
"else
"let s .= '%#TabLine#'
"endif
""add buffer names
"if n == ''
"let s.= '[New]'
"else
"let s .= n
"endif
""switch to no underlining and add final space to buffer list
"let s .= ' '
"endfor
""after the last tab fill with TabLineFill and reset tab page nr
"let s .= '%#TabLineFill#%T'
""right-align the label to close the current tab page
"if tabpagenr('$') > 1
"let s .= '%=%#TabLineFill#%999Xclose'
"endif
"return s
"endfunction
"}}}
""{{{if BUFFER used NEED WORKING
""CTRL-Tab is next buffer
"noremap <C-Tab> :bn<CR>
""CTRL-SHIFT-Tab is previous tab
"noremap <C-S-Tab> :bp<CR>
""Let 'tl' toggle between this and the last accessed tab
"let g:lasttab = 1
"nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
"au TabLeave * let g:lasttab = tabpagenr()
""}}}
"}}} file TABS setting
"{{{ Backup Settings
"set backup
"set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
"set backupskip=/tmp/*,/private/tmp/*
"set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
"set directory=.,$TEMP
"set writebackup
:set nobackup
""To make Backups with Date
"":au! BufWrite * execute "w"expand("%") . strftime(".%y%m%d.%H%M%S")
":au! BufWrite * execute "w!"expand("%") . strftime(".%y%m%d.")
"noremap <leader>ba :au! BufWrite * execute "w!"expand("%") . strftime(".%y%m%d.")<CR>
"}}} Backup Settings
"{{{ FOLD settings
set foldcolumn=3 "Add a bit extra margin to the left
set foldenable "enable folding
set foldlevelstart=0 "open most folds by default
set foldnestmax=10 "10 nested fold max
"set foldmethod=indent "fold based on indent level
set foldmethod=marker
"set foldmethod=syntax
"set foldmethod=expr
"foldlevel=0
set foldlevel=0
set modelines=1
autocmd FileType vim setlocal foldmethod=marker
"autocmd FileType vim setlocal foldmethod=indent
"autocmd FileType apdl setlocal foldmethod=syntax
autocmd FileType apdl setlocal foldmethod=marker
autocmd FileType apdl setlocal foldmarker=anfang,ende
autocmd FileType dosbatch setlocal foldmethod=marker
autocmd FileType dosbatch setlocal foldmarker=anfang,ende
autocmd FileType asm setlocal foldmethod=marker
autocmd FileType asm setlocal foldmarker=anfang,ende
autocmd FileType c setlocal foldmarker=anfang,ende
autocmd FileType html setlocal foldmarker=anfang,ende
autocmd FileType autohotkey setlocal foldmarker=anfang,ende
autocmd FileType javascript setlocal foldmarker=anfang,ende
autocmd FileType html setlocal foldmarker=anfang,ende
autocmd FileType css setlocal foldmarker=anfang,ende
autocmd FileType scss setlocal foldmarker=anfang,ende
"let g:FoldMethod = 0 "Defining Global Variable
let g:doFoldLevel=5
"let g:vimsyn_folding='af'
"Section Name {{{ ---3 brackets are markers
"set number "This will be folded
"}}}
"}}} FOLD Settings
"{{{ FUNCTIONS
"noremap <leader>m :call ToggleNumber()<cr>
"{{{ toggle between number and relativenumber
"fun! ToggleNumber()
"if(&relativenumber == 1)
"set norelativenumber
"set number
"else
"set relativenumber
"endif
"endfunc
"}}} toggle between number and relativenumber
"{{{ strips trailing whitespace at the end of files. this is called on buffer write in the autogroup above.
function! <SID>StripTrailingWhitespaces()
"save last search & cursor position
let _s=@/
let l = line(".")
let c = col(".")
%s/\s\+$//e
let @/=_s
call cursor(l, c)
endfunction
"Delete trailing white space on save, useful for Python and CoffeeScript ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
"autocmd BufWritePre *.php,*.py,*.js,*.txt,*.hs,*.java,*.md
"\:call <SID>StripTrailingWhitespaces()
"autocmd BufWrite *.py :call DeleteTrailingWS()
"autocmd BufWrite *.coffee :call DeleteTrailingWS()
"}}} strips trailing whitespace at the end of files. this is called on buffer write in the autogroup above.
"{{{ Function1 Adding Menu Item for Commands!!!
function! CmdLine(str)
exe "menu Foo.Bar :". a:str
emenu Foo.Bar "add menu
unmenu Foo "remove menu
endfunction
"}}} Function 1
"{{{ selection
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?". l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("Ack \"". l:pattern . "\"")
elseif a:direction == 'replace'
call CmdLine("%s". '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /". l:pattern . "^M"
endif
let @/ = l:pattern
let @"= l:saved_reg
endfunction
"}}} Selection
"{{{ Function1
"Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
en
return ''
endfunction
"}}} Function1
"{{{ Function1
"Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
"}}} Function1
"set diffexpr=MyDiff() "ONLY required if VIM doesnot have DIFF component
"{{{ Function1 ONLY REQUIRED IF VIM does not have DIFF Component
"function MyDiff()
"let opt = '-a --binary '
"if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
"if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
"let arg1 = v:fname_in
"if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
"let arg2 = v:fname_new
"if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
"let arg3 = v:fname_out
"if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
"let eq = ''
"if $VIMRUNTIME =~ ' '
"if &sh =~ '\<cmd'
"let cmd = '""' . $VIMRUNTIME . '\diff"'
"let eq = '"'
"else
"let cmd = substitute($VIMRUNTIME, ' ', '"', '') . '\diff"'
"endif
"else
"let cmd = $VIMRUNTIME . '\diff'
"endif
"silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
"endfunction
"}}} Function1
"{{{ Toggle Fold Function
noremap <leader>ff :call ToggleFold()<cr>
fun! ToggleFold()
if &foldmethod == 'marker'
exe 'set foldmethod=syntax'
else
exe 'set foldmethod=marker'
endif
endfun
"}}}
"}}} FUNCTIONS
"{{{ Other Settings
"Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\""|
\ endif
set viminfo^=% "Remember info about open buffers on close
"Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
set autoread "Auto reload files if changed outside
set so=7 "Set 7 lines to the cursor - when moving vertically using j/k
"Linebreak on 500 characters
"set lbr
"set tw=500
set ai "Auto indent
set si "Smart indent
"set wrap "Wrap lines
set mousehide "Hide the mouse when typing text
set timeout timeoutlen=3000
set history=700 "Sets how many lines of history VIM has to remember
set autoread "Set to auto read when a file is changed from the outside
set showcmd "show command in bottom bar, display incomplete commands
set cursorline "highlight current line
set wildmenu "visual autocomplete for command menu
set showmatch "highlight matching [{()}] Show matching brackets when text indicator is over them
set incsearch "search as characters are entered, do incremental searching
set hlsearch "highlight matches
set lazyredraw "redraw only when we need to.
set wildmenu "Turn on the WiLd menu
set ruler "Always show current position
set cmdheight=2 "Height of the command bar
set ch=2 "Make command line two lines high
set hid "A buffer becomes hidden when it is abandoned
set backspace=eol,start,indent "Configure backspace so it acts as it should act allow backspacing over everything in insert mode
set whichwrap+=<,>,h,l "Configure backspace so it acts as it should act
set ignorecase "Ignore case when searching
set smartcase "When searching try to be smart about cases
set magic "For regular expressions turn magic on
set mat=2 "How many tenths of a second to blink when matching brackets
"No annoying sound on errors
set noerrorbells visualbell t_vb=
if has('autocmd')
autocmd GUIEnter * set visualbell t_vb=
endif
set noeb vb t_vb=
set vb t_vb=
syntax on
filetype plugin on
filetype plugin indent on "required
filetype indent on "load filetype-specific indent files
filetype plugin on
filetype indent on
autocmd InsertEnter * :set number
autocmd InsertLeave * :set relativenumber
"Cursor is green, Cyan when ":lmap"mappings are active, Constants are not underlined but have a slightly lighter background
highlight Cursor guibg=Green guifg=NONE
highlight lCursor guibg=Cyan guifg=NONE
"CtrlP settings
let g:ctrlp_match_window = 'bottom,order:ttb'
let g:ctrlp_switch_buffer = 0
let g:ctrlp_working_path_mode = 0
"let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
"create language-specific settings for certain filetypes/file extensions
augroup configgroup
autocmd!
autocmd VimEnter * highlight clear SignColumn
autocmd FileType java setlocal noexpandtab
autocmd FileType java setlocal list
autocmd FileType java setlocal listchars=tab:+\ ,eol:-
autocmd FileType java setlocal formatprg=par\ -w80\ -T4
autocmd FileType php setlocal expandtab
autocmd FileType php setlocal list
autocmd FileType php setlocal listchars=tab:+\ ,eol:-
autocmd FileType php setlocal formatprg=par\ -w80\ -T4
autocmd FileType ruby setlocal tabstop=2
autocmd FileType ruby setlocal shiftwidth=2
autocmd FileType ruby setlocal softtabstop=2
autocmd FileType ruby setlocal commentstring=#\ %s
autocmd FileType python setlocal commentstring=#\ %s
autocmd BufEnter *.cls setlocal filetype=java
autocmd BufEnter *.zsh-theme setlocal filetype=zsh
autocmd BufEnter Makefile setlocal noexpandtab
autocmd BufEnter *.sh setlocal tabstop=2
autocmd BufEnter *.sh setlocal shiftwidth=2
autocmd BufEnter *.sh setlocal softtabstop=2
augroup END
"Convenient command to see the difference between the current buffer and the file it was loaded from, thus the changes you made.
"Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
"Running current file in BATCH or CMD
"noremap <C-y> :!%:p<CR>
"noremap <leader>run :!%:p<CR>
nnoremap <leader>run :!start %:p<CR>
"noremap <leader>brun :exe '!start cmd /k' . expand(pathbat) . '/SM.bat & pause'<CR>
"noremap <leader>brun :exe '!start cmd /k' . expand(pathbat) . '/SM.bat'<CR>
noremap <leader>bun :exe '!start cmd /c' . expand(pathbat) . '/SM.bat'<CR>
"}}} Other Settings
"{{{ Intent-Guide Plugin Settings
let g:indent_guides_start_level=1
let g:indent_guides_guide_size=1
let g:indent_guides_auto_colors=1
let g:indent_guides_space_guides=0
let g:indent_guides_enable_on_vim_startup=1
let g:indent_guides_color_change_percent=3
"}}}
"{{{ Use CTRL-S for saving, also in Insert mode
noremap <C-S> :update!<CR>
vnoremap <C-S> <C-C>:update!<CR>
inoremap <C-S> <C-O>:update!<CR>
"}}}
"{{{ Commenting blocks of code. Alternative to Nerd Commentator
"autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
"autocmd FileType sh,ruby,python let b:comment_leader = '# '
"autocmd FileType conf,fstab let b:comment_leader = '# '
"autocmd FileType tex let b:comment_leader = '% '
"autocmd FileType mail let b:comment_leader = '> '
"autocmd FileType vim let b:comment_leader = '"'
"autocmd FileType apdl let b:comment_leader = '! '
"noremap <silent> ,cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
"noremap <silent> ,cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
"}}}
"{{{TABLINE SETTINGS
"set showtabline=2 "always show tabs in gvim, but not vim
""set up tab labels with tab number, buffer name, number of windows
"function! GuiTabLabel()
"let label = ''
"let bufnrlist = tabpagebuflist(v:lnum)
""Add '+' if one of the buffers in the tab page is modified
"for bufnr in bufnrlist
"if getbufvar(bufnr, "&modified")
"let label = '+'
"break
"endif
"endfor
""Append the tab number
"let label .= v:lnum.': '
""Append the buffer name
"let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
"if name == ''
""give a name to no-name documents
"if &buftype=='quickfix'
"let name = '[Quickfix List]'
"else
"let name = '[No Name]'
"endif
"else
""get only the file name
"let name = fnamemodify(name,":t")
"endif
"let label .= name
""Append the number of windows in the tab page
"let wincount = tabpagewinnr(v:lnum, '$')
"return label . ' [' . wincount . ']'
"endfunction
"set guitablabel=%{GuiTabLabel()}
"}}}
"{{{ File Type Association
"APDL filetye association
au BufNewFile,BufRead *.in setf apdl
au BufNewFile,BufRead *.mac setf apdl
au BufNewFile,BufRead *.out setf apdl
au BufNewFile,BufRead *.inp setf apdl
au BufNewFile,BufRead *.solc setf apdl
au BufNewFile,BufRead *.csv setf apdl
au BufNewFile,BufRead *.s01 setf apdl
au BufNewFile,BufRead *.s02 setf apdl
au BufNewFile,BufRead *.s03 setf apdl
au BufNewFile,BufRead *.s04 setf apdl
au BufReadPost *.mac set syntax=apdl
au BufReadPost *.mac setf apdl
au BufReadPost *.in setf apdl
au BufReadPost *.out setf apdl
au BufReadPost *.inp setf apdl
au BufReadPost *.solc setf apdl
au BufReadPost *.csv setf apdl
au BufReadPost *.s01 setf apdl
au BufReadPost *.s02 setf apdl
au BufReadPost *.s03 setf apdl
au BufReadPost *.s04 setf apdl
au BufReadPost *.ans setf apdl
au WinEnter *.mac setf apdl
"}}}
"{{{ Nerd Commentator Settings
let g:NERDCustomDelimiters = {
\ 'ruby': { 'left': '#', 'leftAlt': 'FOO', 'rightAlt': 'BAR' },
\ 'grondle': { 'left': '{{', 'right': '}}' },
\ 'apdl': { 'left': '! ', 'leftAlt': '!', 'right': '' },
\ 'mac': { 'left': '! ', 'leftAlt': '!', 'right': '' },
\ 'macro': { 'left': '! ', 'leftAlt': '!', 'right': '' },
\ 'asm': { 'left': '! ', 'leftAlt': '!', 'right': '' },
\ }
let NERD_apdl_alt_style=1
let NERD_mac_alt_style=1
let NERD_macro_alt_style=1
"}}}
"{{{ Open Important Files
noremap <leader>vrc :exe 'tabedit ' . expand(pathRTP) . '/vimrc.vim'<CR>
noremap <leader>apd :exe 'tabedit ' . expand(pathRTP) . '/syntax/apdl.vim'<CR>
noremap <leader>bat :exe 'tabedit ' . expand(pathbat) . '/SM.bat'<CR>
noremap <leader>baat :exe 'tabedit ' . expand(pathbat) . '/SM2.bat'<CR>
noremap <leader>cp :exe 'tabedit ' . expand(pathsm) . '/macros/cp7.mac'<CR>
noremap <leader>sm :exe 'tabedit ' . expand(pathsm) . '/sm.mac'<CR>
noremap <leader>app :exe 'tabedit ' . expand(pathRTP) . '/colors/deserts.vim'<CR>
noremap <leader>ab :exe 'tabedit ' . expand(pathsm). '/absm.mac'<CR>
noremap <leader>snip :exe 'tabedit ' . expand(pathRTP) . '/snips/apdl.snippets'<CR>
"}}}
"{{{ UltiSnips Settings
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsSnippetDirectories=["UltiSnips","snips"]
let g:UltiSnipsSnippetsDir=expand(pathRTP) . '/snips'
"}}}
"{{{ BOOKMARKS Settings
let g:bookmark_save_per_working_dir = 1
let g:bookmark_auto_save = 1
let g:bookmark_manage_per_buffer = 1
"let g:bookmark_auto_save_file = pathWork
"mm :BookmarkToggle
"mi :BookmarkAnnotate <TEXT>
"mn :BookmarkNext
"mp :BookmarkPrev
"ma :BookmarkShowAll
"mc :BookmarkClear
"mx :BookmarkClearAll
":BookmarkSave <FILE_PATH>
":BookmarkLoad <FILE_PATH>
let g:bookmark_no_default_key_mappings = 1
function! BookmarkMapKeys()
nmap mm :BookmarkToggle<CR>
nmap mi :BookmarkAnnotate<CR>
nmap mn :BookmarkNext<CR>
nmap mp :BookmarkPrev<CR>
nmap ma :BookmarkShowAll<CR>
nmap mc :BookmarkClear<CR>
nmap mx :BookmarkClearAll<CR>
endfunction
function! BookmarkUnmapKeys()
unmap mm
unmap mi
unmap mn
unmap mp
unmap ma
unmap mc
unmap mx
endfunction
autocmd BufEnter * :call BookmarkMapKeys()
autocmd BufEnter NERD_tree_* :call BookmarkUnmapKeys()
"}}}
"{{{"The Silver Searcher
"if executable('ag')
""Use ag over grep
"set grepprg=ag\ --nogroup\ --nocolor
""Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
"let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
""ag is fast enough that CtrlP doesn't need to cache
"let g:ctrlp_use_caching = 0
"endif
"}}}
"{{{ SEARCH OPTIONS
"bind K to vimgrep word under cursor
nnoremap <leader>gw :vimgrep! /<C-R><C-W>/gj *.in<CR>:cw<CR>
"Search in Dir and sub directories for word under Cursor in ALL FILES
"map <F4> :execute "vimgrep /". expand("<cword>") . "/gj **"<Bar> cw<CR>
"same as above but for some extension Only...
map <F4> :execute "vimgrep /". expand("<cword>") . "/gj *.in"<Bar> cw<CR>
"Search for word under cursor in same file.... Same as / searching....(* or #) is preferred
command! GREP :execute 'vimgrep /'.expand('<cword>').'/gj '.expand('%') | copen
"{{{GREP settings
let Grep_Path=expand(pathRTP).'\GREP\bin\grep.exe'
let Fgrep_Path=expand(pathRTP).'\GREP\bin\fgrep.exe'
let Egrep_Path=expand(pathRTP).'\GREP\bin\egrep.exe'
let Agrep_Path=expand(pathRTP).'\GREP\bin\agrep.exe'
let Grep_Xargs_Path=expand(pathRTP).'\GREP\bin\xargs.exe'
let Grep_Find_Path=expand(pathRTP).'\GREP\bin\find.exe'
let Grep_Default_Filelist='*.in *.mac *.out'
let Grep_Default_Options = '-ri'
let Grep_Find_Use_Xargs = 0
"let Grep_Xargs_Options = '--null'
nnoremap <leader>spc :Grep sp.*case *.in *.mac *.out <CR>
"}}}
"}}}
"{{{ Session Settings
let SessionLoad=1