Home

Today I Learned Mapping te to tabedit in Vim

Vim's [TODO: Code shorthand span ] command seems long considering how often it's used. Applying logic from this StackOverflow answer produces this customization:

bash
cnoreabbrev <expr> te getcmdtype() == ":" && getcmdline() == 'te' ? 'tabedit' : 'te'

It defines a [TODO: Code shorthand span ] shortcut which expands to `:tabedit`. Throw it in [TODO: Code shorthand span ] and save five characters for every tab open.

It's worth pointing out that this accepted StackOverflow answer provides a dangerous alternative. It recommends [TODO: Code shorthand span ] (aka [TODO: Code shorthand span ]). For example, [TODO: Code shorthand span ].

The gotcha hidden in this approach is that it expands across the command. Trying to run [TODO: Code shorthand span ] will be altered to [TODO: Code shorthand span ].

Not so good.

And, yes, I added an answer to help out there too.

~ fin ~