Search code examples
macoskeymappinglunarvim

How to set keymaps to ctrl+w in LunarVim


Why ?

I come from windows (specifically pycharm) and am really used to

ctrl+backspace

to delete whole words, Now i am switching to mac and neovim and am finding it really hard not having that.

The question

I found that there is a replacement to this, namely

ctrl+w

and i want to set it to

command+delete

is there any way to do this?

Sorry if this question has been already asked i could not find any solutions anywhere (also i am pretty new to Neovim) Any feedback is appreciated


Solution

  • There is already a built in shortcut in vim to delete a whole word. The motion is "diw". d(elete) -> i(n) -> w(ord) If you are just getting started with vim, I would highly recommend this playlist by theprimagen https://www.youtube.com/watch?v=X6AR2RMB5tE&list=PLm323Lc7iSW_wuxqmKx_xxNtJC_hJbQ7R&ab_channel=ThePrimeagen If you must use that shorcut, here is how you could remap it in your nvim config

    vim.keymap.set({ 'n', 'v' }, '<C-BS>', 'diw', { silent = true, desc = "deletes the word that the cursor is on" })
    
    vim.keymap.set({ 'i }, '<C-BS>', '<C-W>', { silent = true, desc = "deletes the previous word in insert mode" })
    

    I will add that the google search "ctrl backspace shortcut nvim" paired with "how to remap keys in neovim" would have gotten you the answer.