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.

____________________

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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s