I want to create a key binding that insert a piece of text in the code, for example “hi”.
I tried adding this to my .vimrc file:
map gp :hi
but it doesnt work..
Any idea?
Javi
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are three approaches shown in this answer for inserting text with shortcuts. The first one is for mapping in normal mode, the second inserting abbreviations in insert mode, and the third for abbreviations in command mode.
Additionally, you can take a look to plugins like
snipmate1. Insert text from normal mode and return to normal
:nnoremap gp iHi<Esc>2. Change ‘hi’ to ‘hello’ and keep in insert mode
Abbreviations in insert mode are:
:iab hi Hello(test it typing hi followed by spacebar)if you like to insert a month list:
:iab mOn Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Decif you want a shortcut for including stdio.h
:iab inC #include <stdio.h>3. Abbreviations in command mode
:ab hi HelloA practical example, using e.g.
wsufor saving the current file with superuser credentials.:ab wsu w !sudo tee %