EsckO
seems shortest: I can also come up with Ctrl-o?>?-
Enter or Esc?<
Enter%O
and variations for robustness, but they're more strokes.
Now, you can map any one of those (in normal or insert mode) to make it a single keystroke. I recommend a <buffer>
-local mapping, since this is specific to HTML-like (JSX?) code.
You could also use input()
to get the name and value of the attribute, and insert the line from the mapping. Something like
function PutAttribute() abort
const key = input('key: ')
const val = input('val: ')
const closer = search('>', 'bnW')
const to_place = closer - 1 " guess, can do better
const ind = repeat(' ', indent(to_place))
if closer > 1
return append(to_place, printf('%s%s=%s', ind, key, val))
endif
return 2
endfunction
Then map a call to PutAttribute
, but beware warnings in :help input()
about mappings which call input()
.
ci"
,vipJ
, etc. So I thought it'd be legitimate to ask for help and if I overlooked something.