0

I use both Notepad++ and VS Code, and for easy switching between the two, I have set up a Run command in Notepad++ to start VS Code with the current file, and caret position:

code -g $(FULL_CURRENT_PATH):$(CURRENT_LINE):$(CURRENT_COLUMN)

However, the values for line and column are off by 1, so if in Notepad++ I am on line 2, column 4, I find myself at line 1 column 3 in VS Code.

Apart from writing an intermediate script that adds 1 to both values, is there a way to fix this?

1 Answer 1

1

CMD can't really do arithmetic in one line, so I would use powershell. This command works for me, though it's not much different than writing up a script at this point. I've added line breaks for readability, but it is a one-liner for NP++ Run:

powershell -command $FILE="""$(FULL_CURRENT_PATH)""";
$LINE=$(CURRENT_LINE)+1;
$COLUMN=$(CURRENT_COLUMN)+1;
$command = """code -g `"""${FILE}:${LINE}:${COLUMN}`""" """;
Invoke-Expression -command $command

Triple quotes since notepad launches programs using Run, and variable names in ${foo} format due to colon characters.

2
  • Thanks, but I asked for something other than a script.
    – Berend
    Commented Jul 12, 2023 at 19:54
  • @Berend it's still a single NP++ run command like you have in your question. Neither VS Code nor NPP have an option to change their line/character indexes, though both have github issues requesting it
    – Cpt.Whale
    Commented Jul 12, 2023 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .