Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There is a similar command that I use to open the currently selected word on command prompt:

cmd /D "%windir%/system32" /K ""$(CURRENT_WORD)""

Is there any command for opening the current line without selecting any text on that line manually?

share|improve this question
add comment

1 Answer

Neither How to Run an external program from Notepad++ nor the documentation of the plugin NppExec mention a environment variable containing the current line.

Likewise, macros can only action Scintilla messages (list), search and replace recordings and some Notepad++ defined commands (undocumented?), so there's no way to achieve this with macros.

Aside from writing your own plugin, to only way I know how to do this is using an external program. An AutoHotkey script will do what you want.

AutoHotkey script:

WinGetActiveTitle, Title
if RegExMatch(Title, "- Notepad\+\+$")
    SendPlay {Home}+{End}{F5}
    SendPlay cmd /D "%windir%/system32" /K "$(CURRENT_WORD)"
    SendPlay {Enter}
    SendPlay ^{F5}

What it does:

  • If Notepad++ is the active window, the key combination Ctrl + F5 will select the current line and execute the external command

    cmd /D "%windir%/system32" /K ""$(CURRENT_WORD)""

    $(CURRENT_WORD) now contains the whole line, since it was selected. The only drawback is that you will lose the current cursor position, as the script will leave the current line selected.

  • If Notepad++ is not the active window, the key combination Ctrl + F5 will behave normally.

How to use:

  1. Download and install the latest version.

  2. Save the above script as npp_runline.ahk, using your favorite text editor.

  3. Double-click the file to run the script.

  4. If you wish, copy the script (or a link to it) in the Startup folder.

How it works:

  • ^F5:: specifies the used hotkey (Ctrl + F5).

  • WinGetActiveTitle, Title stores the title of the active window in the variable Title.

  • RegExMatch(Title, "- Notepad\+\+$") returns the position of the leftmost occurrence of the regular expression - Notepad\+\+$ (where \+ is a literal + and $ in the end of the string) in Title, or zero if there is no match.

    • If there is a match, the block follwing if... gets executed:

      • SendPlay {Home}+{End}{F5} simulates pressing Home and Shift + End (selecting the current line without leading whitespace) and then F5 (opening the Run... dialogue).

      • SendPlay cmd /D "%windir%/system32" /K "$(CURRENT_WORD)" enters just that in the Run... dialogue.

      • SendPlay {Enter} simulates pressing Enter (finalizing the Run... dialogue).

    • If there is no match, the block following else gets executed:

      • SendPlay ^{F5} simulates pressing Ctrl + F5 (fallback if we need the shortcut outside of Notepad++).
  • return terminates the execution of the script at the current point.

See also:

share|improve this answer
Sorry but that just gives me the line number. What i need are the contents from that line. –  TMRW May 21 '12 at 19:34
As per this topic: superuser.com/questions/424559/… i figured i could do HOME, HOME, SHIFT+END and then run Open in CMD via shortcut key (in my case CTRL+SHIFT+C) and put all this in the macro and the macro in context menu. Unfortunately it did not work for some reason. The text on the current line becomes selected but never opens in CMD window... –  TMRW May 21 '12 at 19:37
I missed the word number. The updated answer is tested and should work. –  Dennis May 22 '12 at 2:55
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.