Updated: I found out that Ctrl+y in the insert mode can duplicate whatever’s above the cursor. So there’s no need to use the mapping at all.
____________________
Outdated:
imap <F1> @<Esc>kyWjPA<BS>
nmap <F1> @<Esc>kyWjPA<BS>
imap <F2> @<Esc>kvyjPA<BS>
nmap <F2> @<Esc>kvyjPA<BS>
The following mapping can help to copy the word or character above the cursor and paste it at the current cursor position by pressing F1(for word) or F2(for single character).
Example:
class User < ActiveRecord::Base attr_accessible :email, :name has_many :microposts ^ end
If my cursor is at the ^ location, and I want to duplicate has_many above the cursor into the current position, I press F1. Pressing F2 can duplicate h, pressing F2 again and again will duplicate a, s, _, m…etc.