Search code examples
jsonvisual-studio-codekey-bindings

using regex inside keybindings.json


I want to use regex inside of the text in args,

{
    "key": "ctrl+shift+r",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text":'${file}.'\u000D"  } 
}

I want to take the name of the file from the file path using this regex - ^\\(.+\\)*(.+)\.(.+)$ or taking the filename in other way, anyone can help?:)


Solution

  • You do not need to use a regexp, you want to use a different variable:

    {
      "key": "ctrl+shift+r",
      "command": "workbench.action.terminal.sendSequence",
      "args": { "text": "'${fileBasename}'"  } 
    }
    

    See Variables Reference.