A Django site.
July 14, 2008
» Use Vim As A Syntax Highlighting Pager

It has been some time since I’ve done a Vim Tip of the Week, but I came across something today that I thought I would share.  This tip will allow you to use Vim, with all its syntax highlighting glory, as a pager (similar to less or more).

If you use cat or less or more regularly to quickly view files, but you’d like to keep the same syntax highlighting that you’d get in Vim you can use an included config that makes Vim act as a pager.  Setup the following within your .bashrc file, or wherever you keep your shell aliases:

alias vless='vim -u /usr/share/vim/vim71/macros/less.vim'

You’ll then need to re-read that file, which can be done using:

. .bashrc

At this point you can use vless to view a file, which will use the beloved syntax highlighting.  Normal pager shortcuts should work.  q to quit, / to search, pg-up, pg-dn, etc.

Random Posts

June 17, 2008

Dennis Muhlestein
nonic
All My Brain
» Formatting Source Code with Wordpress

Sometimes you get used to doing things one way and you forget to take a step back now and then and see if there isn't something you're missing. In my case, I was formatting source code on this blog by putting html non-breaking spaces and < codes for angle brackets etc. Ouch. [...]

March 29, 2008

Hans Fugal
no nic
The Fugue :
» sh.vim

Have you ever been frustrated with perfectly valid bash syntax being highlighted as incorrect in vim? Like this:


#!/bin/sh
foo=$(ls /tmp)

$() is a perfectly valid, nay preferred substitute for backticks. The problem is that vim is deciding this is pure old bourne shell instead of whatever else we'd like it to be. If you change the shebang to #!/bin/bash and re-edit the file, then the error markings go away. But maybe you're writing for the nebulous POSIX shell, not bash nor sh. Or maybe you just don't care and you don't want vim complaining that you're using bashisms even though your shebang says sh. You can set the defaults so that it reflects your system and preferences. It's all there in :help sh.vim.