Blog // Keyboard Shortcut for Selecting Next and Previous Occurrences in Visual Studio Code

By Destin Moulton on March 22, 2017

    I have been using Visual Studio Code for a few months now and I love it. I have been integrating many of the IDE features into my old-school emacs workflow. For some reason my "Selection >> Add Next/Previous Occurrence" wasn't bound to a keyboard shortcut. I couldn't find any mention of "occurrence" in the default keymap file. After a bit of digging I uncovered the command names.

    The commands are:

    • Selection >> Add Next Occurrence
      • editor.action.addSelectionToNextFindMatch
    • Selection >> Add Previous Occurrence
      • editor.action.addSelectionToPreviousFindMatch.

    Here is the snippet from my keybindings.json:

    // Selection >> Add Next Occurrence 
    {   
        "key": "ctrl+alt+n",            
        "command": "editor.action.addSelectionToNextFindMatch",
        "when": "editorFocus" 
    },
    // Selection >> Add Previous Occurrence
    {   
        "key": "ctrl+alt+p",            
        "command": "editor.action.addSelectionToPreviousFindMatch",
        "when": "editorFocus" 
    }