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.

Mac OSX Tips

  • Opening a file using KEYBOARD in finder: command+o

When searching a file in Finder, it’s very intuitive for me to just press enter ( I used windows previously), but it will go into the rename mode instead of launching. So command+o is the correct key.

  • Deleting a file using the delete button: command+delete, if u’re using an external Mac keyboard, note that there’re 2 delete buttons, try another one if it didn’t work.
  • Switching between windows of the same application: command + `

Git Checkout

I just want to record down the 2 common usages of git checkout so that I don’t need to refer again next time!

git checkout — <filename>

  • this will overwrite your file with the name <filename> in your working directory with the <filename> from the staging area.

git checkout -f

  • replace all the files in the working directory with files from HEAD
  • clear the staging area to match with HEAD

Git Reset

I always forget about what does git reset do exactly after not using it for a while. So I decided to write it down with diagrams. Below is the usage of git reset with different arguments:

git reset <commit>

  • update HEAD+master to point to <commit> (if HEAD is attached to master)
  • update index to match <commit>
  • working directory(WD) untouched

git reset –soft <commit>

git reset –hard <commit>

git reset — <filename> or git reset HEAD — filename

  • unstage the file name <filename>, in other words, if it is a tracked file, it will revert index’s <filename> to HEAD’s <filename>; if it is not a tracked file, it will simply unstage it.

git reset <commit> — <filename>

  • work the same as the above git reset — <filename>, but instead of updating with HEAD’s <filename>, it updates with <commit>‘s <filename>.