comparison plugins/taghelp.vim @ 11:eeda6b1401ae

changing files to .vim
author luka
date Fri, 28 Nov 2025 08:45:17 -0500
parents plugins/taghelp@1a705d7a7521
children
comparison
equal deleted inserted replaced
8:9c80955f0c6e 11:eeda6b1401ae
1 autocmd BufRead,BufNewFile *.blade.php set filetype=blade
2
3
4 " autocmd FileType blade inoremap<buffer> > <c-r>=CreateTag()<cr>
5
6
7 " Abbreviations
8 autocmd FileType blade iabbr <silent> class= class=""<Left><C-R>=Eatchar('\s')<CR>
9 autocmd FileType blade iabbr <silent> id= id=""<Left><C-R>=Eatchar('\s')<CR>
10 autocmd FileType blade iabbr <silent> log console.log()<Left><C-R>=Eatchar('\s')<CR>
11
12
13
14
15 func Eatchar(pat)
16 let c = nr2char(getchar(0))
17 return (c =~ a:pat) ? '' : c
18 endfunc
19
20 func CreateTag()
21 let line = getline('.')
22 let end = col('.') - 1
23 let begin = end - 1
24 let start = ''
25 let tagname_regexp = '[a-zA-Z0-9-_\.#]'
26 let first_chars = '[a-zA-Z0-9]'
27 let id_regexp = '[#]'
28 let class_regexp = '[\.]'
29 let tagname = ''
30 let id = ''
31 let classes = ''
32 let current_type = 0 " 0: tagname, 1: classes, 2: id
33 " incase the previous character was not in the usage
34 if line[begin] !~ first_chars
35 return '>'
36 endif
37
38 " reverse until we leave the replacement
39 while begin > 0
40 if line[begin] !~ tagname_regexp
41 let begin += 1
42 break
43 endif
44 let begin -= 1
45 endwhile
46
47 let start = begin
48
49 " start over reading the tag name
50 while begin < end
51 "deteremine if the type changes
52 if line[begin] =~ id_regexp
53 let current_type = 2
54 elseif line[begin] =~ class_regexp
55 let current_type = 1
56 "need a space in the class if there is already classes
57 if classes != ''
58 let classes .= ' '
59 endif
60 else
61 " Write to the current type
62 if current_type == 0
63 let tagname .= line[begin]
64 elseif current_type == 1
65 let classes .= line[begin]
66 elseif current_type == 2
67 let id .= line[begin]
68 endif
69 endif
70
71 let begin += 1
72 endwhile
73
74 " Trim the strings, just in case
75 let tagname = trim(tagname)
76 let id = trim(id)
77 let classes = trim(classes)
78
79
80 let str = '<' .tagname
81 if id != ''
82 let str .= ' id="' . id . '"'
83 endif
84 if classes != ''
85 let str .= ' class="' . classes . '"'
86 endif
87 let str .= '> </'. tagname . '>'
88 " delete the previous characters
89 let del_count = (end-start)
90 execute "normal! " . del_count . "X"
91 " delete the char under the cursor
92 execute "normal! x"
93
94 return str . repeat("\<Left>", len(tagname) + 4)
95
96 endfunc
97