nye17
nye17

Reputation: 13347

vim abbr: how to stop from generating new line?

in vimrc if I do

iab YBK \left<\right><Left><Left><Left><Left><Left><Left><Left>

then when I type YBK I will have

\left<
_\right>

where _ is the where the cursor stays. This is pretty much what I want except that vim automatically generates a line break before the cursor position, as what I want is

\left< _ \right>

So, how to avoid the nuisance of line break? thanks.

Upvotes: 1

Views: 215

Answers (1)

sehe
sehe

Reputation: 393114

look at surround.vim. I think you can extend it with your own 'open/close' pairs. It has this behaviour builting for several types of pairs already. Two examples to spark your interest:

  • vSC-] (wraps in { ... } with newlines around it and indenting according to the filetype indent settings

  • vSC-<paraEnter (wraps in <para> ... </para>), example:

.

the quick fox jumped over

(position cursor on the q in quick, press v2eSC-<paraEnter

Result:

the <para>
    quick fox
</para> jumped over
Edit

It appears that maybe you wanted this the other way around - without linebreaks. Well then, use vs<paraEnter or vS{ respectively, which by default don't insert linebreaks

Upvotes: 2

Related Questions