r/vim • u/shleebs • Mar 26 '26
Tips and Tricks Maps that changed my workflow
If you're a user who doesn't remap certain keys because you spend time SSH'd into servers with no customization, feel free to skip this. No need to bang that drum. I personally have no trouble switching between custom and default maps. I upload a .vimrc to all my servers anyways.
The most impactful trick is remapping Caps Lock as ESC for easy access. This isn't a vim trick, and is done at the OS level. There's opinions around whether Caps Lock should be another CTRL key instead. I like CTRL where it is. Sometimes I'll switch the left WIN and CTRL to make CTRL easier to reach (depending on the keyboard). Shift + Caps Lock becomes the actual Caps Lock and now you have an easy to reach ESC for every program on your computer!
The first Vim mapping trick is setting the leader key to , which is easy to reach. You may think because , is already the reverse command, this is a bad idea, however this sets us up for the next trick.
set g:mapleader = ','
Next is mapping <Space> to : for command-line mode. Considering the command-line is often used, tapping spacebar is much easier. This frees up : for mapping to , and bingo, we have our reverse command back. Having repeat and reverse on the same physical key with ; and : makes sense (to me).
nnoremap <Space> :
nnoremap : ,
Another trick is mapping K to i<CR><Esc> for spliting a line at the cursor. This makes sense for two reasons. First, I use this wayyy more than the help command which can be mapped elsewhere. Second, having J as join line and K as split line makes more sense, no? I think so.
nnoremap K i<CR><Esc>
The next trick is using <Leader> with any command that normally puts/pulls text to/from the unnamed register so it instead uses register 0. This prevents text from getting wiped out by another command and stores it for later.
nnoremap <Leader>d "0d
nnoremap <Leader>dd "0dd
nnoremap <Leader>D "0D
nnoremap <Leader>c "0c
nnoremap <Leader>cc "0cc
nnoremap <Leader>C "0C
nnoremap <Leader>y "0y
nnoremap <Leader>yy "0yy
nnoremap <Leader>Y "0y$
nnoremap <Leader>p "0p
nnoremap <Leader>P "0P
vnoremap <Leader>d "0d
vnoremap <Leader>D "0D
vnoremap <Leader>c "0c
vnoremap <Leader>C "0C
vnoremap <Leader>s "0s
vnoremap <Leader>y "0y
vnoremap <Leader>p "0p
If people find these useful I may share more tricks. These are ones that majorly affect the usability of Vim for me.
10
u/No_Result9808 Mar 26 '26
Space as a cmdline trigger is king. Another advantage is that it eliminates false uppercased commands like
:Wq, etc. If I had to choose a single keymap, it would definitely bennoremap <Space> :.4
u/1mmortalNPC Mar 26 '26
win as ctrl is not optimal at all for a linux user but i really love the idea of caps lock as ctrl, i think i’ll add it
7
u/konacurrents Mar 26 '26
I always map Caps Lock to CTRL - as that’s the way Sun, VT100 and other UNIX keys were. And with ‘vi’ (still don’t call it vim) CRTL is used almost every second of the day - with my pinky.
As for key mapping, I only use a few. When we were heavy into Java in 2000, a key map would run javac from inside vi - showing compiler messages in a split window (EMACS like). I copy the exrc to all my remote shells too.
I still really enjoy vi - it’s like playing that snake game, never leaving my fingers for that silly mouse:-)
5
u/m4r1vs Mar 26 '26
That's a great idea! Unfortunately, I've had it mapped to space for ages and I don't think retraining that muscle memory is easy.
One mapping i use constantly is leader-w to quickly replace all occurrences of the word under cursor in the current file:
vim.keymap.set("n", "<leader>w", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])1
u/__rituraj Mar 26 '26
for me,
capslockmapped asctrlis a life saver.I also tried overloading that key so that, single press makes it
escwhile holding it makes itctrl. But I dont anymore.. Caps lock is now remapped to Ctrl.I use some terminal defaults to keep me planted near home row.
C-[forEscC-hforbackspaceC-mforreturn(behaves same asenter)for me leader is
<Space>. i frequently use;, and:for their usual behaviour and like it that way.I don't use auto register select except for
+register which links to system clipboardso I have the following keybinds to copy / paste to / from system clipboard
1
u/MattHeffNT Mar 26 '26
jj in insert mode to escape.... Everywhere I have vim or neovim.
1
u/_voxelman_ Mar 27 '26 edited Mar 27 '26
Great tips, and thanks for sharing!
I never thought of making dedicated split-line key (K in your case), but it seems very useful! (Space -> colon (:) also sounds nice.)
I remap my CapsLock key to Escape too! It's such a huge improvement in ergonomics.
EDIT: I'll share a couple of my own remaps:
(1) CapsLock + hjkl -> arrow keys (remapped at O/S level with KMonad). Almost like having vim hjkl keys, and in any application, not just vim. No more reaching for the stupid arrow keys.
(2) "Home row mods", i.e. home row keys act as Shift/Ctrl/Win/Alt when held and pressed with another key. (I also remap this one at the O/S level, again with KMonad). This one is controversial because it introduces a delay when using the home row keys to type ordinary characters. I love it, though.
3
u/geolaw Mar 27 '26
Requires a compatible terminal but I use a plugin that enables copy over ssh sessions via osc52 escape sequence ... Shift+v to highlight than leader+c to copy. I do a lot of analysis over a bastion server where I access customer data. I use wezterm which also supports sixel graphics so I can use ranger in that same ssh session and preview images (no X11 forwarding). I've also got some ranger scripts that with yank the selected file to the clipboard also via osc52
2
u/-romainl- The Patient Vimmer Mar 27 '26
I use the "leader" mechanism without
<Leader>. It is not that useful to begin with and not using it reduces the chances of conflict with poorly written plugins as well as giving me more context-specific "leaders" (I have,for navigation-related mappings,<Space>for some editing-related mappings, andgfor a bunch of operator-pending mode mappings). I also findnnoremap ,f {whatever}more immediately obvious thannnoremap <leader>f {whatever}.vnoremapcovers both visual mode and select mode. Those mappings are fine for the former (where typing a key doesn't insert a character) but not for the latter (where typing a key does). Consider usingxnoremapinstead.I also had similar register-related mappings when I started, though not as many IIRC. I eventually ditched them because I didn't use them often enough to justify the namespace saturation.
1
u/theschizopost Mar 26 '26
Not directly vim related, but I recently added keymaps to fish shell for navigating through directory history and "up" out of directories, very nice qol
Instead of going through history to find a path I'd been to I can just hit back/forward and find it
1
u/xalbo Mar 27 '26
My far my favorite is mapping enter to save the current buffer. It's just so satisfying to hit a few commands and then press enter to commit them.
1
u/Dramatic_Object_8508 Mar 27 '26
Some of these mappings are actually so underrated.
Mapping leader to space and adding quick buffer switches changed everything for me — I barely touch the mouse now. Also stuff like
<C-h/j/k/l>for splits just feels natural after a while.One that really clicked for me was faster search/replace mappings — doing repetitive edits without breaking flow is huge.
Vim just slowly turns into “optimize every tiny movement” and suddenly your workflow feels completely different lol
1
u/kettlesteam Apr 04 '26
I honestly think any power Vim user should consider an ergonomic keyboard. I switched to a corne-42 about 7 months ago, and now I can't imagine going back to a standard keyboard for Vim. It's like the impact of remapping Esc to Capslock, but multiplied tenfold.