Useful Vim Mapping For duplicating word or character above the cursor

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.



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).


class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :microposts

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s