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

Tuesday, July 10, 2012

How to run two linux commands in one line?

Use && or || in the command

$cd dir && ls -al
$./ && 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