noVIMber: Seeing the unseeable with VIM

This is why ninjas are scared of VIM – it allows you to see that which
cannot be seen.  This is a trick that I learned when editing a lot of
Python code in a massive project.  As you may or may not know,
in Python, whitespace is syntactically significant.  Indented lines are
used to indicate the bodies of functions, classes, and loops.  Problems
can arise when bothspaces and tabs are used for indentation, because
Python doesn’t necessarily consider eight spaces to be the equivalent
of two tabs, even though they may look the same to a human eye.

So when you have a file open in VIM and you want to view non-printing
characters, you can turn on list mode to see non-printing characters:

:se list

With list mode enabled, tabs will appear as ^I, carriage returns will
appear as ^M, etc.  To turn list mode off, type:

:se nolist

If you see a character and you’re not sure what it is, you can use
another couple of tricks to view the ASCII value of the character.  Put
your cursor on top of it and type:

ga

(Think “get ASCII”).  If you’re editing a UTF-8 file, the command is:

g8

Then you can look up the value at http://www.asciitable.com/ or
http://www.utf8-chartable.de/ to see what it is. (Unless you’ve memorized the ASCII and UTF-8 tables, in which case you’re probably an emacs user and not interested in these VIM tips anyway.)

Happy VIMming!

- David Roth

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • StumbleUpon
  • Technorati
  • Tumblr
  • TwitThis
  • Fark
  • FriendFeed
  • HackerNews
  • Posterous
  • Slashdot

About druzziel

Comments

  1. phatworm says:

    vim is way too powerful for the simple text editting that we needed to do every once in a while.

Bad Behavior has blocked 209 access attempts in the last 7 days.