Wednesday, July 11, 2012

How to view the file path of currently opened file in Vim?

File name is stored in the register %. To retrieve it, in vi command mode type:
:echo @%
Above will display the relative path from the present working directory.  To get the absolute path type:
:echo expand('%:p')
Ref:
http://vim.wikia.com/wiki/Get_the_name_of_the_current_file

Tuesday, July 10, 2012

How to run two linux commands in one line?

Use && or || in the command

examples:
$cd dir && ls -al
$./startup.sh && tail -f ../logs/catalina.out
&& doesn't run the second command if the first doesn't complete successfully
|| runs both commands

What are the commands commonly used with Vimdiff?

[c = Previous Change
]c = Next Change

zo = Open fold
zc = Close fold

zr = Expand all
zm = Collapse all

do = Get changes of other window to the current window
dp =  Put change of the current window in the other window

:diffupdate :diffu = Recalculate the diff.

Ctrl+w, Ctrl+w = Switch cursor to other window

Ref:
http://stackoverflow.com/questions/5288875/vimdiff-what-are-the-most-frequently-used-commands-shortcuts-that-could-get-a-n