Reputation: 4283
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?
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
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:
Upvotes: 4
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...
Remember the position of this command, 3 in this case.
Create a keyboard shortcut to "command3"
tools | Options | Keyboard
and search for externalcommand
Assign your desired key combination to this command ctrl-shift-alt L
for example.
Verify your command is as expected on the Tools menu
Now put it all into action
ctrl-shift-alt L
Notepad++ opens up the file on the line and column for the search result!
What's left?
pause
out of the cmd file as it was used just for debugging purposes.-multiInst -nosession
argumentsConclusion
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
Reputation: 29431
Using $(ItemPath) -n$(CurLine)
as arguments did the work for me:
Upvotes: 7