keyboard

Text Editors — Back to Vim!

Being the keyboard kind of guy that I am, I’ve totally gotten back into the Vim editor. I had used it years ago, and discovered it again recently when I was looking for a text editor for some Ruby code I was writing.

It’s one of those power tools that most people, myself included, really didn’t like very much the first time you use it. But then you achieve a certain level of proficiency and you can slice and dice any text you have to edit so quickly that you become very spoiled.

I also have switched to using a black background. I found a great dark color scheme for Vim called Moria, that I would highly recommend. It’s a very readable, easy on the eyes scheme, that just seems right to me. I’ve posted an image of my setup using the abbrev.rb file from Ruby 1.8.5.

If you like using keyboard shortcuts, you owe it to yourself to try the Vim text editor. It does take some time to get used to a modal editor, but if you are going to be editing lots of text, it’s time well spent.

I still really like the text editor built into Visual Studio and will continue to post any tips and keyboard shortcuts that I find useful there too.

Vim Color Scheme

keyboard
tools
ruby
programming

Comments (2)

Permalink

Visual Studio Keyboard Tip #7 - Incremental Search

The Visual Studio editor has a very useful incremental search feature built in. Let’s try it out.

  • Create a new Windows Application project.
  • Open up the Form1.Designer.cs file in the editor.
  • CTRL + I (this activates Incremental search mode)
  • Type: “disp” (without the quotes)
  • The selection should have moved to the first match of “disp” in the file.
  • Type CTRL + I again. This moves you to the next match.
  • CTRL + SHIFT + I moves you to the previous match.
  • BACKSPACE removes the last character from the search string.
  • ESC cancels incremental search mode.

visual studio
keyboard
c#
.net

Comments (0)

Permalink

Visual Studio Keyboard Tip #6 - Find Window Command Line

There’s a great feature hidden in the Find Window Combo Box that is part of the standard Toolbar in Visual Studio.

  1. Open Visual Studio
  2. CTRL + N (Create a new file) choose “HTML Page”
  3. Position the cursor on the tag
  4. Press CTRL + /
  5. The focus should have shifted to the Find Combo Box
  6. Type >
  7. Now type E
  8. Cool! It’s a command line with built in Intellisense.
  9. Type dit.LineT
  10. The entry for Edit.LineTranspose should be selected
  11. Press enter

You’ll notice that the and tags are now transposed. Take a few minutes to look around at what commands are available in this list. You can browse the list by entering one letter at a time. For example “>a” to see all the items that begin with a.
This is a great way to quickly execute commands that aren’t mapped to convenient keyboard shortcuts.

visual studio
keyboard
programming

Comments (0)

Permalink

Visual Studio Keyboard Tip #5 - Code Snippets

When I first saw code snippets in the Eclipse IDE a few years ago, I thought it was a great feature. It’s nice to see it included in Visual Studio 2005.

Let’s take a quick tour.

  1. Open up visual studio, and go to any C# code editor window.
  2. Position the cursor inside a method and enter CTRL + SPACE

Code Snippet Dropdown

In the dropdown that appears, look at the icon next to the #if or #region — that icon indicates the entry is a code snippet. Ok, next step:

  1. Type for
  2. This should set the selected index of the dropdown to the entry for.
  3. While for is selected enter TAB, then TAB again.

You should see this:

For Code Snippet

The caret is positioned on the i. Type the following word - index. Then hit TAB. You should see that all instances of i are replaced with index. Pretty cool.

Even better, all code snippets are defined in an xml format that you can edit.

  1. Enter the following keys CTRL + K, CTRL + B. This should bring up the code snippet manager.
  2. Expand the Visual C# node, then select for, in the location label right between the Language dropdown and the treeview gives you the location of the xml for the code snippet.
  3. Select and copy the path, then enter CTRL + 0 (that’s not a zero), and paste it into the filename, hit enter, and now you’ll see the xml for the code snippet.

This post on the VSEditor blog provides some details on the schema used to create a code snippet file.

I hope you are enjoying this series of visual studio keyboard tips. If you have any editor/keyboard topics that you would like to see, please feel free to comment on this blog and I’ll try and create a new post covering it. Thanks for reading!

visual studio
keyboard
c#

Comments (0)

Permalink

Visual Studio Keyboard Tip #4 - Outlining

Wouldn’t it be great if you had the ability to make all the other code in the text editor disappear, so that you could just focus on the one method you are working on?

