Interact with this post using Mastodon or
Underrated keybindings
Published on
I am sharing here few keybindings that helped me daily.
As you know, defining a keybinding in vim is as simple as adding this line of in your vimrc
or init.lua
:
modemap key command # for vimrc
vim.keymap.set( 'mode', 'key', 'command') # for init.lua
# where:
# mode is n (for normal), i (for insert), v (for visual)
# key is your keypress
# command is the command to be executed by vim
╭── Take care of your eyes
Adding zz
to some default commands allow the current line to be automatically placed in the middle of the screen. This greatly reduces the fatigue on the eyes and helps finding things easily.
key | command | action |
---|---|---|
j | jzz | move down one line |
k | kzz | move up one line |
n | nzz | jump to the next search match |
N | Nzz | jump to the previous search match |
╭── Work on your files easily
For these ones I don’t share my personal keybindings since there are no default ones.
command | action |
---|---|
:so | reload vim config on the fly |
:History | open a list of previously opened files |
:%s//g | write the replace command so you only have to |
type the text to be replaced (to be used in normal/insert mode) | |
:s//g | write the replace command so you only have to |
type the text to be replaced (to be used in visual mode) |
╭── Makes visual keybindings act as the delete/yank ones
There is certainly a good reason why hitting vv
or V
doesn’t act like dd
, yy
, or D
and Y
but that confuses me. So I’ve made this happen:
key | command | action |
---|---|---|
vv | 0v$ | select the entire line |
V | v$ | select the end of the line |
Thanks for your read. Hope it's been useful to you.
✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
More food for thoughts? Check other posts about: #(Neo)vim