-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vimrc8
891 lines (875 loc) · 37.8 KB
/
_vimrc8
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
" .vimrc
" Tested back to 7.4.1147 (gvim, 2013-08-10) and 7.0 (vim, 2006-05-08)
" 01 Windows, WSL specific options {{{
" Windows Vim/Gvim stores the '.vimrc' as '_vimrc' in the home directory.
" The following are changes made so that the experience using Windows Gvim
" and WSL, are optimal.
" From 2023-07-15 use a .gvimrc / _gvimrc; despite being two separate files,
" that is the recommended approach. It is particularly useful for separate
" gui-only things, like customising the Toolbar.
"
" Prevent startup in Replace mode in WSL (no impact native Linux/Win32)
set t_u7=
if has("gui_running")
" MOVED TO _gvimrc
" " set guifont=DejaVu_Sans_Mono_for_Powerline:h12
" " Set gvim-specific font to ensure display of special characters
" " however, for WSL the font can be set in the
" " WSL Properties dialog, but the font should also be installed
" set guifont=FiraCode_NFM:h12 " https://www.nerdfonts.com/font-downloads
" " extend default guioptions to...
" set guioptions+=!abceghLmrtT
" " customise the tabline for when using vim9-tene
" if version > 899
" set guitablabel=%{%join(tabpagebuflist('%'),'\ ˙\ ')..' %t'%}
" endif
" if has("Win32")
" " set renderoptions=type:directx " 'glyphs more beautiful', coloured emoji
" " BUT ligatures in coding fonts ... NO!
" " KEEP cmd.exe default as that keeps gx working!
" "set shell=bash.exe " Vim plays nicest with Linux/bash, so exploit that
" " set shell=powershell.exe " system32\WindowsPowerShell\v1.0\powershell.exe
" let $PYTHONPATH="~/AppData/Local/Programs/Python/Python311" " needed?
" endif
else " No GUI, but Windows = console Vim; a more distinct Replace mode cursor
" Only partially works in console Win32, but use it nonetheless (guicursor)
if has("Win32")
set guicursor=n-v-c-sm:block,o-r-cr:hor50,i-ci:hor25
set lines=28
" Keep cmd.exe, but you can use "powershell" from the command line to
" start powershell anyway
" set shell=powershell.exe
"let $PYTHONPATH="~/AppData/Local/Programs/Python/Python311" " needed?
" could look to doing a non-gui tabline here using the guitablabel content
" for the tabs?
endif
endif
" Mini thesaurus: use if present
if v:version > 801
if has("Win32")
if filereadable($HOME..'\vimfiles\mini-thesaurus.txt')
set thesaurus=$HOME\vimfiles\mini-thesaurus.txt
endif
else
if filereadable($HOME..'/.vim/mini-thesaurus.txt')
set thesaurus=$HOME/.vim/mini-thesaurus.txt
endif
endif
endif
" Autocommand to create the log directory if it doesn't exist
" create the log directory in the _gvimrc when in the GUI, otherwise toolbar
" unmenu gets written
if has("Win32")
if !isdirectory(expand($HOME) . '\vimfiles\logs')
silent! call mkdir($HOME . '\vimfiles\logs', 'p')
endif
let g:verbose_log_filename = $HOME . '\vimfiles\logs\' . strftime('%Y-%m-%dT%H%M%S.log')
else
if !isdirectory(expand($HOME) . '/.vim/logs')
silent! call mkdir($HOME . '/.vim/logs', 'p')
endif
let g:verbose_log_filename = $HOME . '/.vim/logs/' . strftime('%Y-%m-%dT%H%M%S.log')
endif
"Turning off verbose logging...
"let &verbosefile=g:verbose_log_filename
" }}}
" 02 Highlights {{{
" There are not a lot of .vimrc highlights because I accept defaults for many
" things. I used to set these up here, but now use a function and a
" combination of autocommand groups and a one-off setup at the end of either
" this vimrc or gvimrc (for the GUI).
" ----------------------------------------------------------------------------
" NB: This is set for my setup in Windows Vim (non-GUI). It needs to be
" optimised for Debian 12, WSL, and Vim from PowerShell?
" First, set the colorscheme to default, which I toyed with changing, but
" settled with default EVERYWHERE, so this is kind of redundant...
if !has("gui_running")
if has("unix")
colorscheme default
else
colorscheme default
endif
else
" Set things in _gvimrc since this is specific to the GUI
endif
" }}}
" 03 Settings (global) {{{
" Vim can be run with "-u NONE" or "-C" to not load a vimrc.
" Individual settings can be reverted with ":set option&" in most cases.
" For global settings that are left with the defaults, refer the end of this
" section.
set backspace=indent,eol,start " Allow backspacing everywhere in Insert mode
if v:version > 704 || (v:version == 704 && has("patch1147"))
set belloff=backspace,cursor,esc,insertmode " Turn off the bell!
endif
set clipboard=autoselect " Puts any Visual mode text into clipboard * register
set cmdheight=2 " Cmd-line height 2 lines; avoid lots of press <Enter> to...
set cmdwinheight=9 " Cmd-line window (q:) height: a few more lines v. default
if v:version > 702
set colorcolumn=80 " Put a highlighted column at chr 80; refer <leader>I below
endif
"set cursorlineopt=number,line " Highlight the line + number in insert modes
if v:version > 799
set display=truncate " Show @@@ in last line if truncated
endif
set encoding=utf-8 " Character encoding used inside Vim itself, not files
set expandtab " Uses No. of spaces to insert a <Tab>s
set fileformats=unix,dos
set foldclose=all " auto close folds when cursor leaves
set foldcolumn=1 " Show folds in a single column; equiv. let &foldcolumn = 1
set foldlevelstart=0 " Start editing with all folds closed
" set gui* are above in Windows...
set helpheight=13 " Minimum initial height for :h when it opens in a window
set hidden " Enable unsaved buffers to remain open (reduces error msgs)
set history=10000 " keep max lines of command line history (default is 50)
set hlsearch " use <C-L> to turn off highlighting w/ mapping <C-L> below
set incsearch " show search patten matches typing; requires has('reltime')
set keymodel=startsel " Makes <S-PageUp> etc. select the text and Visual mode
set keywordprg=:help " Program used for K (jumps to the Word) - use Vim help
set laststatus=2 " Always display statusline, even if when only one window
" set lines is above in Windows/GUI section
set list " Shows tabs, eol, etc., and refer below for setlistchars
if v:version >= 700 " listchars is not valie in 6.0 - may be in 6.n?
if v:version > 801
set listchars=nbsp:°,trail:·,tab:——►,eol:¶ " highlight formatting /specials
else
set listchars=nbsp:°,trail:·,tab:—►,eol:¶ " highlight formatting /specials
endif
endif
if v:version > 703
set matchpairs=(:),{:},[:],“:”,‘:’ " pairs to highlight when one's selected
endif
silent execute has('mouse') ? 'set mouse=ar' : '' | " enable in all modes
" don't hide the mouse cursor when something is typed - low value
set nomousehide
if v:version > 799
set nolangremap " prevent opt: may not be needed, but follows defaults.vim
endif
if v:version > 600
set numberwidth=3 " Line number width to min of 3; expand if more
endif
" set operatorfunc is defined in the map section (xnoremap <F8>) section
set printfont=FiraCode_NFM:h9 " This seems to keep things within 80chrs
set printheader=%<%F %h %m (%L lines)%=Page %N " custom header, incl. lines
set printoptions=number:y " prints with line numbers
if v:version > 600
set pumheight=9 " limit the popup menu for Insert mode completion to 9 lines
endif
if v:version > 800
set pumwidth=18 " ... and increase the character width for popup menu items
endif
" set renderoptions is in _gvimrc8
set scrolloff=99 " keep the cursor in the middle of the window
if v:version > 600
set sessionoptions=buffers,curdir,folds,help,options,tabpages,winpos,winsize
endif
" set shell is above in Windows/GUI section
set shiftwidth=2 " Spaces for each autoindent
set shortmess=inxtToOs " Close to default; better treatment of long messages
if v:version > 600
set showbreak=↪ " Show wrapped lines with U+21AA
else
set showbreak=_ " Show wrapped lines with U+21AA
endif
set showcmd " Display incomplete commands
set showmatch " Briefly jumps and shows matched { } ( ) [ ] when visible
set showmode " Show the mode you are in with --- INSERT --- et al.
silent execute version < 900 ? '' : 'set showtabline=1' | " use airline in v8
set sidescroll=2 " Just keep moving 1 char off the screen to the right
set smarttab " Inserts shiftwidth spaces at start of line
set softtabstop=0 " Mix of tabs and spaces ... nah, just confusing
set splitbelow " Split below rather than above
set startofline " Move to the first non-blank on the line after gg, d, etc.
" set statusline is obviously not a one line entry!
" set tabline is under development and includes guitablabel
set tabstop=8 " Explicit [default] number of spaces a tab equates to
" set thesaurus is above in Windows/GUI section
set tildeop " Makes ~ for changing case work w/ an operator v just a char
set timeout " Wait for mapping or key sequences
set title " Ensures filename [+=-] (path) - VIM in the titlestring
set ttimeout " time out on key codes, though superfluous with timeout 'on'
set ttimeoutlen=100 " wait up to 100ms after Esc for special key
set verbose=0
set viewdir=$HOME/vimfiles/view " Dir to save views (prevents rw errors)
if v:version > 600
set viminfo='100,<9999,s1000,h,rA:,rB:,r/tmp " viminfo file settings
else
" defaults
endif
set virtualedit= " Default the virtual edit setting (but <leader>v below!)
set whichwrap=b,s,h,l,>,<,~,],[ " Allow <Left>, etc., to wrap, all modes allowed
if v:version > 703
set wildignorecase " ignore case when completing file names and directories
endif
set wildmenu " display completion matches in a status line
set winheight=3 " Minimum number of lines in current window
set winminheight=3 " Minimum number of lines in each window
" -- Explanation of tabs because they are confusing in the help --
" Do not change 'tabstop' from its default value of 8 - there is good guidance
" out there for why not to mess with tabstop=8). With 'expandtab' the tab key
" will always insert spaces whereas with noexpandtab (the default, i.e., et=0)
" tabs will be inserted once a threshold of spaces is entered, e.g., at the
" fourth tab when softtabstop is set to 2. To enter an actual tab, use
" CTRL-V<Tab>, which I have mapped, in Insert mode, to Shift-Tab, which is a
" very easy way of ensuring an actual Tab character can be input but otherwise
" spaces are used.
" -- Non-local off/defaults -- {{{2
" allowrevins; ambiwidth; autochdir; autoshelldir;
" autoread; autowrite; autowriteall; background; backup; backupcopy;
" backupdir; backupext; backupskip; balloon*; breakat; browsedir; casemap;
" cd*; cedit; charconvert; columns; compatible; confirm; cpoptions;
" cryptmethod; cscope*; debug; define; delcombine; dictionary; diff*;
" digraph; directory; eadirection; edcompatible; emoji; equalalways;
" equalprg; errorbells; errorfile; errorformat; esckeys; eventignore; exrc;
" fileencodings; fileformats; fileignorecase; fillchars; foldopen; formatprg;
" fsync; gdefault; grepformat; grepprg; helpfile; helplang; highlight; hkmap;
" hkmapp; icon; iconstring; ignorecase; im*; include*; indentexpr; insertmode;
" isfname; isident; isprint; joinspaces; lang*; lazyredraw; linespace; lisp*;
" loadplugins; luadll; magic; make*; matchtime; maxcombine; maxfuncdepth;
" maxmapdepth; maxme*; menuitems; mkspellmem; modelin*; more; mousemodel;
" mousemoveevent; mouseshape; mousetime; mz*; opendevice; packpath; paragraphs;
" paste; pastetoggle; patchexpr; patchmode; path; perldll; previewheight;
" previewpopup; printdevice; printencoding; printexpr; printmb*; prompt;
" py*; quickfixtextfunc; redrawtime; regexpengine; remap; report; scroll;
" restorescreen; revins; rightlef*; rubydll; rule*; runtimepath; scroll*;
" sections; secure; selection; selectmode; shell?*; shiftround; shortname;
" showbreak; showfulltag; sidescrolloff; smartcase; smartindent;
" spellsuggest; splitright; suffix*; swap*; switchbuf; synmaxcol;
" tabpagemax; tag*; tcldlll; term*; terse; thesaurusfunc; timeoutlen;
" titlestring; titlelen; titleold; toolba*; tty*; undo*; update*; verbos*;
" viewoptions; viminfofile; visualbell; warn; weirdinvert; wildcha*;
" wildignore; wildmode; wildoptions; winaltkeys; window; winheight;
" winminwidth; winptydll; wrapscan; write; writebackup; writedelay; xtermcodes
" 2}}}
" {{{2 Local settings that I want initially (usually)
set autoindent " Alhough local, useful if working with text files.
if v:version > 704 || (v:version == 704 && has("patch1147"))
set nrformats=alpha,hex,bin " all except Octal for CTRL-A and CTRL-X
endif
silent execute (version < 900) ? '' : 'set nrformats+=unsigned'
set number " Display line numbers on the left and number width to 3
" nowrap Prefer to not wrap initially - turn it on if wanted
set nowrap
" 2}}}
" " }}}
" 04 Commands {{{
"
" -- COMMAND Cbum — creates a popup menu of the output of a command
" Mapped with <leader>b and <leader><shift>b below, i.e., create a popup
" menu for 8 seconds that displays the current buffers (and which can be
" used to select the buffer wanted and open it in a new split).
command! -nargs=1 -complete=command Cbum redir @x |
\ silent execute <q-args> | redir END |
\ let @y = substitute(strtrans(@x),'\^@','|','g') |
\ let g:lr = split(@y, "|") |
\ if len(g:lr) == 1 |
\ let winid = popup_menu(g:lr, #{time: 8000}) |
\ else |
\ let winid = popup_menu(g:lr,
\ #{borderchars:[ '', ' ', '', ' ', '', '', '', ''],
\ callback: {id, result ->
\ execute("if " .. result .. " > 0 | buffer " ..
\ str2nr(split(g:lr[result-1])[0]) .. " | endif" ..
\ " | if &buftype=='help' | set nolist | endif", "") } }) |
\ endif
"
" -- COMMAND Cpop — creates a popup of the output of a command
" For example, the command :Cpop ls! would be a synonym for the
" remapped <leader>b below, i.e., create a popup for 8 seconds that
" displays the current buffers (and which can be clicked to hide).
command! -nargs=+ -complete=command Cpop redir @x |
\ silent execute <q-args> | redir END |
\ let @y = substitute(strtrans(@x),'\^@','|','g') |
\ let g:lr = split(@y, "|") |
\ let winid = popup_menu(g:lr,
\ #{borderchars:[ '', ' ', '', ' ', '', '', '', ''],
\ time: 8000})
" \ let winid = popup_menu(g:lr, #{time: 8000})
" \ #{borderchars:[ '═', '║', '═', '║', '╒', '╕', '╝', '╚'],
" \ #{borderchars:[ '─', '│', '─', '│', '╭', '╮', '╯', '╰'],
"
" -- COMMAND DiffOrig — displays a diff between the buffer and the file loaded
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit #
\ | 0d_ | diffthis | wincmd p | diffthis
endif
"
" -- COMMAND Rp — redirects outputs of a command to the p register
" This means, for example, :Rp filter /S[duh]/ command
" will put the output of that command to the p register. Then all you need
" to do is "pp to put the contents of that register p to the buffer
" in Normal mode
command! -nargs=+ -complete=command Rp redir @p | silent execute <q-args> | redir END
" -- Command Ct - provides a popup of the time it takes to run a command
command! -nargs=+ -complete=command Ct let g:start = reltime() | silent execute <q-args> | let g:elapsed = reltimestr(reltime(g:start, reltime())) | call popup_menu(g:elapsed, {})
command! -nargs=+ -complete=command Cpop2 redir @x |
\ silent execute <q-args> | redir END |
\ let winid = popup_menu(@x, #{time: 8000})
" -- Command B - uses g:GoToBufferInTabs8(n) to go to the buffer number
if v:version >= 704 || (v:version == 704 && has('patch2015'))
command! -nargs=1 -complete=command B
\ silent execute ":call g:GoToBufferInTab8(" .. <f-args> .. ')'
" Mark a buffer and go to a buffer (uses :B command, above)
let g:mbuf = {}
command! -nargs=1 -complete=command Mb g:mbuf[<q-args>] = bufnr('%')
command! -nargs=1 -complete=command Gb execute ':B ' .. g:mbuf[<q-args>]
endif
" }}}
" 05 Functions {{{
"
" NB : the recommendation to add 'abort' after each so that
" if something goes wrong Vim will not try to run the whole function, as
" recommended by the Reddit vimrctips.
"
" ColoursConsoleReset
" NB:
" 1. Console only - for GUI refer gvimrc
" 2. Presumes using defaults for terminal (e.g., PowerShell = Campbell)
" The colours here are for just a few distinct key highlights like the line
" numbers and the current line number, non-printing wrap characters, and
" non-printing special characters, which are highlighted so that they are
" more obvious when editing documents. These are in an autocmd group too,
" so that they re-set if a colorscheme is called, and early in the .vimrc
" to ensure it is called if a colorscheme is. It is kept intentionally
" low impact (using default colorscheme only, and tweaking from there in all
" variants) PLUS considering vim-tene, which re-uses some of the in-built
" highlight groups, so some need slight tweaking.
function g:ColoursConsoleReset() abort
" default colorscheme overrides (they persist until the colorscheme changes)
if !has("gui_running")
if g:colors_name == "default"
" line numbers
highlight LineNr ctermfg=DarkGrey
" the line number of the active cursor
highlight CursorLineNr cterm=bold ctermfg=Yellow
" 'showmode' message's colour (e.g., -- INSERT --)
highlight ModeMsg ctermfg=LightGrey
" 'showbreak' and other non-text characters
highlight NonText ctermfg=DarkGrey
" 'list' characters like Tab
highlight SpecialKey ctermfg=Grey
" The inactive statusline, etc.
highlight ColorColumn ctermbg=DarkGrey
if has('Win32') " Windows: Powershell, Console Vim
highlight StatusLine ctermbg=White
highlight StatusLineNC ctermbg=DarkGrey
else " Windows Git Bash, Native Linux
highlight Visual cterm=reverse ctermbg=Black
highlight DiffAdd ctermbg=Blue
endif
else
" Do nothing special - only use default!
endif
else " GUI ...
" Handled in _gvimrc
endif
endfunction
"
" -- FUNCTION CustomCursorBLOCK — Cursor shape setting (XFCE only)
function! CustomCursorBLOCK() abort
if isdirectory('~/.config/xfce4')
if filewritable('~/.config/xfce4/terminal/terminalrc')
silent execute "!sed -i.bak -e 's/TERMINAL_CURSOR_SHAPE_IBEAM/TERMINAL_CURSOR_SHAPE_BLOCK/' ~/.config/xfce4/terminal/terminalrc"
endif
endif
set nocursorline
endfunction
"
" -- FUNCTION CustomCursorIBEAM — Cursor shape setting (XFCE only)
function! CustomCursorIBEAM() abort
if isdirectory('~/.config/xfce4')
if filewritable('~/.config/xfce4/terminal/terminalrc')
silent execute "!sed -i.bak -e 's/TERMINAL_CURSOR_SHAPE_BLOCK/TERMINAL_CURSOR_SHAPE_IBEAM/' ~/.config/xfce4/terminal/terminalrc"
endif
endif
set cursorline
endfunction
"
" -- FUNCTION CycleVirtualEdit — Cycle virtualedit settings from "all" to ""
function! CycleVirtualEdit() abort
if &virtualedit == "all"
set virtualedit=block
echo 'virtualedit=block'
elseif &virtualedit == "block"
set virtualedit=insert
echo 'virtualedit=insert'
elseif &virtualedit == "insert"
set virtualedit=onemore
echo 'virtualedit=onemore'
elseif &virtualedit == "onemore"
set virtualedit=
echo 'virtualedit='
else " One of: empty, none or NONE - synonymns - NB: none/NONE are only vim9
set virtualedit=all
echo 'virtualedit=all'
endif
endfunction
"
" -- FUNCTION GenerateUnicode(160,0xA1) — Puts table of Unicode characters
function! GenerateUnicode(first, last) abort
let i = a:first
while i <= a:last
if (i%256 == 0)
$put ='------------------------------------'
$put =' 0 1 2 3 4 5 6 7 8 9 A B C D E F'
$put ='------------------------------------'
endif
let c = printf('%04X ', i)
for j in range(16)
let c = c . nr2char(i) . ' '
let i += 1
endfor
$put =c
endwhile
endfunction
"
" -- FUNCTION Fpopmode ― Makes a popup notification with just the current mode
function! Fpopmode() abort
let winid = popup_notification(mode(1),#{time: 1000})
return ''
endfunction
"
" -- FUNCTION FwindowWrapToggle ― toggles wrap and nowrap for the current window
function! FwindowWrapToggle() abort
if &wrap==0
set wrap
else
set nowrap
endif
return ''
endfunction
"
" -- FUNCTION NextBuffer — Next/Prior buffer in the current window
function! NextBuffer(incr) abort
let current = bufnr("%")
let last = bufnr("$")
let new = current + a:incr
while 1
if new != 0 && bufexists(new)
execute ":buffer ".new
if &buftype == 'help'
set nolist
endif
break
else
let new = new + a:incr
if new < 1
let new = last
elseif new > last
let new = 1
endif
if new == current
break
endif
endif
endwhile
endfunction
"
" -- FUNCTION ToggleComment — Commenting code easily
" Modified from a stackoverflow source (1676632). Could use vim-commentary?
let s:comment_map = {"python": '#', "sh": '#', "bat": 'REM', "vbs": "'",
\ "omnimark": ";", "vim": '"'}
function! ToggleComment() abort
if has_key(s:comment_map, &filetype)
let comment_leader = s:comment_map[&filetype]
if getline('.') =~ "^\\s*" . comment_leader . " "
" Uncomment the line
execute "silent s/^\\(\\s*\\)" . comment_leader . " /\\1/"
else
if getline('.') =~ "^\\s*" . comment_leader
" Uncomment the line
execute "silent s/^\\(\\s*\\)" . comment_leader . "/\\1/"
else
" Comment the line
execute "silent s/^\\(\\s*\\)/\\1" . comment_leader . " /"
end
end
else
echo "No comment leader found for filetype"
end
endfunction
"
" -- FUNCTION ToggleLineNumber — Literal / relative / no line number toggling
function! ToggleLineNumber() abort
if !&number
set number
set norelativenumber
elseif &number && !&relativenumber
set relativenumber
elseif &number && &relativenumber
set nonumber
set norelativenumber
endif
endfunction
" Function to write a message to the log file
function! WriteVerboseLog() abort
let g:timestamp = strftime('%Y-%m-%dT%H%M%S')
execute 'silent! write! >> ' .. &verbosefile .. ' | echom "Vim started at " .. g:timestamp'
endfunction
" Function to go to a buffer wherever it appears in any tab (first instance)
function! g:GoToBufferInTab8(b)
let c = tabpagenr()
for t in range(tabpagenr('$'))
execute ':norm ' .. (t + 1) .. 'gt'
for w in range(1, winnr('$'))
if winbufnr(w) == a:b
execute ':' .. w .. 'wincmd w'
return
endif
endfor
endfor
execute ':norm ' .. c .. 'gt'
echo "Buffer not found in any window."
endfunction
" }}}
" 06 Mappings {{{
" Using silent execute enables a | to add a comment :)
" nmap — Normal mode mappings
silent execute 'nnoremap <Space> <Nop>' | " Remap space to nothing so that it
let mapleader = ' ' " can be remaped to leader in Normal
silent execute 'nnoremap <C-K> i<C-K>' | " Enter :digraphs from Normal mode too
silent execute 'nnoremap <C-L> :nohl<CR><C-L>' | " Redraw screen AND h/l off
silent execute 'nnoremap <C-S> :%sm_x_y_gc<C-Left><Right><Right>' | " CTRL-S
"nnoremap <silent> <Tab> :call NextBuffer(1)<CR>
"nnoremap <silent> <S-Tab> :call NextBuffer(-1)<CR>
" c[nore]map - Command-line mode only mappings {{{2
cnoremap <C-L> :exe "redrawstatus"<CR>
" 2}}}
" xmap — Visual mode mappings
silent execute 'xnoremap <C-S> :sm_x_y_gc<S-Left>' | " CTRL-S 'template' :%sm
xnoremap <silent> <leader>l :call ToggleLineNumber()<CR>gv
" From the help, add quotes around the visual selection (w/in line) g@ object
xnoremap <F8> <Cmd>set operatorfunc='{t ->getline(".")
\ ->split("\\zs") ->insert("\"", col("'']")) ->insert("\"", col("''[") - 1)
\ ->join("") ->setline(".")}'<CR>g@
" map — Normal, Visual, and Operator Pending modes mappings
noremap <leader>v :call CycleVirtualEdit()<CR>
noremap <leader>w :call FwindowWrapToggle()<CR>
noremap <leader>i :exe "set colorcolumn=80 \| set textwidth=79"<CR>
noremap <leader>I :exe "set colorcolumn=0 \| set textwidth=0"<CR>
noremap <silent> <leader>l :call ToggleLineNumber()<CR>
noremap <silent> <leader>c :call ToggleComment()<cr>
noremap <silent><leader>b :CpBuffersMenu buffers<CR>
noremap <silent><leader><S-b> :CpBuffersMenu buffers!<CR>
" imap — Insert mode mappings
silent execute 'inoremap <C-U> <C-G>u<C-U>' | " Bram recommended undo atom
silent execute 'inoremap <S-Tab> <C-V><Tab>' | " Enter a with <S-Tab>
" *map — mappings in all/many modes grouped for common sense
" <F9> for a mongo toggle to : and Normal mode from anywhere
" Remapping of the 'arrow' keys is a common practice, e.g., inoremap jk <Esc>
" but the delay is just annoying IMHO. A better approach is setting a specific
" mapping to <C-\><C-N>, the equivalent to escape, from a Function key. Since,
" F8 is a very comfortable key, being Lower with the left thumb and index
" finger on V, that works really well.
" (NB: Remapping Esc itself has unwanted side effects: don't do that!)
" So, <F9> is mapped in Normal, Insert, Visual, Op. Pending, and Terminal
" modes to go straight to Command mode. But, then also Command mode with
" <F9> goes to Normal mode. The overall result is that <F9> works like a
" mongo toggle between Normal and Command modes, as well as going there
" from all the other modes, with the exception of Terminal-Normal, where it
" needs to be exited first. (refer :h map-table for all combinations)
" Combined with belloff (turning the bell off, refer above)
" the annoying bell when <ESC> is pressed in Normal mode is also deactivated.
nnoremap <F9> <Esc>:
inoremap <F9> <C-\><C-N>:
vnoremap <F9> <C-\><C-N>:
onoremap <F9> <C-\><C-N>:
cnoremap <F9> <Esc>
if v:version > 800
tnoremap <F9> <C-W>c:
endif
" gk and gj for Up and Down screenwise
" Up-down motions default behaviour and comments
" Normal mode - j/k operate linewise
" - <Up>/<Down> operate linewise
" Insert mode - <Up>/<Down> operate linewise
" Mapping <C-Up> and <C-Down> in Normal mode makes sense because in Normal
" mode, e.g., j, <Down> and <C-Down> are synonyms and so that is inefficient.
" So, the 'solution' to enable screen-wise motion in Normal mode is to map:
nnoremap <C-Up> gk
" and
nnoremap <C-Down> gj
" There is no 'clean' way for making Insert mode work in the same manner.
" That is because the means of moving a visual line is to use <C-O> to
" make one Normal mode command. That has a few side effects when the
" statusline refreshes to account for the change in mode (i.e., from i
" to niI to i) as well as (oddly) creating a new buffer momentarily.
" Nonetheless, it is still worth providing the option for the times that there
" are wrapped lines. It also pays to add it for Visual/Select mode too:
inoremap <C-Down> <C-O>gj
inoremap <C-Up> <C-O>gk
vnoremap <C-Down> gj
vnoremap <C-Up> gk
" Note that with the 40% keyboard this is gold because the Down, Up are
" I turned these off because it makes the statusline jump too much and when
" in insert mode the functionality is not so bad anyhow.
"
"Toggle renderer in Windows: needs a if gui, if win32, and if directx; moved
"to _gvimrc since is is so specific to Win32 gui.
" }}}
" 07 Autocommands {{{
" vimStartup {{{2
augroup vimStartup
autocmd!
" 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 " 2}}}
" xfce {{{2
augroup xfce
autocmd!
autocmd InsertEnter * call CustomCursorIBEAM()
autocmd InsertLeave * call CustomCursorBLOCK()
autocmd VimEnter * call CustomCursorBLOCK()
autocmd VimLeave * call CustomCursorIBEAM()
augroup END " 2}}}
" skeletons (templates) {{{2
augroup skeletons
autocmd!
if filereadable(expand('~/vimfiles/skeleton.asciidoc'))
autocmd BufNewFile *.asciidoc 0r ~/vimfiles/skeleton.asciidoc
endif
if filereadable(expand('~/vimfiles/skeleton.txt'))
autocmd BufNewFile *.txt 0r ~/vimfiles/skeleton.txt
endif
augroup END " 2}}}
" colorschemes {{{2
if v:version >= 704 || (v:version == 704 && has('patch2015'))
augroup vimrc8-ColorScheme
autocmd!
autocmd ColorScheme * if v:version >= 704 || (v:version == 704
\ && has('patch2015')) |
\ call g:ColoursConsoleReset() | endif
augroup END
endif " 2}}}
" cursorline always on in Normal mode and Insert modes {{{2
augroup cursorline
autocmd!
" v:versionlong could be used here, however, that was only introduced in
" https://github.com/vim/vim/releases/tag/v8.1.1526 so the || with v:version
" and has('patchNNNN') must be used
autocmd InsertLeave * if v:version >= 802 || (v:version == 802
\ && has('patch0934')) |
\ set cursorlineopt=number | let &cursorline = 1 | endif
autocmd InsertEnter * if v:version >= 802 || (v:version == 802
\ && has('patch0934')) |
\ set cursorlineopt=number | let &cursorline = 1 | endif
augroup END " 2}}}
" force Normal mode moving to an unmodifiable buffer {{{2
" https://github.com/vim/vim/issues/12072
augroup forcenormal
autocmd!
autocmd BufEnter * execute (!&modifiable && !&insertmode)
\ ? ':call feedkeys("\<Esc>")' : ''
autocmd BufEnter * execute (!&modifiable && &insertmode)
\ ? ':call feedkeys("\<C-L>")' : ''
augroup END
" 2}}}
" }}}
" 08 Plugins {{{
" I am now using the inbuilt Vim plugin handling.
" * Plugins path: $HOME/.vim/pack/plugins $HOME\vimfiles\pack\plugins
" * To determine the remote git repository: git remote show origin
" https://github.com/madox2/vim-ai.git
" NB: Command packadd was not added until 7.4.1485, refer
" https://github.com/vim/vim-win32-installer/commit/7891721dfe19add4d0058fcfd8b43ae39fc54ba3
if v:version > 802
packadd! vim-ai
endif
" https://github.com/habamax/vim-asciidoctor.git
if v:version > 704
packadd! vim-asciidoctor
let g:asciidoctor_allow_uri_read = " -a allow-uri-read"
endif
" https://github.com/kennypete/vim-sents.git (my own vim9script plugin)
if v:version > 801
packadd! vim-sents
endif
" https://github.com/kennypete/vim-popped.git
let g:vim_popped_nowarn = 1
if (v:version > 802 || (v:version == 802 && has('patch3434')))
packadd! vim-popped
endif
" https://github.com/kennypete/vim-characterize.git (a fork, incl. my tools)
" characterize fails with v7.x (though perhaps works with late patches of 704)
if v:version > 704
packadd! vim-characterize
endif
" https://github.com/kennypete/vim-tene.git
"For testing colorschemes with vim-tene:
"set bg=dark
"set bg=light
"colorscheme gruvbox
try
let g:tene_ga = exists("g:tene_ga") ? g:tene_ga : {}
let g:tene_ga["line()"] = ['¶', ''] " Use pilcrow for line numbers ASCII
let g:tene_hi = exists("g:tene_hi") ? g:tene_hi : {}
let g:tene_hi['x'] = 'Conceal' " Override for Inactive statuslines
let g:tene_modes = exists("g:tene_modes") ? g:tene_modes : {}
let g:tene_modes["c"] = "CMDLINE" " Override for COMMAND-LINE
let g:tene_modestate = 1 " Always show the state(), not just mode(1)
let g:tene_8warn = 1 " Warning with Vim 8
" packadd was not a thing until v704.1485
if v:version > 704 || v:version == 704 && has('patch1485')
packadd! vim-tene
else
source $HOME/vimfiles/pack/plugins/opt/vim-tene/plugin/tene.vim
endif
catch " But, if vim-tene is unavailable or fails, create a basic statusline
set statusline=\ %-6.(%{mode(1)..'\ '..state()}%)\ b%n%<\ %t\ %m\ %r\ %h%=%y
set statusline+=\ %{&fileencoding}\ %{&fileformat}
set statusline+=\ %{'¶'..line('.')..'/'..line('$')}\ \|
set statusline+=%{virtcol('.')}\ U+%B\
endtry
" }}}
" 09 Syntax + filetype {{{
if v:version > 704 || (v:version == 704 && has("patch1147"))
syntax enable " syntax h/l; could be 'on' and/or test for t_Co/has('syntax')
endif
filetype plugin indent on " Refer :filetype-overview Current status :filetype
"}}}
" 88 Deleted {{{
" (notes to more material deletions and .vimrc history)
" VIM MODES ***********************************************************
" Mode information: the table that was included as a comment has been removed.
" Just gx this https://github.com/kennypete/asciidoc/blob/main/vim.asciidoc
" Also gx https://rawgit.com/darcyparker/1886716/raw/vimModeStateDiagram.svg
" PYMODE **************************************************************
" Deleted plugin: Pymode. I was not using this enough. If the old setup is
" wanted for whatever reason, the setup as at 6/7/2022 is at:
" https://github.com/kennypete/.vimrc/blob/86db077d1039a4cd43b5d67f050bca1f4f2e8a91/_vimrc
" }}}
" 98 Development {{{
" --------------------------
" COMMAND LINE NORMAL 'MODE'
" --------------------------
" Look to using g:r and g:f etc. for r, f, t, commands
" Look to using g:00 for {n} before other commands
function! Truncate() abort
let g:num = strlen(getcmdline()) - (strlen(getcmdline()) - getcmdpos())
let @" = strpart(getcmdline(), 0, g:num)
endfunction
function! CommandLineNormal() abort
" not handled: n{char}; multiple chars, e.g., dl, but a commented example
" has been retained to show how it could work, noting d would then have the
" obligatory delay before executing; f could maybe be made to work with a
" function? (for now it is <Nop>);
" ideas from https://github.com/tpope/vim-rsi/blob/master/plugin/rsi.vim
execute maparg('0', 'c') == '' ? 'cnoremap 0 <Home>' : 'cunmap 0'
execute maparg('$', 'c') == '' ? 'cnoremap $ <End>' : 'cunmap $'
execute maparg('a', 'c') == '' ? 'cnoremap a <Right><Cmd>call CommandLineNormal()<CR>' : 'cunmap a'
execute maparg('b', 'c') == '' ? 'cnoremap b <C-Left>' : 'cunmap b'
execute maparg('c', 'c') == '' ? 'cnoremap c <Cmd>call CommandLineNormal()<CR>' : 'cunmap c'
execute maparg('d0', 'c') == '' ? 'cnoremap d0 <C-U>' : 'cunmap d0'
execute maparg('dd', 'c') == '' ? 'cnoremap dd <End><C-U>' : 'cunmap dd'
execute maparg('dl', 'c') == '' ? 'cnoremap dl <Del>' : 'cunmap dl'
execute maparg('dh', 'c') == '' ? 'cnoremap dh <Backspace>' : 'cunmap dh'
execute maparg('e', 'c') == '' ? 'cnoremap e <C-Right>' : 'cunmap e'
execute maparg('f', 'c') == '' ? 'cnoremap f <Nop>' : 'cunmap f'
execute maparg('g', 'c') == '' ? 'cnoremap g <Nop>' : 'cunmap g'
execute maparg('h', 'c') == '' ? 'cnoremap h <Left>' : 'cunmap h'
execute maparg('i', 'c') == '' ? 'cnoremap i <Cmd>call CommandLineNormal()<CR>' : 'cunmap i'
execute maparg('j', 'c') == '' ? 'cnoremap j <Down>' : 'cunmap j'
execute maparg('k', 'c') == '' ? 'cnoremap k <Up>' : 'cunmap k'
execute maparg('l', 'c') == '' ? 'cnoremap l <Right>' : 'cunmap l'
execute maparg('m', 'c') == '' ? 'cnoremap m <Nop>' : 'cunmap m'
execute maparg('n', 'c') == '' ? 'cnoremap n <Nop>' : 'cunmap n'
execute maparg('o', 'c') == '' ? 'cnoremap o <Cmd>call CommandLineNormal()<CR>' : 'cunmap o'
execute maparg('p', 'c') == '' ? 'cnoremap p <C-R>"' : 'cunmap p'
execute maparg('q', 'c') == '' ? 'cnoremap q <Nop>' : 'cunmap q'
execute maparg('r', 'c') == '' ? 'cnoremap r <Nop>' : 'cunmap r'
execute maparg('R', 'c') == '' ? 'cnoremap R <Insert>' : 'cunmap R'
execute maparg('s', 'c') == '' ? 'cnoremap s <Del><Cmd>call CommandLineNormal()<CR>' : 'cunmap s'
execute maparg('t', 'c') == '' ? 'cnoremap t <Nop>' : 'cunmap t'
execute maparg('u', 'c') == '' ? 'cnoremap u <Nop>' : 'cunmap u'
execute maparg('v', 'c') == '' ? 'cnoremap v <Nop>' : 'cunmap v'
execute maparg('w', 'c') == '' ? 'cnoremap w <C-Right>' : 'cunmap w'
execute maparg('x', 'c') == '' ? 'cnoremap x <Del>' : 'cunmap x'
execute maparg('X', 'c') == '' ? 'cnoremap X <C-U>' : 'cunmap X'
"execute maparg('y', 'c') == '' ? 'cnoremap y <Del>' : 'cunmap y'
execute maparg('Y', 'c') == '' ? 'cnoremap Y <Cmd>let @"=getcmdline()<CR>' : 'cunmap Y'
"execute maparg('<C-x>', 'c') == '' ? 'cnoremap <C-X> <End><C-U>' : 'cunmap <C-x>'
endfunction
cnoremap <C-n> <Cmd>call CommandLineNormal()<CR>
cnoremap <C-s> <Cmd>call Truncate()<CR>
" augroup beronowrite
" autocmd!
" autocmd BufEnter * let &write = &readonly==1 ? 0 : 1
" augroup END
" ***********************
" Tabline?
" ***********************
" set tabline=
" for i in range(tabpagenr('$'))
" if i + 1 == tabpagenr()
" set tabline+='%#TabLineSel#'
" else
" set tabline+='%#TabLine#'
" endif
" set tabline+=%{'%'..(i+1)..'T'}
" set tabline+='\ '
" set tabline+=%{%bufname(tabpagewinnr(1))%}
" endfor
" set tabline+='%#TabLineFill#'
" #set tabline+='%T'
" if tabpagenr('$') > 1
" set tabline+='%=%#TabLine#%999Xclose'
" endif
"set tabline=%{%join(tabpagebuflist('%'),'\ ˙\ ')..' %t'%}
" function MyTabLine()
" let s = ''
" for i in range(tabpagenr('$'))
" select the highlighting
" if i + 1 == tabpagenr()
" let s ..= '%#TabLineSel#'
" else
" let s ..= '%#TabLine#'
" endif
"
" set the tab page number (for mouse clicks)
" let s ..= '%' .. (i + 1) .. 'T'
"
" the label is made by MyTabLabel()
" let s ..= ' %{MyTabLabel(' .. (i + 1) .. ')} '
" 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 ..= '%=%#TabLine#%999Xclose'
" endif
"
" return s
" endfunction
"
" Now the MyTabLabel() function is called for each tab page to get its label. >
"
" function MyTabLabel(n)
" let buflist = tabpagebuflist(a:n)
" let winnr = tabpagewinnr(a:n)
" return bufname(buflist[winnr - 1])
" endfunction
" ***********************************
" Mark a buffer and go to a buffer
" ***********************************
let g:mbuf = {}
command! -nargs=1 -complete=command Mb let g:mbuf[<q-args>] = bufnr('%')
command! -nargs=1 -complete=command Gb execute ":b" .. g:mbuf[<q-args>]
" In au group, ideally read the mode before entering the buffer, so maybe use
" BufLeave to set that and use the mode at BufLeave and read that at
" BufEnter? The following could also be used, however, it only does with
" ModeChanged, so v:event can't be used with BufEnter.
" autocmd ModeChanged *:* let vevent=string(v:event) | redrawstatus!
"augroup vimEnter
" autocmd!
" autocmd VimEnter * call WriteVerboseLog()
"augroup END
" }}}
" vim: cc=+1 et fdm=marker ft=vim sta sts=0 sw=2 ts=8 tw=79