by adamredwoods · 6y ago · 0 comments
nmap ,w :w<cr>
in my vimrc so I can only press two keys to save the file. I think the colon character (:) adds a little overhead to such a common command because one has to press shift with the colon/semicolon key (depending on the keyboard layout), and then release them to continue pressing the remaining keys. And this is if you're already in normal mode; if you're in visual/insert mode you'd have to press Esc or Ctrl+[ first. Of course, these are small details that you don't normally think about, but it does feel a little cumbersome when coming from an editor where you can just press Ctrl+s or C-x C-s (in the case of Emacs) and continue working.In the end, vim doesn't stop you from defining key bindings to improve your workflow.
" save with ctrl+s
nmap <c-s> :w<CR>
imap <c-s> <Esc>:w<CR>a
Edit: I guess it should be: nmap <D-s> :w<CR>
imap <D-s> <Esc>:w<CR>a imap <C-s> <C-o>:w<CR>
<C-o> in insert mode can be used to execute normal mode commands.1. You can bind save to any key combo you want. I personally use <leader>w. I find it more ergonomic, fast, and portable than command-s.
2. Every action in vim reads like a little story. You start to speak the stories to yourself. For example:
Select the entire line (V), move to the end of the line ($), move to the matching end brace (%), delete (d)
3. Then you realize you can store those stories into a macro and execute them ad hoc, and the world becomes amazing.
The things you learn are cumulative. You begin to expect the pattern to continue and more often than not it does.