VB 2005 Snippet Annoyance - A solution...
With VB’s snippet feature, every time you add a new snippet the coloring stays around until you close the file and re-open it. This can quickly lead to a lot of visual clutter while your developing if you use snippets a lot. And why shouldn’t you leverage such a feature?
Well, during the beta I asked about whether this would be resolved in some manner and it was a bit late in the schedule. So I set out to figure out a possible work around. The work around consists of a simple macro that will save your current cursor location, save/close the file, open the file and return the cursor to it’s current location. You can configure the macro to work as a tool bar button and/or a keyboard combination.
Here’s what I’m referring to (visually):
Here’s the macro.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Sub ReloadFile()
' Make a note of the current file.
Dim file As String = DTE.ActiveDocument.FullName
' Make a note of the current cursor position.
Dim ep As EditPoint = CType(DTE.ActiveDocument.Selection, TextSelection).ActivePoint.CreateEditPoint
' Save the current file.
DTE.ActiveDocument.Save()
' Close the current file.
DTE.ActiveDocument.Close()
' Open the current file.
DTE.ItemOperations.OpenFile(file)
' Move cursor to the previously saved position.
CType(DTE.ActiveDocument.Selection, TextSelection).MoveToLineAndOffset(ep.Line, ep.LineCharOffset)
End Sub
Enjoy!
Note: For a step by step walk through on creating and consuming macros, see here.