.vim/autoload/vimrc.vim

Mon, 13 Feb 2023 02:20:08 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 13 Feb 2023 02:20:08 -0600
changeset 1015
21950cadff6b
parent 953
e033f9ce0d8c
permissions
-rw-r--r--

Ongoing nvim config

631
8e07c29f2672 fix viewdoc abbrevs and cabbrevs in general
Meredith Howard <mhoward@roomag.org>
parents: 619
diff changeset
1 func! vimrc#CommandAlias(abbrev, expand) abort
632
9a87ce42aa3c getcmdpos is cursor position in expr mode here, wont work
Meredith Howard <mhoward@roomag.org>
parents: 631
diff changeset
2 execute printf('cnoreabbrev <expr> %s (getcmdtype()==":" && getcmdline()=="%s") ? "%s" : "%s"', a:abbrev, a:abbrev, a:expand, a:abbrev)
631
8e07c29f2672 fix viewdoc abbrevs and cabbrevs in general
Meredith Howard <mhoward@roomag.org>
parents: 619
diff changeset
3 endfunc
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4
580
5a9e9be223f0 shorten
Meredith Howard <mhoward@roomag.org>
parents: 579
diff changeset
5 func! vimrc#AutoFmtToggle() abort
641
60b56bbfc143 use strict regex ops
Meredith Howard <mhoward@roomag.org>
parents: 640
diff changeset
6 if &formatoptions =~# 'a'
640
f8985ae54969 avoid abbreviated options
Meredith Howard <mhoward@roomag.org>
parents: 632
diff changeset
7 setl formatoptions-=a | echo '-a'
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 else
640
f8985ae54969 avoid abbreviated options
Meredith Howard <mhoward@roomag.org>
parents: 632
diff changeset
9 setl formatoptions+=a | echo '+a'
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 endif
580
5a9e9be223f0 shorten
Meredith Howard <mhoward@roomag.org>
parents: 579
diff changeset
11 endfunc
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12
586
ab5763bb6ca7 improve ltag
Meredith Howard <mhoward@roomag.org>
parents: 583
diff changeset
13 func! vimrc#Ltag(term) abort
ab5763bb6ca7 improve ltag
Meredith Howard <mhoward@roomag.org>
parents: 583
diff changeset
14 exe "ltag " . a:term
ab5763bb6ca7 improve ltag
Meredith Howard <mhoward@roomag.org>
parents: 583
diff changeset
15 lopen
ab5763bb6ca7 improve ltag
Meredith Howard <mhoward@roomag.org>
parents: 583
diff changeset
16 endfunc
ab5763bb6ca7 improve ltag
Meredith Howard <mhoward@roomag.org>
parents: 583
diff changeset
17
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 " Make paths when writing, as necessary
580
5a9e9be223f0 shorten
Meredith Howard <mhoward@roomag.org>
parents: 579
diff changeset
19 func! vimrc#MkNonExDir(file, buf) abort
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21 let dir=fnamemodify(a:file, ':h')
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22 if !isdirectory(dir)
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 call mkdir(dir, 'p')
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 endif
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 endif
580
5a9e9be223f0 shorten
Meredith Howard <mhoward@roomag.org>
parents: 579
diff changeset
26 endfunc
470
4c2db769baac Move into autoload
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27
805
59b23772424a No more unite-session
Meredith Howard <mhoward@roomag.org>
parents: 803
diff changeset
28 func! vimrc#AutoSessionCheck() abort
583
e2c2404479d3 move one more func
Meredith Howard <mhoward@roomag.org>
parents: 580
diff changeset
29 if strlen(v:servername) > 0 && match(v:servername, 'VIM') == -1
805
59b23772424a No more unite-session
Meredith Howard <mhoward@roomag.org>
parents: 803
diff changeset
30 let sessionfile = g:vimcache . "/session/" . tolower(v:servername) . ".vim"
59b23772424a No more unite-session
Meredith Howard <mhoward@roomag.org>
parents: 803
diff changeset
31
59b23772424a No more unite-session
Meredith Howard <mhoward@roomag.org>
parents: 803
diff changeset
32 if filereadable(sessionfile)
59b23772424a No more unite-session
Meredith Howard <mhoward@roomag.org>
parents: 803
diff changeset
33 execute "source " . sessionfile
59b23772424a No more unite-session
Meredith Howard <mhoward@roomag.org>
parents: 803
diff changeset
34 endif
583
e2c2404479d3 move one more func
Meredith Howard <mhoward@roomag.org>
parents: 580
diff changeset
35 endif
e2c2404479d3 move one more func
Meredith Howard <mhoward@roomag.org>
parents: 580
diff changeset
36 endfunc
728
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
37
953
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
38 func! vimrc#Grep(...) abort
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
39 let pattern = get(a:000, 0, expand('<cword>'))
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
40 let cmd = join([&grepprg, shellescape(pattern)] + a:000[1:], ' ')
832
8acb094e5e12 use cword as ag/rg default
Meredith Howard <mhoward@roomag.org>
parents: 829
diff changeset
41
953
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
42 cgetexpr system(cmd)
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
43 call setqflist([], 'a', {"title": cmd})
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
44 let @/ = '\v' . pattern
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
45 copen
e033f9ce0d8c Simplify ag/grep setup
Meredith Howard <mhoward@roomag.org>
parents: 943
diff changeset
46 cfirst
803
ffc6f9c140cd Move this Ag stuff into a function, remove flickers
Meredith Howard <mhoward@roomag.org>
parents: 750
diff changeset
47 endfunc
ffc6f9c140cd Move this Ag stuff into a function, remove flickers
Meredith Howard <mhoward@roomag.org>
parents: 750
diff changeset
48
728
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
49 func! vimrc#Gcd() abort
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
50 let root = system('git rev-parse --show-toplevel 2>/dev/null')[:-2]
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
51 if ! v:shell_error
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
52 exec 'cd ' . root
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
53 endif
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
54 pwd
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
55 endfunc
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
56
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
57 func! vimrc#Hgcd() abort
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
58 let root = system('hg root 2>/dev/null')[:-2]
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
59 if ! v:shell_error
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
60 exec 'cd ' . root
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
61 endif
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
62 pwd
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
63 endfunc
60df63f03873 I don't really use these except for the cd shortcuts
Meredith Howard <mhoward@roomag.org>
parents: 725
diff changeset
64
750
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
65 func! vimrc#SafeFilterFile(cmd)
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
66 let errors = tempname()
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
67 try
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
68 exec 'silent %!' . a:cmd . ' 2>' . shellescape(errors)
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
69 if v:shell_error
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
70 for line in readfile(errors)
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
71 echomsg line
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
72 endfor
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
73 endif
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
74 finally
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
75 call delete(errors)
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
76 endtry
36a4da0a9863 Separate errors from filter stream
Meredith Howard <mhoward@roomag.org>
parents: 728
diff changeset
77 endfunc
920
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
78
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
79 if has('perl')
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
80 func! vimrc#PruneSession() abort
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
81 perl <<END_PERL
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
82 my @bufs =
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
83 grep { !-e $_->Name || -d _ || (-M _ >= 30) }
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
84 grep { $_->Name } VIM::Buffers();
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
85
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
86 while (my $b = shift @bufs) {
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
87 VIM::Msg 'pruned: ' . $b->Name, 'Comment';
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
88 VIM::DoCommand 'bwipeout ' . $b->Number;
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
89 }
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
90 VIM::DoCommand 'bprev'
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
91 unless $curbuf->Name;
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
92 END_PERL
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
93 endfunc
c1cc35d18597 Add PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 897
diff changeset
94 endif
939
b769704bb258 auto-prune junk directories
Meredith Howard <mhoward@roomag.org>
parents: 920
diff changeset
95
940
fb5519032710 Whoops, fix args
Meredith Howard <mhoward@roomag.org>
parents: 939
diff changeset
96 func! vimrc#PrepDir(path) abort
fb5519032710 Whoops, fix args
Meredith Howard <mhoward@roomag.org>
parents: 939
diff changeset
97 if !filewritable(a:path)
fb5519032710 Whoops, fix args
Meredith Howard <mhoward@roomag.org>
parents: 939
diff changeset
98 call mkdir(a:path, 'p', 0700)
939
b769704bb258 auto-prune junk directories
Meredith Howard <mhoward@roomag.org>
parents: 920
diff changeset
99 endif
b769704bb258 auto-prune junk directories
Meredith Howard <mhoward@roomag.org>
parents: 920
diff changeset
100 endfunc
b769704bb258 auto-prune junk directories
Meredith Howard <mhoward@roomag.org>
parents: 920
diff changeset
101
943
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
102 if has('ruby')
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
103 func! s:PruneFiles(path, days) abort
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
104 ruby <<END_RUBY
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
105 require 'pathname'
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
106
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
107 (path, days) = VIM.evaluate('[a:path, a:days]')
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
108 sunset = Time.now - (days * 86400)
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
109
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
110 Pathname(path).realpath.each_child do |file|
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
111 file.delete if file.mtime < sunset
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
112 end
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
113 END_RUBY
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
114 endfunc
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
115 else
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
116 func! s:PruneFiles(path, days) abort
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
117 endfunc
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
118 endif
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
119
939
b769704bb258 auto-prune junk directories
Meredith Howard <mhoward@roomag.org>
parents: 920
diff changeset
120 func! vimrc#PruneFiles(path, days) abort
943
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
121 call s:PruneFiles(a:path, a:days)
939
b769704bb258 auto-prune junk directories
Meredith Howard <mhoward@roomag.org>
parents: 920
diff changeset
122 endfunc
943
e0ff02862951 rubyize PruneFiles
Meredith Howard <mhoward@roomag.org>
parents: 940
diff changeset
123

mercurial