-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
1513 lines (1249 loc) · 45.3 KB
/
Copy path.vimrc
File metadata and controls
1513 lines (1249 loc) · 45.3 KB
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
" , .__
"._ _ _ . .._ -+- _.*._ _ _ ._.[__)._.
"[ | )(_)(_|[ ) | (_]|[ )(/,(/,[ [__)[
" =*=*=**=*=*= START DEFAULTS.VIM CHERRY PICK =*=*=**=*=*=
"source $VIMRUNTIME/defaults.vim
"arch linux: /usr/share/vim/vim82/defaults.vim
"set ttimeout " time out for key codes
"set ttimeoutlen=100 " wait up to 100ms after Esc for special key
"set default shell syntax (also good for zsh scripts)
"check ':help ft-sh-syntax'
let g:is_bash = 1
"if you notice highlighting errors while scrolling backwards which are fixed
"when one redraws with ctrl-l, try setting the "sh_minlines" internal variable
"to a larger number. The default value is 200.
let sh_minlines = 1000
":syntax sync minlines=10000
":set redrawtime=10000
"syntax sync fromstart
"https://github.com/vim/vim/issues/2790
" Allow backspacing over everything in insert mode.
"set backspace=indent,eol,start
" Configure backspace so it acts as it should act
"set backspace=eol,start,indent
"set whichwrap+=<,>,h,l
" For regular expressions turn magic on
" Magic is like egrep instead of grep RE
set magic
" Use sane regexes.
"nnoremap / /\v
"vnoremap / /\v
" Keep search matches in the middle of the window.
"nnoremap n nzzzv
"nnoremap N Nzzzv
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
nnoremap <c-o> <c-o>zz
" gi already moves to "last place you exited insert mode", so we'll map gI to
" something similar: move to last change
nnoremap gI `.
" Change the way text is displayed.
" truncate = show @@@ in the last line if it is truncated.
set display=lastline
" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it confusing.
set nrformats-=octal
"toggle paste mode for pasting text
"set pastetoggle=<f5>
" Only do this part when Vim was compiled with the +eval feature.
if 1
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" Revert with ":filetype off".
" 'indentexpr'
"filetype plugin indent on
"See: https://vim.fandom.com/wiki/Indenting_source_code
"https://www.serverwatch.com/guides/automatic-indenting-vim/
"
" Do not expand tabs to spaces
set noexpandtab
" Set tab width
set tabstop=8
"set softtabstop=8
"set shiftwidth=8
" COBOL compact format extended
" 1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67
"
" Use the indent of the previous line for a newly created line
set autoindent
"set cindent
"set smartindent
"smartindent and cindent might interfere with file type based
"indentation, and should never be used in conjunction with it.
"
" Line will continue visually indented (same amount of space as the
" beginning of that line), thus preserving horizontal blocks of text
"set breakindent
" Put these in an autocmd group, so that you can revert them with:
" ":augroup vimStartup | au! | augroup END"
augroup vimStartup
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid, when inside an event handler
" (happens when dropping a file on gvim) and for a commit message (it's
" likely a different one than last time).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup END
endif
" 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.
" Revert with: ":delcommand DiffOrig".
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
if has('langmap') && exists('+langremap')
" Prevent that the langmap option applies to characters that result from a
" mapping. If set (default), this may break plugins (but it's backward
" compatible).
set nolangremap
endif
" =*=*=**=*=*= END DEFAULTS.VIM CHERRY PICK =*=*=**=*=*=
" Set Vim colours, either for dark or light backgrounds
set background=dark
"Color Scheme -- background settings above may interfere
"colorscheme default
"colorscheme anotherdark
"colo jellybeans
"colo badwolf
"colo palenight
"colo inkpot
color astronaut "dr chimp's astronaut theme
"color landscape "https://vimawesome.com/plugin/landscape-vim
"
"Note: Color schemes are located at
" /usr/share/vim/vim81/colors/
" /home/jsn/.vim/colors/
""To check for set color scheme:
"echo g:colors_name
"Ref:https://stackoverflow.com/questions/2419624/how-to-tell-which-colorscheme-a-vim-session-currently-uses
"Ref:https://alvinalexander.com/linux/vi-vim-editor-color-scheme-colorscheme
" Screen Buffer
" Use Main Screen Buffer of XTerm to keep last Vim Buffer on screen,
" otherwise, leave buffer at Alternate Screen.
set t_ti= t_te=
"Ref:https://www.linuxquestions.org/questions/linux-general-1/disable-the-clear-after-you-close-vi-657233/
"Note: First off, it's recommended that you use screen's scrollback buffer instead.
"Since you can have multiple windows in a screen session, if you switch between
"those windows, your terminal scrollback will mix lines from all of those windows,
"but screen keeps separate scrollback buffers for each one. Just use C-a ESC
"or C-a [ to enter copy mode. One other reason for that behaviour will be the
"setting of the terminal TERM for each user.TUI applcations like vim and less
"tailor their behaviour to whatever the terminal that they find themselves
"talking to is capable of.
"Ref:https://serverfault.com/questions/270103/gnu-screen-clearing-on-vim-less-etc-exit
"
"set t_Co=0" to tell vim the terminal supports zero colors,
"or `TERM=vt220 vi' or `TERM=vt100 vi' or `TERM=dumb vi'
"
"<c-a> may be taken by `tmux' (custom config), type it twice to reach `vim'.
" LESS-like Mode Options
func LessInitFunc()
set nocursorcolumn nocursorline
set colorcolumn=0
"autocmd VimEnter * AnsiEsc
endfunc
"colorscheme?
"set t_ti= t_te=
"colorsbox-faff
" Size at start
"set columns=80
"set lines=35 columns=80
" Title of Vim Windows
set title
"Note: Vim will update the title according to the file being edited
" Fixed title
"set titlestring=VIM
" Try to use a window icon ( Works only in GUI VIM )
"set icon
"set iconstring=Vim
" Display cursor position always
set ruler
"Note: It is displayed at the lower right corner of the Vim window
" Ruler Formats
"
set rulerformat=%l,%c%V%=%P
" From: https://codeyarns.com/2010/11/28/vim-ruler-and-default-ruler-format/
" Line numbering
"set number
"
" Set how many spaces will be preallocated to show line numbers
set numberwidth=5
" Cursor Lines
" Underline
"set cursorline
" Column
"set cursorcolumn
"Note: Useful for alignment!
" Color columns
set colorcolumn=72,77
" Make it obvious where 80 characters is
" Tab and indent options
"
" set display width of tab; 1 tab = x space with
"set tabstop=8
"
" transform tab to x spaces (x is tabstop); on pressing tab, insert 4 spaces
"set expandtab
"
" auto indent; new line with number of space at the beginning same as previous
"set autoindent
"
" when indenting with '>', use 4 spaces width
"set shiftwidth=2
"https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces/38461002
" Set whitespace and tab chars
set listchars=tab:>-,trail:·,eol:$
" kai hendry: set list listchars=nbsp:¬,tab:»·,trail:·,extends:>
"All: set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
"Enable: set list
" Scroll Offset
" Minimum number of screen lines that you would like above and below
" the cursor. This option applies to all commands, including searching.
set scrolloff=4
" Incremental search, show results as you type
set incsearch
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
"Obs:Needs ignorecase on!
set smartcase
" Remove useless splash screen
set shortmess+=I
" Set Menu for completion
set wildmenu
" Set Wild Menu mode
set wildmode=longest,list,full
" Set Wild to not list files with certain patterns
"set wildignorecase=
" Highlight Switching
"Note: This switches on syntax highlighting, but only if colors are available.
" And the 'hlsearch' option tells Vim to highlight matches with
" the last used search pattern
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
"Diff Mode
if &diff
set nohls
syntax off
colorscheme 0x7A69_dark
set diffopt=internal,filler,closeoff,algorithm:histogram,
\indent-heuristic,inline:char,linematch:60,vertical
set fillchars+=diff:╱
set cursorline
set cursorlineopt=line "number, both
set cursorbind scrollbind
set scrollopt=ver,jump,hor
"set diffopt+=iwhite
"highlight CursorLine cterm=underline gui=underline ctermbg=NONE guibg=NONE
"highlight DiffAdd ctermbg=22 guibg=#003300
"highlight DiffDelete ctermbg=52 guibg=#330000
"highlight DiffChange ctermbg=17 guibg=#000033
"highlight DiffText ctermbg=88 guibg=#660000 cterm=bold gui=bold
"Jump to next/previous change and center the view
nnoremap ]c ]czz
nnoremap [c [czz
au VimEnter * RainbowParenthesesToggle
endif
"Unset syntax highlighting in `diff' mode
"https://odd.blog/2016/11/24/howto-disable-syntax-highlighting-in-vimdiff/
" Matching brakets
set showmatch
"Note: Show matching brackets when text indicator is over them
"
" Matching brakets blink duration
set matchtime=4
"Note: How many tenths of a second to blink when matching brackets
" Show partial command in the last line of screen
set showcmd
"
" Command-line line number
"set cmdheight=3
"Note: Number of screen lines to use for the command-line.
" Split panes to right and bottomi
"set splitbelow
"set splitright
"Note: May feel more natural
" Auto-reload File
set autoread
"Note: When a file has been detected to have been changed outside of Vim and
"it has not been changed inside of Vim, automatically read it again. When the
"file has been deleted this is not done
" Vim has the ability to make use of the mouse,
" but it only works for certain terminals
"For XTerm, set mouse=a ; for xfce4-terminal use nothing or mouse=v
set mouse=a
"set mouse=v
"Ref: https://superuser.com/questions/436890/cant-copy-to-clipboard-from-vim
"Pasting from clipboard turns newlines into ^M (ctrl-m)
"Tip: :%s/\r//g
"https://stackoverflow.com/questions/5843495/what-does-m-character-mean-in-vim
" Confirmation messages
"set confirm
"Note: Certain operations that would normally fail because of unsaved
"changes to a buffer, e.g. ":q" and ":e", instead raise a dialog
"asking if you wish to save the current file(s)
"spelling check
"dictionaries
set spelllang=en_gb,pt_br,medicalterms-en
"medical,en-rare
"custom dictionary
set spellfile=~/.vim/spell/en.utf-8.add
"turn non spellcheck
"set spell
"setlocal spell
"setlocal spell spelllang=en_us
"see also: :help spell-quickstart
"https://www.linux.com/training-tutorials/using-spell-checking-vim/
" Searcheable Dirs list
set path+=~/.config/**,~/.cache/**,~/.fonts/**,~/.themes/**,~/.vim/**,**
"Note: This adds root dirs to your path
" WRAPPING
" Allow Wrap
set wrap
" Side-scrolling if NOWRAP
set sidescroll=5
"Note: Sidescrolling n chars at a time
"smooth scroll vim 9.1 (ctr-e, ctr-y, and mouse)
set smoothscroll
" HARD WRAPPING
" Wrap margin ( Effectively puts a <EOL> at wrappping!)
"set wrapmargin=1
" To set colour of "showbreak" and the empty-line "tilda" and others:
" "hi-NonText ctermfg=Blue" at your favorite theme: Default is Blue
"
" Add <EOL> at specified line width
" (Default: disabled, nought)
set textwidth=0
" cc=+1 " highlight column after 'textwidth'
"hi ColorColumn ctermbg=Blue
" Above option is overwwritten by color scheme colour
"
" Extra margin to the left
" (Causes textwidth to wrap more!)
"set foldcolumn=1
" SOFT WRAPPING
" Wrap long lines at a character in 'breakat' rather than at the last
" character that fits on the screen. Unlike 'wrapmargin' and 'textwidth',
" this does not insert <EOL>s in the file
set linebreak
" String to put at the start of lines that have been wrapped
"set showbreak=+++
" Display Invisible Chars (but disables soft wrapping)
" Previous/Next line movement
" ( Default: set whichwrap=b,s )
set whichwrap=b,s,<,>,[,],h,l
"Notes: Allow specified keys that move the cursor left/right to move to
"the previous/next line when the cursor is on the first/last character
"in the line."
" <BS> key when used at first position of line, move
" cursor to the end of previous line. <Space> key moves
" from the end of a line to the start of the next one
" in normal and editor modes
"If you want to keep your existing textwidth settings for most lines in your
"file, but not have Vim automatically reformat when typing on existing lines:
set formatoptions-=t
" GUI GVIM
set guifont=Ubuntu\ Mono\ 14
"set window size
if has("gui_running")
" GUI is running or is about to start.
" Maximize gvim window (for an alternative on Windows, see simalt below).
set lines=28 columns=80
"else
" " This is console Vim.
" if exists("+lines")
" set lines=50
" endif
" if exists("+columns")
" set columns=100
" endif
endif
"https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size
" SET SELECTION
"set clipboard=unnamed [ defaults ]
"set clipboard=unnamed
set clipboard=unnamedplus
"Copy/Paste/Cut
"if has('unnamedplus')
" set clipboard=unnamed,unnamedplus
"endif
"termux clipboard
if !empty($TERMUX_VERSION)
vnoremap <C-x> :!termux-clipboard-set<CR>
vnoremap <C-c> :w !termux-clipboard-set<CR><CR>
inoremap <C-v> <ESC>:read !termux-clipboard-get<CR>i
"https://ibnishak.github.io/blog/post/copy-to-termux-clip/
au TextYankPost * call system('termux-clipboard-set &', @")
function Paste(p)
let sysclip=system('termux-clipboard-get')
if sysclip != @"
let @"=sysclip
endif
return a:p
endfunction
noremap <expr> p Paste('p')
noremap <expr> P Paste('P')
"https://github.com/termux/termux-packages/issues/2308
endif
"PRIMARY BUFFER ACCESS ------> *Use XTerm PRIMARY_copy/paste keys!*
" Copy to PRIMARY
"nnoremap <F7> "*y
" Paste from PRIMARY
"nnoremap <F8> "*p
"Registers:
" * ( primary )
" + ( secondary )
" To copy: To paste:
" "*y "*p
"Ref: https://stackoverflow.com/questions/11489428/how-to-make-vim-paste-from-and-copy-to-systems-clipboard
"Ref: https://vim.fandom.com/wiki/Copy,_cut_and_paste
"paste in insert mode
inoremap <c-s> <c-r>*
inoremap <c-S> <c-r>+
"https://stackoverflow.com/questions/2861627/paste-in-insert-mode
" HISTORY AND UNDO
"
"
" History for commands, search strings,
" expressions, input() lines & debug cmds
" It does not manage Undo history!
" Default is 50; max 10000
set history=4000
"Notes: There are five separate history tables:
"- one for ':' commands
"- one for search strings
"- one for expressions
"- one for input lines, typed for the input() function.
"- one for debug mode commands
"Notes:
"- When you enter a command-line that is exactly the same as an older one, the
" old one is removed (to avoid repeated commands moving older commands out of
" the history).
"- Only commands that are typed are remembered. Ones that completely come from
" mappings are not put in the history.
"- All searches are put in the search history, including the ones that come
" from commands like "*" and "#". But for a mapping, only the last search is
" remembered (to avoid that long mappings trash the history).
"
"
" Undo history
set undofile
" Undo levels
" ( Default: 1000 for Unix )
set undolevels=2000
"TIP: move through history branches!
" type g- and g+
" BACKUP
" Set Backup
set backup
"Make a backup before overwriting a file.
set writebackup
" How Vim handles its renaming and moving of files
" Make a copy of the file and overwrite the original one
set backupcopy=yes
" Note: Slower but better than to rename and move file
" Keep first version
"set patchmode=.orig
" Backup extension (don't set if BufWritepre is set for backup)
"set backupext=~
" Otherwise, meaningful backup name, ex: filename@2015-04-05.14:59
" Same as incremental backups ( a new backup file every minute )
au BufWritePre * let &bex = '.bak' . strftime("%F.%Hh%Mm")
"https://gist.github.com/nepsilon/1c998cd95907ef5d2d29
" Skip patchmode file when pattern matches
"set backupskip [pattern]
" SWAP FILES
"Note: recover swap files with 'vim -r file.swp'
"Backup dir
set backupdir=~/.vim/bak
" Undofile dir
" ( Default: saved at same location as the editing file )
set undodir=~/.vim/undoes
" Set swap cache directory
set directory=~/.vim/swap
" Make those folders automatically if they don't already exist.
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
"https://github.com/PtrckM/dotfiles/blob/master/.vimrc
" FILEINFO
" Fileinfo Configuration
set viminfo=%,'400,n~/.vim/viminfo
"Example:
"set viminfo=%,<800,'10,/50,:100,h,f0,n~/.vim/cache/.viminfo
" | | | | | | | + viminfo file path
" | | | | | | + file marks 0-9,A-Z 0=NOT stored
" | | | | | + disable 'hlsearch' loading viminfo
" | | | | + command-line history saved
" | | | + search history saved
" | | + files marks saved
" | + lines saved each register (old name for <, vi6.2)
" + save/restore buffer list
"
" The viminfo file is used to store:
" The command line history.
" The search string history.
" The input-line history.
" Contents of non-empty registers.
" Marks for several files.
" File marks, pointing to locations in files.
" Last search/substitute pattern (for 'n' and '&').
" The buffer list.
" Global variables.
"
"Note: To check all options available, within vim :help options
"Refs:
"https://stackoverflow.com/questions/23012391/how-and-where-is-my-viminfo-option-set
"https://vi.stackexchange.com/questions/14357/moving-viminfo-file-to-vim-dir
"About viminfo creation:
"https://bugzilla.redhat.com/show_bug.cgi?id=193150
"https://unix.stackexchange.com/questions/59155/why-is-vi-apparently-broken-viminfo-error-e576-and-how-can-i-fix-it
"https://renenyffenegger.ch/notes/development/vim/editing/viminfo/index
"
" MISCELLANEOUS
"See: Steve Losh vimrc
"https://github.com/sjl
"Possible to rename file and maintain undo?
"Using :saveas keeps the undo history intact.
":saveas is equivalent to the combination of :w newname followed by :e #.
""I usually find it more handy than the :w + :e, especially since
"with :saveas it's not really
"https://vi.stackexchange.com/questions/25331/possible-to-rename-file-and-maintain-undo
" Do not redraw screen in the middlw of macro (makes them complete faster)
set lazyredraw
"https://www.hillelwayne.com/post/intermediate-vim/
"To limit the width of text to 72 characters in Mutt
au BufRead /tmp/mutt-* set tw=72
" Resize splits when the window is resized
au VimResized * :wincmd =
" A buffer becomes hidden when it is abandoned
"set hid
" COMMANDS & FUNCTIONS
"Edit .Vimrc
command Vrc !vim ~/.vimrc
"Edit .ViFMrc
command Vfrc !vim ~/.config/vifm/vifmrc
"Edit .Xresources
command Xrc !vim ~/.Xresources
"Edit .Bashrc
command Brc !vim ~/.bashrc
" Browse recent docs with scratch buffer
command Brosb :new +setl\ buftype=nofile |
\ 0put =v:oldfiles | execute 'g/^/m0' |
\ nnoremap <buffer> <CR> :e <C-r>=getline('.')<CR><CR>
"Note: For full height, set :99new
" https://www.google.com/search?client=firefox-b-d&q=how+to+use+%3Aol+vim
" Select a Range of Lines instead of entering Visual Mode
command! -range Vis normal! <line1>GV<line2>G
"Ex: :10,12Vis
" https://unix.stackexchange.com/questions/43381/select-lines-using-ranges-in-vim
" Sudo saves the file with :W
" ( Useful for handling the permission-denied error )
"command Sw w !sudo tee % > /dev/null
" Should have the same effect as:
"command! SudoWrite w !sudo tee > /dev/null %
"https://www.reddit.com/r/vim/comments/8k4p6v/what_are_your_best_mappings/
"Note: Compare SudoWrite and SudoEdit in plug-in vim-eunuch
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
"https://github.com/PtrckM/dotfiles/blob/master/.vimrc
" Select (charwise) the contents of the current line, excluding indentation.
" Great for pasting Python lines into REPLs.
nnoremap vv ^vg_
" Super TAB
" Install vim-supertab OR use the following function
"
"function! Smart_TabComplete()
" let line = getline('.') " current line
"
" let substr = strpart(line, -1, col('.')+1) " from the start of the current
" " line to one character right
" " of the cursor
" let substr = matchstr(substr, "[^ \t]*$") " word till cursor
" if (strlen(substr)==0) " nothing to match on empty string
" return "\<tab>"
" endif
" let has_period = match(substr, '\.') != -1 " position of period, if any
" let has_slash = match(substr, '\/') != -1 " position of slash, if any
" if (!has_period && !has_slash)
" return "\<C-X>\<C-P>" " existing text matching
" elseif ( has_slash )
" return "\<C-X>\<C-F>" " file matching
" else
" return "\<C-X>\<C-O>" " plugin matching
" endif
"endfunction
"
"inoremap <tab> <c-r>=Smart_TabComplete()<CR>
"
"Ref: Function: https://vim.fandom.com/wiki/Smart_mapping_for_tab_completion
"Ref: vim-supertab: https://github.com/ervandew/supertab
" :w!!
" write the file when you accidentally opened it without the right (root) privileges
"cmap w!! w !sudo tee % > /dev/null
"Ref: https://github.com/charnley/dotfiles/blob/master/vimrc
" Ignore whitespace diff mode
"if &diff
" " diff mode
" set diffopt+=iwhite
"endif
"Check: https://github.com/charnley/dotfiles/blob/master/vimrc
"
" diff context lines around changes
":set diffopt+=context:0
" PLUG - INS
"
" VIM-EUNUCH
":Delete: Delete a buffer and the file on disk simultaneously.
":Unlink: Like :Delete, but keeps the now empty buffer.
":Move: Rename a buffer and the file on disk simultaneously.
":Rename: Like :Move, but relative to the current file's containing directory.
":Chmod: Change the permissions of the current file.
":Mkdir: Create a directory, defaulting to the parent of the current file.
":Cfind: Run find and load the results into the quickfix list.
":Clocate: Run locate and load the results into the quickfix list.
":Lfind/:Llocate: Like above, but use the location list.
":Wall: Write every open window. Handy for kicking off tools like guard.
":SudoWrite: Write a privileged file with sudo.
":SudoEdit: Edit a privileged file with sudo.
"File type detection for sudo -e is based on original file name.
"New files created with a shebang line are automatically made executable.
"New init scripts are automatically prepopulated with /etc/init.d/skeleton
"https://github.com/tpope/vim-eunuch
" VIM-SUPERTAB
let g:SuperTabDefaultCompletionType = "context"
"
"the default is to press <CTR-X> + <CTR-O> to activate omni-completion
" the following setting means you can just press Tab instead
"let g:SuperTabDefaultCompletionType = "<C-X><C-O>" "good for HTML+CSS
"https://vim.fandom.com/wiki/Omni_completion_popup_menu
"
"or:https://stackoverflow.com/questions/7722177/how-do-i-map-ctrl-x-ctrl-o-to-ctrl-space-in-terminal-vim
"inoremap <leader>, <C-x><C-o>
"
" INSTANT COMPLETION
"imap <Leader><Tab> <C-X><C-F>
" NOW WE CAN
" - Hit tab to :find by partial match
" - Use * at the beginning or end of string to make it fuzzy
" THINGS TO CONSIDER
" - :b lets you autocomplete any open buffer
"https://www.youtube.com/watch?v=XA2WjJbmmoM
" KEYBINDINGS
"
"Note: map = all modes
" vmap = for
" |------ visual(vmap) and
" |------ select mode(xmap)
"
" :map and :noremap are recursive and non-recursive versions
" of the various mapping commands. What that means is that if you do:
" :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.
"https://stackoverflow.com/questions/3776117/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping
"
"
"Note: The only suggestion I have is not just using a single prefix like <leader>
"and instead think of prefixes as logical groupings of functionality.
"so maybe you use <space> for a lot of things, and \ for others,
"and , for yet another grouping of mappings. i don't use <leader> at all, but there are bad (yes, I think it's bad) plugins that ship with <leader> as a default <Plug> mapping. if that is your case, still set your leader, but for the mappings you write yourself, consider using explicit <space> or otherwise.
"
"
"Note: In insert mode, <C-o> allows you to execute normal mode commands
"without leaving insert mode.
" MISC KEYBINDDINGS
" Command aliases
command! -nargs=* Set set <args>
"https://vi.stackexchange.com/questions/20720/how-can-i-alias-a-command-with-arguments
" One-stroke type ":" for cmd
noremap ; :
"https://vim.fandom.com/wiki/Map_semicolon_to_colon
" Autocorrect writing two colons
noremap :: :
" If you happen to press twice...
noremap :; :
" Exits
"Prefer to use ZZ or ZQ
" Bash-like Quit
"noremap <C-D> :q<CR>
"inoremap <C-\> :q<CR>
" Other Exits
noremap ;q :q
noremap :Q :q
noremap ;Q :q
noremap :Wq :wq
noremap ;Wq :wq
" Go to same line position within a wrapped line
noremap <Up> gk
noremap <Down> gj
inoremap <Up> <C-o>gk
inoremap <Down> <C-o>gj
" Alternative <ESC>
" Don't leave keyboard to ESC
" *Press and hold these keys*
inoremap jj <Esc>
cnoremap jj <Esc>
"inoremap \\\ <Esc>
"cnoremap \\\ <Esc>
"Note: It has to be a key combo you usually do not type!
"Ref: https://vi.stackexchange.com/questions/16963/remap-esc-key-in-vim
"imap jj <ESC>
" One user says: mapping jj to <esc> is a must have for me.
" It should be a default
" Quickly executing throw-away macros with q register
nnoremap Q @q
" Resize splits
"map + <c-w>-
"map - <c-w>+
"map < <c-w><
"map > <c-w>>
"easier indenting
"vnoremap > <gv
"vnoremap < <gv
"https://vim.fandom.com/wiki/Shifting_blocks_visually
" Escape spaces in command-mode by pressing space twice
"cnoremap <space><space> \<space>
" }}}
" Trailing whitespace {{{
" Only shown when not in insert mode so I don't go insane.
"augroup trailing
" au!
" au InsertEnter * :set listchars-=trail:⌴
" au InsertLeave * :set listchars+=trail:⌴
"augroup END
"https://gist.github.com/sooop/8dc424e13c6fe2e2a663
" CONTROL & SHIFT KEYS
" INDEX FOR CONTROL & UPPERCASE LETTERS ( SHIFT )
" C-Home Go to Top of document
" C-End Go to End of document
" Control + Home/End go to Top/Bottom of file
noremap <C-Home> gg
noremap <C-End> G
inoremap <C-Home> gg
inoremap <C-End> G
"https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping
"https://vim.fandom.com/wiki/Moving_around
"
" FUNCTION KEYS
" INDEX OF Fn KEYS
" <F1> Recent files
" <F2> Toggle line numbers
" <F3> Add timestamp
" <F4>
" <F5>
" <F6> Auto-Scroll
" <F7>
" <F8>
" <F9>
" <F10>
" <F11>
" <F12>
"Note:Fn keys do not work in GVim visual mode!!!
"
" <> Copy to PRIMARY (check set clipboard )
" <> Paste from PRIMARY ( idem )
"
" Recent Files
noremap <F1> :browse oldfiles<CR>
"Note: You can use '0, '1, '2, ... '9 to jump amongst recent files
"To set shortcuts for recent files :h c_#<
"E.g. :edit #<1 will open last file
"If you want to use 0-9 as marks for navigation,do not mark them manually
"After finding your query, press q or ESC and filenumber to edit it
" Line Numbers Toggle
noremap <F2> :set number! number?<CR>
"Note: Or nnoremap <F2> :set nonumber!<CR>
"The last cmd will report state "number" or "nonumer"
"https://stackoverflow.com/questions/762515/vim-remap-key-to-toggle-line-numbering
"Add Timestamp
"How to insert the result of a command into the text in vim?
nmap <F3> "=strftime('%c')<C-M>p
imap <F3> <C-R>=strftime('%c')<C-M>
"https://unix.stackexchange.com/questions/8101/how-to-insert-the-result-of-a-command-into-the-text-in-vim
" Auto-scrolling (Default: 3800m = 3.8 seconds)
map <F6> <C-e>:sleep 3800m<CR>j<F6>
"Note: Use CTR-C to stop
"Note: Use map not noremap
"Note: https://www.reddit.com/r/vim/comments/8k4p6v/what_are_your_best_mappings/
"
" MAPLEADER 0 ( Built-in )
" ( Default set to \ )
"let mapleader = "\"
"Suggestions: - , \ "\\" ç " " "\<Space>\<Space>"
"https://www.reddit.com/r/vim/comments/72kfsn/leader_suggestions/
" INDEX OF LEADER \ <defaults>
" \dust Remove shell dust such as ${var} --> $var
" \c Replace word under cursor (down)
" \C Replace word under cursor (up)
" \ci Replace word under cursor, case insensitive (down)
" \Ci Replace word under cursor case insensitive (up)
" \ca Replace all
" \f :find in dirs path
" \] Blank line below
" \[ Blank line above
" \t Capitalise Line As In A Title
" \T Capitalise Line As In a Title
" \s Open shell prompt
" \whs Trim whitespace in document