Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 

NewNoteFromSelection-VSCode

Creates a new markdown file with selected text and replaces original text with link to new file

  1. Install Macros extension

  2. Install FileUtils extension

    Note: They're pretty useful tools to have, so its not a complete "waste" to install them just for this task.

  3. Open your User settings by pressing Ctrl+Shift+P and tpying "Open Settings (JSON)" or locating settings.json at the following paths

    • Windows %APPDATA%\Code\User\settings.json
    • MacOS $HOME/Library/Application Support/Code/User/settings.json
    • Linux $HOME/.config/Code/User/settings.json
  4. Add the following code to the bottom of the file:

    "macros.list": {
            //if you are having trouble with the formatting, you can make this delay slower (1000 is 1 second). Just depends on the speed/load of your processor.
            "updateNote": [
                //if you are having trouble with the formatting, you can make this delay slower (1000 is 1 second)
                {
                    "command": "$delay",
                    "args": {
                        "delay": 500
                    }
                },
                "workbench.action.files.save",
                "editor.action.insertLineAfter",
                "editor.action.insertLineAfter",
                "editor.action.clipboardPasteAction",
                "cursorTop",
                "fileutils.copyFileName",
                "editor.action.clipboardPasteAction",
                "deleteLeft",
                "deleteLeft",
                "deleteLeft", 
                "cursorHomeSelect",
                "editor.action.clipboardCopyAction",
                "cursorTop",
                {"command": "type", "args": {"text": "# " }},
                "workbench.action.files.save",
                "workbench.action.closeActiveEditor",
                //"workbench.action.navigateBack",
                "deleteRight",
                {"command": "type", "args": {"text": "- [[" }},
                "editor.action.clipboardPasteAction",                 
            ],
    
            "copySelection": [
                "editor.action.clipboardCopyAction"
            ],         
        },
    
  5. Open the user tasks file by entering Ctrl+Shift+P -> "Tasks: Open User Tasks". This file can also be found (or created) at the same user settings folder paths mentioned in step 3.

  6. Insert the following code into the file. If you don't have any existing tasks, you can replace the entire code. NOTE: This is set to use Windows Powershell. You might have to modify the code, especially in the "newNote" section, if you are using a different system

        {
        "version": "2.0.0",
        "tasks": [
          {
            "label": "newNote",
            "type": "shell",
            "command": "echo '' > -encoding UTF8 '${input:fileName}.md' | code '${input:fileName}.md'", 
            "presentation": {
              "reveal": "silent",
              "clear": true,
            },
          },
          {
            "label": "copyText",
            "type": "shell",
            "command": "${command:macros.copySelection}",  
            "presentation": {
              "reveal": "silent",
              "clear": true,
            }, 
          },
          {
            "label": "newNoteFromSelection",
            "type": "shell",
            "command": "${command:macros.updateNote}",
            "dependsOrder": "sequence",
            "dependsOn": ["copyText","newNote"]
            "presentation": {
              "reveal": "silent",
              "clear": true,
            },
          }
        ],
    
        "inputs": [
          /* {
            "type": "promptString",     
            "id": "folderName",
            "description": "Complete my folder name.",
            "default": "folder"
          }, */
          {
            "type": "promptString",
            "id": "fileName",
            "description": "New file name for selected texte",
            "default": "new file name",
            "presentation": {
              "reveal": "silent",
              "clear": true,
            },
          }
        ]
      }
    
  7. Open the user Keybindings file, by either entering Ctrl+Shift+P -> "Preferences: Open Keyboard Shortcuts (JSON) or opening this file from the same directory listed in Step 3.

  8. At the bottom, add the following code and customize the keyboard shortcut to your preference.

    {
      "key": "ctrl+alt+shift+n",    // whatever you choose
      "command": "workbench.action.tasks.runTask",
      "args": "newNoteFromSelection"
    },
    
    
  9. Open the markdown file with the text that you would like to extract.

  10. Select text.

  11. Use the keyboard shortcut that you just set.

  12. Enter a title in the Input Box. If it has multiple words in it, you might consider adding "-" between each word in case it helps with links. However your links and graph node labels will have "-" in them.

    This would also be a very good place for someone to improve the code with some sort of Regex find/replace for "-","_", etc...

  13. Wait for macro to run. It should take a few seconds.

  14. If you are unsatisfied with the results, you can undo it all by pressing Ctrl+Z.

  15. If the formatting is all out of order, look in the settings.json file and increase the delay.

About

Creates a new markdown file with selected text and replaces original text with link to new file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published