BeyelerStudios
BeyelerStudios

Reputation: 4283

Change or Add a Default Editor in Visual Studio

I'd like to add a new (external) default editor for a file type in Visual Studio 2012. My editor (Notepad++) supports jumping directly to a specific line via programme arguments. Sadly the msdn reference doesn't mention any macro parameters to use the line (and character) offset in a given context (i.e. when double clicking a search result).

Is it possible to get the line and/or character offset in the Arguments field in Add Program?

AddProgrammeDialog

Edit: Is there a way to access these open-events through extensions with information about the file, line and the chosen opening programme?

Upvotes: 15

Views: 4660

Answers (3)

gReX
gReX

Reputation: 1080

It is not possible by default, because there are no Arguments reflecting the Search-Result. So you have first open the File inside VisualStudio and then with external Tool.

I think you could create a custom Visual-Studio Plugin and hook inside the selection of your search-Results. Look at Adding Search to a Tool Window available for VS 2015, 2013 and 2012. Some Implementation this way seems to be Quick Open File Plugin for VS2010 but a textbox to enter the linenumber is missing.

More Documentation to create VS Plugins on MSDN

Btw, have you Checked the "Promt for arguments" Option to extend Thomas answer:

External Tools VS Dialog

Upvotes: 4

Kory Gill
Kory Gill

Reputation: 7153

You can get a solution to this that takes 2 steps, both of which take little time once you have your search results. Double-click the result, press ctrl-shift-alt-L (can be changed of course).

The steps below are verbose to show as much as possible so everyone can understand the steps and modify accordingly.

Create a cmd file that will launch notepad++ with file, line, and column arguments

Save the code below in d:\util\startnppwith3args.cmd

setlocal
set _file=%0
set _line=%1
set _column=%2
set _line=%_line:"=%
set _column=%_column:"=%
: remember to use "" as first arg as blank title so we call npp properly :)
start "" "F:\Program Files (x86)\Notepad++\notepad++.exe" -multiInst -nosession -n%_line% -c%_column% %_file%
pause
endlocal

Create external tool to call startnppwith3args.cmd

tools | External Tools...

enter image description here

Remember the position of this command, 3 in this case.

Create a keyboard shortcut to "command3"

tools | Options | Keyboard and search for externalcommand

enter image description here

Assign your desired key combination to this command ctrl-shift-alt L for example.

Verify your command is as expected on the Tools menu

enter image description here

Now put it all into action

  • Open a file in Visual Studio
  • Search for something in the file
  • Double-click desired search result
  • Press ctrl-shift-alt L

Notepad++ opens up the file on the line and column for the search result!

enter image description here

What's left?

  • Take the pause out of the cmd file as it was used just for debugging purposes.
  • decide if you want -multiInst -nosession arguments
  • Take a look at Arguments for External Tools for all variables that are assigned when you launch an external tool.

Conclusion

This was in interesting question, and an area I had not explored before. I might use this technique myself and for other purposes.

Upvotes: 1

Thomas Ayoub
Thomas Ayoub

Reputation: 29431

Using $(ItemPath) -n$(CurLine) as arguments did the work for me:

enter image description here

Upvotes: 7

Related Questions