DEV Community

Cover image for 10 VS Code Vim Tricks to Boost Your Productivity ⚡

10 VS Code Vim Tricks to Boost Your Productivity ⚡

Anson Heung on June 13, 2023

Learning Vim is one of the best things any aspiring software engineers can do to improve their productivity. I’ve been using the VSCodeVim extensio...
Collapse
 
anurag_pramanik profile image
Anurag Pramanik

Thanks a lot for sharing this. Apart from this I use FindItFaster extention in vscode. It's like telescope.nvim but within the terminal. Works really well. You can adjust the keybindings in settings.json like <leader>ff to find files etc.

 "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["leader", "f", "r"],
      "commands": ["find-it-faster.findWithinFiles"]
    }
  ],
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mghalix profile image
Mohanad Mohamed Eissa Ghali

Extra Tip

At this part of the article
#4 - Navigate Menus without Arrow Keys
you can remap the keys you use to go up and down in opened menus to be more intuitive by being close to the original Vim up and down motion j - k.

Steps

  • Open your command pallet (CTRL + Shift + P)
  • Type Preferences: Open Keyboard Shortcuts (JSON)
  • Add this to your file
    {
        "key": "ctrl+j",
        "command": "workbench.action.quickOpenSelectNext",
        "when": "inQuickOpen"
    },
    {
        "key": "ctrl+k",
        "command": "workbench.action.quickOpenSelectPrevious",
        "when": "inQuickOpen"
    }
Enter fullscreen mode Exit fullscreen mode

Now when any menu is opened, you're able to Move to the next item by using Ctrl + j and to the previous item by using Ctrl + k !

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

Great suggestion! ⚡️

Collapse
 
d9k profile image
Dmitry

Thanks! Very cool & useful tips.

May be useful setting for peek view:

"editor.peekWidgetDefaultFocus": "editor",

May be useful keybindings for switching occurences/code view in peek view:

  {
    "key": "alt+right",
    "command": "togglePeekWidgetFocus",
    "when": "inReferenceSearchEditor || referenceSearchVisible"
  },
  {
    "key": "alt+left",
    "command": "togglePeekWidgetFocus",
    "when": "inReferenceSearchEditor || referenceSearchVisible"
  },
Enter fullscreen mode Exit fullscreen mode
Collapse
 
adavis9012 profile image
adavis9012 • Edited

"Bravo! Thanks for sharing this. At first, I was surprised and thought, 'How do you navigate between tabs if you're overwriting the switch tab functionality with 'gt'?' But then I saw the clever solution you provided in the second part, which includes a great mapping. Well done man!" Also, I can't even imagine how long it took you to develop this setup, again, thanks for sharing.

Collapse
 
irshathcodes profile image
Irshath Codes

Hey this was very helpful for me. Especially gpd I needed this. Thank you very much. You're amazing!

Collapse
 
splautz profile image
Stephen Plautz

This was super helpful, I appreciate you taking the time to put this together!

Collapse
 
ansonh profile image
Anson Heung

Thank you so much :)

Collapse
 
overrevvv profile image
Arnav

This was really helpful, I've been using this extension for months.

Based on the this article i can assume you know how to remap binding in correct way, I'd appreciated if you can help me out with this,

Please take a look at this.

github.com/VSCodeVim/Vim/discussio...

Collapse
 
ansonh profile image
Anson Heung

Glad to hear that you found this article helpful :)

As for your question, sorry that I don't know the answer. I also had the same question a while ago haha

Collapse
 
kunalsalunkhe12 profile image
Kunal Rajesh Salunke

Is there a way to navigate between open files?

Collapse
 
ansonh profile image
Anson Heung

Yes, I mapped H and L to focus the previous and next opened file respectively. Try this in settings.json:

"vim.normalModeKeyBindings": [
    {
      "before": ["H"], // Focus previous tab at the left
      "commands": ["workbench.action.previousEditor"]
    },
    {
      "before": ["L"], // Focus next tab at the right
      "commands": ["workbench.action.nextEditor"]
    },
]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
bolig_2017_9ea732635a544f profile image
Bolig 2017

Please add a tip to change "change" and "delete" behaviour from cutting content into DELETING. Add a leader-c and leader-d to change-with-yank and delete-with-yank