Calling an external tool from Visual Studio

I recently helped someone who wanted to open an external editor from Visual Studio. Below are the steps I suggested to map a keyboard shortcut to open Notepad++ to the same line/column cursor position as the Visual Studio editor was at.

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.