Dienstag, 12. April 2011

Vim 005: Efficient formatting

The following example demonstrates how to format a run control file efficiently. The initial PYTHONPATH in the file is

export PYTHONPATH=$HOME/shellscripts:$HOME/tree/lib64/python2.4/site-packages:$HOME/kemibin/2010/woche_03/wave/

and it is difficult to read. It would be nice to have all directories added to the path on separate lines. In Vim, this can be done by issueing:

:s/:\$/:\rexport PYTHONPATH=\$PYTHONPATH:\$/g

\r is the line feed character (apparently it works on Linux, even if its the Windows line feed character). The common Unix linefeed character is \n. \$ escapes the dollar sign so it can be found and replaced/inserted (it would be considered the end of the line if not escaped). Calling the command returns

export PYTHONPATH=$HOME/shellscripts:
export PYTHONPATH=$PYTHONPATH:$HOME/tree/lib64/python2.4/site-packages:
export PYTHONPATH=$PYTHONPATH:$HOME/kemibin/2010/woche_03/wave/

There remains a colon on all but the last lines. Replacing this would require the command to recognize if it is operating on a line which is not the last one of the selection.

Keine Kommentare:

Kommentar veröffentlichen