-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.ex
More file actions
80 lines (68 loc) · 2.05 KB
/
html.ex
File metadata and controls
80 lines (68 loc) · 2.05 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
"This file contains some maps that are useful when editing XML or HTML code.
" When a > is input at the end of a tag, automatically add the closing tag
map input > noremap >mmF<ye`mpa>bi/`mli
" Make the % command match XML tags. This doesn't work as the destination of
" operator commands or during visual selections, though, so we only map it for
" commands.
map command % noremap :xmlmatch
" Add <> to matchchar
set matchchar="{}()[]<>"
alias xmlmatch {
"Move the cursor to the matching HTML or XML tag name
"If not on tag name, then do the normal % character match
if current(/\i/) == ""
then normal %
else {
" d is the direction to search
" i counts nested tag pairs
" n is the tag name without any punctuation
" t is origin tag name without args or >
local d i n t
"Configure search parameters to be "normal"
local nowrapscan magic magicchar=^$.[* magicname noincsearch ignorecase nosmartcase
"HTML ignores case, but XML is case sensitive
if (tolower(dirext(filename)) << 4) == ".htm"
then set ignorecase
else set noignorecase
"This particular alias doesn't really change the file, but it uses
"the :normal command which *can* change the file and hence is not
"allowed on locked buffers. Temporarily turn off locking.
local nolocked
"Get the current tag name
let t=current(/<\/\i\+/)
if t
then {
let d="backward"
let n=t[,3...]
}
else {
let t=current(/<\i\+/)
if t
then {
let d="forward"
let n=t[,2...]
}
else error cursor isn't on a tag name
}
" move to the start of this tag, so we don't immediately find it in
" the following search loop and mistake it for a nested tag.
normal F<
"search for the tag, for nested tags. Stop on the matching one
normal mx
try {
set i=1
while i > 0
do {
"find the next opening or closing tag, in the proper direction
switch d
case forward normal /<\/\?\=$n\>
case backward normal ?</*\=$n\>
"count nested tag levels
if current(/<\/\?$n/) == t
then let i = i + 1
else let i = i - 1
}
}
else normal `x
}
}