0

I want to achieve the following: when inserting text inside a certain app, after pressing a shortcut, bring up a VSCode window with LaTeX as the language (and open a default file), edit text there, and when closing that window, copy the entire text I just input without saving. The first part (listening to keystroke events) is done via hammerspoon (since I'm using macOS), and I don't really know what to do with the latter parts.

More specifically, I'm trying to implement the adding text functionality from this post. There, the author used a python script to listen to keystroke events, and when a t is pressed, a default vim window is brought up, and certain snippets can be used when creating texts. I have already recreated the snippets part in VSCode, so having the ability to bring up such a window in VSCode will be a huge help whenever I'm trying to typeset LaTeX formulas.

1 Answer 1

0

To get VS Code to open a new file on startup (when you don't command it to open a specific folder):

"workbench.startupEditor": "newUntitledFile"

To change the default language of new files, use the files.defaultLanguage setting.

If you don't want these settings to be intrusive to your other use-cases for VS Code, I'd suggest you create a workspace folder dedicated for this use-case and put these settings in the workspace settings.json file. You can open VS Code to specific folders like code <folder path>.

Then, to use https://github.com/ryuta46/vscode-multi-command with the editor.action.selectAll, editor.action.clipboardCutAction, and workbench.action.closeWindow commands. See the extension docs and Visual Studio Code keybindings - Running two or more commands with one shortcut for exact usage details. Or, in VS Code 1.77, use the runCommands command.

4
  • I would like to open a default LaTeX file, like default.tex with everything empty. Is that possible? Since my snippets are defined specifically for .tex files.
    – pbb
    Commented Mar 3, 2023 at 19:23
  • So in this case, whenever I open a new VSCode window, it'll be some sort of default.tex file. Is that possible to config such that this only happens with a certain command? LIke I would like to keep the default behavior as much as possible while only open such default file when I need.
    – pbb
    Commented Mar 3, 2023 at 19:27
  • @pbb at that point, I'd suggest creating a folder dedicated for this use-case, and set these settings in the workspace settings.json file instead of user settings.json file. Seems like there's no such thing as a workspace keybindings.json file though- only user keybindings.json. You can open VS Code to a specific folder via commandline with code <folder path>.
    – starball
    Commented Mar 3, 2023 at 19:29
  • Actually, my problem is not precise since what I really want is the pop-up window, not the whole open workspace (it'll be too chunky to input a one-line text). I have opened a new problem, appreciate your help, though.
    – pbb
    Commented Mar 3, 2023 at 20:42

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