Monday, January 08, 2007
Freezing titles ala spreadsheet land.
Every now and then I have to read the results of a SQL query on the command line, and I find the following setup to work wonders in VIM. At least this works well with MySQL, as its command line query tool is kind enough to spit out the output in tab-delineated form.
Say you have a query to perform. Do the following:
echo "select * from tableX;" | mysql -uUser -pPassword databaseName | vim +'set scb sbo+=hor sbo-=ver nowrap ts=30 bt=nofile| sp | exe "norm \<c-w>j\<c-w>_\<c-e>"' -
This will automatically space out the tabs so you can see each of the search result columns with the data, and then it creates two panes - one for the column descriptions, and one for the data. The scroll options are setup so that you can navigate around the data and always see the column description with the data (particularly helpful for large result sets).
The only real improvement I can think of is to use the VIM dbext plugin. I often find myself on several different machines I don't use often enough to warrant customizing plugins/settings, so this quick and dirty sql result browser setting is very handy to have around.