Jan 15

Quick vi tip: Show Hidden Characters

posted in unix/linux, vi on 01/15/08 at 12:01 PM

I do a lot of development in linux/unix. In fact, that’s where all my development is, but I spend a fair amount of time in the “CLI” or command line interface. I use putty and ssh in to edit files and look at logs and just generally do what I do.

Today I ran into a problem with a file and I couldn’t figure out what was wrong. I kept getting an error and the spacing was off so I started suspecting a hidden character. vi, the command line editor I use in linux can show you hidden characters. Just type:

:set list

And bingo, hidden characters are revealed.

Turning them back off is just as easy:

:set nolist

Write that down, it comes in handy.

Updated 2/25/10: Thanks to Stephen in the comments, I’ve updated the above commands. I had the : in the wrong place!

7 Responses to “Quick vi tip: Show Hidden Characters”

1 Greg Bergeson Says:

Thanks for this info on vi. I didn’t want to drag out the books and figure out which option it was again! I really needed this for file conversion between Mac OS and Windows OS (the infamous carriage return versus line feed issue). Thanks again!

2 shannon Says:

Hey this was potentially one of the most intelligent articles I have view on the topic so far. I don’t know where you gather up all your data but up! I’m going to send a few individuals to this site to take a look at this post. Awesome, totally fantastic. I am just getting into writing articles myself, nothing remotely close to your writing potential (lol) but I’d love for you to check out my article someday! bowfelx series 7 treadmill

3 Stephen Says:

You don’t need to post my response. I think you meant “:set list” and “:set nolist” instead of “set: list”. I got an error when I typed “set: list” and “:set: list”. Thought yuo might want to know so you can fix your post and save others the headache of figuring it out.

This post was very helpful never the less. Thanks!

4 Chrispian Says:

Stephen, so right! Totally typo’d that. Updating it now.

5 jasmin live Says:

Aw, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done

6 Eric Says:

Once you find the characters you want to remove you can use:
:%s///g to remove everything globally. The way to type those pesky special characters in vi (ie ^M) is to use ctrl-v then ctrl-m You then substitute the m for whatever letter you need.

Hope that helps!

7 Eric Says:

Sorry the posting left out some of my characters. A sample of the above technique would be :%s/^M//g

Sorry for the mixup!

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution. I reserve the right to delete any comment for any reason with and will aggressively smite spam, flames and unsavory behavior.