sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #252: python script to align statements

 tip karma   Rating 1/1, Viewed by 1428 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   May 24, 2002 23:55      complexity:   intermediate
author:   Demian L. Neidetcher      as of Vim:   5.7

i know there's some awk scripts out there that do the same thing, and if i were a real trooper i would have
written this in vims internal language but...

i wrote a python script to align statements.

i put this in my .vimrc:
map L :!lineUp.py<cr>   " of course lineUp.py is somewhere in my path

and i have this python file somewhere in my path:
http://ophinity.com/res/dotFiles/lineUp.py

so now i can just pipe the offending lines thru my code:
:5, 10 !lineUp.py
or using the mapping above, visually select the lines and press 'L'

 rate this tip  Life Changing Helpful Unfulfilling 

<< c/c++: align #endif with corresponding #if/#ifdef | The power of | (v75|r- actually...) >>

Additional Notes

jmcpherson@softhome.net, May 28, 2002 12:56
This is a neat idea (and I do like Python), but why not use vimscript #176? It has more features and is native vim so you don't have the overhead of the Python interpreter.
demian 0311 at yah00 d0t c0m, June 2, 2002 13:46
i had trouble getting the other line-up thing to work, probably some issue between my chair and my keyboard.  i didn't feel like hunting down the problem so i just wrote it in python.

in an effort to prove to everyone how lazy i am, i wrote a couple other helpful code-wrangling python scripts that tie in nicely with vim, i have them pretty well documented at: http://www.ophinity.com/code/wrangling/index.html ...the additional scripts provide for a simple templating mechanism for multiplying code (hey i coined a phrase) as well as some scripts to go back and forth between DB_SCHEMA_NAMING_CONVENTIONS and JavaNamingConventions.

anyone think i should post those as a tip?  script?
ekw@backgam.com, July 22, 2003 15:57
the www.ophinity.com URLs don't work.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo