For example, cursor shall be at "*":

  sx={{mb: 3}}
  Che*ck this!

E.g. add align="center" to Typography tag with the fewest keystrokes possible. Is there a nice shortcut, instead of <Esc>ko, something like cit, but "add (attribute) to tag"?

  • is this a vimgolf challenge? Commented May 23, 2023 at 15:29
  • 1. "Lowest number of keys pressed" ≠ "fastest". 2. No, there is no such thing built-in. 3. This is the ideal use case for creating a custom mapping that does exactly what you want with the keystrokes you want. Let's see something that you tried.
    – romainl
    Commented May 23, 2023 at 15:43
  • 1
    @ChristianBrabandt It's the little tips, snippets, mentions I've found and researched on the net, that make my vim experience so pleasant and fast, e.g. ci", vipJ, etc. So I thought it'd be legitimate to ask for help and if I overlooked something.
    – fl_
    Commented May 23, 2023 at 18:18
  • ci" and vipJ are not "tips" or "tricks" or whatever. They are basic functionalities available to anyone smart enough to learn Vim properly.
    – romainl
    Commented Oct 21, 2023 at 16:50

1 Answer 1


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))
  return 2

Then map a call to PutAttribute, but beware warnings in :help input() about mappings which call input().

  • Ty for the inspiration, ?><kbd>Enter</kbd>i is awesome I think and also works when tags are in a single line for example.
    – fl_
    Commented May 24, 2023 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.