Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add vim keymap

Tags:

vim

keymapping

While programming I am regulary using the following two lines:

sprintf(buff,"%s", __func__);

putrsUART(buff);

Is it possible to set any keyboard shortcut to insert these two lines? E.g. when I type \sp in command mode, these functions get added at the cursor position in my file. Is this possible? And if so, how do I map my keys?

Thanks in Advance.

like image 964
beparas Avatar asked Nov 22 '25 03:11

beparas


1 Answers

You can use abbreviations, which are designed for this.

:abbr spb sprintf(buff,"%s", __func__);
:abbr uart putrsUART(buff);

Use :help abbr for the gory details. Note that you need to type another character after the abbreviated form for vim to recognize them. This comes naturally for these as you will type ENTER as the next character. It is also possible to enter more than one line with abbreviations. Simply use <CR> where you want a new line.

like image 111
Jens Avatar answered Nov 24 '25 22:11

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!