Archive for the ‘Because I Forget’ Category

Running the script you are currently editing in vi

Tuesday, April 24th, 2012

Instead of doing all the typing involved with leaving your vi session to run the script you just edited, you could simply type

:!%

“%” is a shortcut for the current filename. For this to work, the current file (%) should be in your $PATH. Or if that’s inconvenient or unwise, you can always just make the call to the file’s absolute path by substituting % with the absolute path of the file. The file should be executable, which, if it isn’t, you change by typing

:!chmod +x %

Of course, if you have just created the file, you’ll need to do a :w to actually commit the file to the filesystem, before you can make any calls to it.

Remember to use

:!!

to repeat the last command you just ran from within vi to save yourself more typing.

VI Cheat Sheet

Monday, May 17th, 2010

Replace commas (or something) with line breaks (or something)

:%s/,/^M/g
where ^M = ctrl+V & ctrl+M

Use vi to comment out (or do something else to) several consecutive lines

Example: If you wanted to comment out lines 20 to 40 of a file, use the following:

:20,40s/^/# /

Use

:set number

to enable visible line numbers.

Problem with “terminal too wide” been plaguing you on those farty old Solaris boxes for the last 6.5 years but you were usually too busy doing something else to stop it from ever happening again?

Tuesday, May 11th, 2010

Well you can install VIM, or if that’s not practical (or if you’re not in the mood to install VIM and its required dependencies on the hundred or so boxes you log into), then the command “stty columns 120” will do ya.

Reset sound in Ubuntu (Linux) without restarting

Wednesday, October 28th, 2009

When messing around with lousy audio players like Amarok2, it sometimes happens that your sound system gets usurped by them when they crash (and boy do they ever crash a lot!).

The first thing to try is:

$ sudo /etc/init.d/alsa-utils restart

But that doesn’t always work, so you should see who’s holding on to your sound system:

$ lsof | grep pcm

kill the processes that still have open files one at a time until you get your sound back.

Register your nick on IRC

Wednesday, October 28th, 2009

# If you’ve never registered before (and if the server provides NickServ):
/msg nickserv register YOURPASSWORD YOUREMAIL

#Check your email for the confirmation, which should have something like this:

/msg NickServ VERIFY REGISTER YOURUID SOMECONFIRMATIONCODE

# Upon returning to the network:

/msg nickserv identify YOURPASSWORD

or possibly…

/nickserv identify YOURPASSWORD