108 Keys and Some are Useful

I’m getting ready to attend the PowerShell Summit next week in Redmond, WA. Aside from my monthly visit to AZPOSH I haven’t had a lot of time to soak in all the new PowerShell goodness that I would like. I’m looking forward to getting the chance to learn from some really really smart people.

I haven’t been posting here lately and I didn’t realize it had been quite as long as it has. I often have moments where I think “I should blog that…”, and well it never gets very far out of the brain and onto the keyboard. So hopefully this will get the buckling springs going…

There are a couple of tricks on the shell console that I’ve found that come in handy when editing your command lines. Particularly longer one-liner style commands with many pipes, braces, and parenthesizes. We are all pretty familiar with the basics of the arrow keys, up and down navigate your command history. The left and right arrows move the cursor left and right within the command line.

You may or may not be familiar with the HOME and END keys. These take your cursor to the very beginning or the very end of the command line respectively. It is much easier to get back to the beginning of a long command with a press of the HOME key then holding down the left arrow. Its just as easy to get back to the end with a touch of the END key.

Whereas left and right arrows alone move you character by character along your command line using these arrow keys with the CTRL key pressed moves you “word” by “word”. In this case a word is anything separated by a space. So “Get-Item”, “C:\Windows\System32” are words and “|” is a word. Traversing your command line this way is much faster than mashing an arrow key and riding it to a location.

The CTRL key provides a modifier to the HOME and END key behavior as well. The CTRL and END keys pressed together will delete the contents of the command line from the position of your cursor to the end of the line. Similarly the CTRL and HOME keys will delete the contents from the cursor to the beginning of the line. Both are helpful when making significant edits to a command line pulled up from your history before re-executing it.

These tricks and the “no loss” tab completion functionality of PowerShell 3.0 have made working in the shell console a very productive experience for me. Do you use any additional keyboard short-cuts to increase productivity within your console?



One response to “108 Keys and Some are Useful

  1. I would like it if ISE incorporated an Emacs editing mode or PowerShell prompt came with a modified Vi for syntax highlighting. The home and arrow keys are like 2″ away from “asdf” and “jkl;”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s