That would be really cool. Unfortunately I have no idea how to do that. But I can show you the next closest thing….outlining!

Open up Visual Studio 2005, and create a brand new Windows Application Project.
Expand the Form1.cs file in the Solution Explorer, and open up the Form1.Designer.cs file.

You’ll see there is some grey text at the bottom of the screen “Windows Form Designer generated code.” Hmm, let’s see what type of code was generated.

CTRL + M, then CTRL + P

You should see that the whole file is now visible — all outlining has been removed. Cool. Next let’s collapse the whole file down.

CTRL + M, then CTRL + O

That’s a letter O by the way. Now you should see a very clean higher level view of what’s contained in the file. Next to each region you’ll see a + that you can use to expand the region. Don’t reach for the mouse yet. Since this is a keyboard tip, we should really review the keyboard shortcut to expand and collapse a region.

Move to line 23 (CTRL + G, then enter 23). You should be on the “Windows Form Designer generated code.”

CTRL + M, then CTRL + M

That region should have expanded. Now move to line 29 (CTRL + G, then enter 29). You should now be on the InitializeComponent method.

CTRL + M, then CTRL + M

The region expands. If you enter the same keyboard combinations again, the region collapses.

One last tip. Let’s expand the whole document again.

CTRL + M, then CTRL + P

Move to line 32 (CTRL + G, then enter 32). Select the text on line 32 and 33.

CTRL + M, then CTRL + H

Pretty cool, huh? Those two selected lines have now been collapsed inside the method down to an ellipsis. This only works in C#, there is no other outlining being done in the whole file, and text is selected.

visual studio
keyboard

Comments (0)

Permalink

Visual Studio HTML Editor Navigation

If you code ASP.NET websites, you need to read Scott Guthrie’s Blog.

In this post Scott demonstrates a great feature of the HTML editor in Visual Studio. When you switch from design to source view the editor keeps the same position.

For example if you select some text that appears in the design view, then switch to source view the selection will automatically be set to the same text.

This feature can help save lots of scanning around an html file.

visual studio
keyboard

Comments (0)

Permalink

Visual Studio Keyboard Tip #3 - Formatting

To automatically format your code in Visual Studio 2005 use the following keyboard shortcuts:

Format Document: CTRL + E, then D
Format Selection: CTRL + E, then F

If you have any syntax errors in your code then the formatting features do not seem to work. So, if you are trying to use the keyboard shortcuts to format a document and it doesn’t seem to be working, then check your code.

The formatting engine is great. You are also able to customize what the format style you want to use for each language you work with. Go to the Tools menu, click Options. Select Text Editor, then the language, for example C#. Expand the node in the tree (C# in this case) and you’ll see either a Format or Formatting child node. Once you select that you’ll see the options available to you.

visual studio
keyboard

Comments (1)

Permalink

Visual Studio Keyboard Tip #2 - Bookmarks

Bookmarks are one of the features of Visual Studio that if you are currently using them take the time to read this tip, they really are that cool.

The keyboard shortcuts to utilize the bookmark feature makes use of “chords”, which are a repeated sequence of keys, the first to select the group of actions and the second to perform the action.

  1. Open a new text file in visual studio.
  2. On the first line type “Here is some code”.
  3. Enter CTRL + K then CTRL + K again. You should now see a bookmark indicator in the left margin of the line.
  4. Hit enter a few times.
  5. Then type “Here is some more code.”. Now create another bookmark by pressing CTRL + K, then CTRL + K again.
  6. Press CTRL + K, then CTRL + N. You should now see that you have navigated to the first bookmark. Enter CTRL + K, then CTRL + N again. You’ll cycle through the bookmarks you have set. Pretty cool, huh?
  7. But wait, you say! Now I have these little blue things in the left margin of my code, how do I get rid of them. Pretty easily, you can remove bookmarks just the way you set them. Position the caret on the line of the bookmark you want to remove and press CTRL + K, then CTRL + K again.

I have found bookmarks to be incredibly useful when coding and hope you do to. In Visual Studio 2005 there are new keyboard shortcuts for bookmarks, although the old ones work as well:

Toggle Bookmark: CTRL + B, then T
Next Bookmark: CTRL + B, then N

visual studio
keyboard

Comments (0)

Permalink

Visual Studio Keyboard Tip #1 - Delete Line

From any position on a line you can delete it by pressing:

CTRL + L

This deletes the entire line and positions the caret at the beginning of the line.

visual studio
keyboard

Comments (1)

Permalink