6 ms·
Handy Keymaps in Vim
- franey 7y agoBy far my favourite remap in (Neo)vim is to map : to ; and ; to , I don't know how many thousand key presses I've saved by not having to hit "Shift" for every command. " Use ; rather than : for commands nore ; : nore , ;
- flukus 7y agoI just switch ':' and ';' along with '-' and '_' in insert mode, cut's out probably 90% of shift key presses. Swapping the numbers and their shift counterparts would probably save another 90%.
- boomlinde 7y agoYMMV depending on what you are actually typing, though. I think I tend to spend significantly less time issuing ex commands than I spend actually typing things.
- joeldo 7y agoI've found a system wide mapping of 'Caps Lock' to 'Esc'(and vice versa) a much better use of keyboard estate / ergonomics. Although the mapping was prompted by Vim usage, it's surprisingly useful for general computing as well.
- gh02t 7y agoMe too. I put escape on my caps lock key on my Ergodox and it's awesome. I miss it whenever I use another keyboard. Escape gets a lot of use everywhere and is in kind of an awkward spot, while for me at least caps lock is literally never used and is in a very comfortable spot.
- devposter 7y agoMe too. When I get a new system, the first thing I do is map CapsLock to Escape. On Windows, I use the Uncap [ https://github.com/susam/uncap https://github.com/susam/uncap ] tool because it does not require install or restart. The tool has good documentation to map CapsLock to Escape for Linux and MacOS too. On the flip side, I struggle to use Vim when I need to do so someone else's computer. :-D
- patrickdavey 7y agoMy favourite mapping for 'Esc' usage is to map kj to Escape ... super handy noremap! kj <esc> https://github.com/patrickdavey/dotfiles/blob/058950c2f470a1d7461514c4f590ad89a58ba5d2/vim/.vimrc#L127-L128 https://github.com/patrickdavey/dotfiles/blob/058950c2f470a1...
- runald 7y agoWhat if you need to type something like blackjack?
- equalunique 7y agoThe remapping would trigger <esc> when both j and k are held down at the same time, so typing "blackjack" could be an issue if it were typed quickly and/or chorded.
- patrickdavey 7y agoIf you needed to type it, you'd have to pause after typing the k (about a second?) then type the j.
- sirsuki 7y agoI found jk to be the best. If I use it in normal mode it is a no op (cursor up and down). The english language (and most all programming languages) don’t have words with a jk sequence in them (unlike kj). It works universally across all keyboards and terminals. My fingers are already there (unlike esc which is just as bad as lifting my hands to use the mouse). Plus in the rare case I do need jk inputed (very very rare) first the default is a safe default (esc) and second the mental load to pause while typing (pressing j wait past the half second timeout then press k) is no different then the mental load to choose to accept the expansion of abbreviations or delay typing to get around the auto expansion triggers. Jk for the win!!! (Also jj works well to). I also set my mapleader to <Space> you would be surprised how useful that is. Not to mention , (comma) is a valid and useful vi movement key.
- patrickdavey 7y ago
- boomlinde 7y agoIMO making it a control key is a better choice (I tried both at some point) because chording with awkward keys is worse than just pressing them, and the control keys are placed awkwardly on most keyboards. Since you can end insertion mode with ^[ you then have a pretty comfortable chord that doesn't stray far from the home row to replace the escape key. I had a tool on a mac that would make caps lock equivalent to escape if it was pressed and released alone, and control if it was chorded. Sounded great on paper but I underestimated how often i press control before realizing I don't want to perform a chord.
- neonroku 7y agoKarabiner Elements is great for doing this kind of remapping on macOS https://pqrs.org/osx/karabiner/ https://pqrs.org/osx/karabiner/ The equivalent for Windows would probably be AutoHotkey https://www.autohotkey.com/ https://www.autohotkey.com/
- Tsiklon 7y agoOS X can natively set Caps Lock (or any of the other modifiers) to CTRL,ALT,CMD,Esc,Caps. in the Keyboard Pref Pane at least as of 10.13. Of course Karabiner can do quite a bit more than that. But if you can't or don't want to install more software it's a choice available to you.
- joeldo 7y agoThat's an interesting idea as well. I've always found reaching for the 'Esc' key to be more awkward than the 'ctrl' key, but undoubtedly I use the 'ctrl' key more often than the 'esc' key outside of Vim, so perhaps the sheer volume of use would make it worth it.
- zipperhead 7y agoMake it both! From http://www.economyofeffort.com/2014/08/11/beyond-ctrl-remap-make-that-caps-lock-key-useful/ http://www.economyofeffort.com/2014/08/11/beyond-ctrl-remap-... xcape -e 'Caps_Lock=Escape;Control_L=Escape;Control_R=Escape'
- adrianrocamora 7y agoSince I can't control the mouse so well anymore due to health reasons I grew to hate Kanban boards and Trello. Nowadays, the following goes into my init.vim along with vimwiki and it has made my work much more enjoyable :) """ KANBAN BOARD " Close board tab map <leader>bc :tabclose<CR> " Main board: soon, doing, today, done map <leader>bb :tabnew /media/datanix/code/mdwiki/wiki/kanban/soon.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/doing.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/today.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/done.md<CR> " Full board: triage, later, soon, doing, today, done, archive map <leader>bf :tabnew /media/datanix/code/mdwiki/wiki/kanban/triage.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/later.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/soon.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/doing.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/today.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/done.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/archive.md<CR> " Triage board: triage, later, soon, doing map <leader>bt :tabnew /media/datanix/code/mdwiki/wiki/kanban/triage.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/later.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/soon.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/doing.md<CR> " Archiving board: done, archive map <leader>ba :tabnew /media/datanix/code/mdwiki/wiki/kanban/done.md<CR>:vnew /media/datanix/code/mdwiki/wiki/kanban/archive.md<CR>
- AH2mdte8kPnJS 7y agoI loved this but wanted to generalize it a bit to clean it up and make it portable across different computers. By no means am I a vimscript expert so any improvements welcome. (I've defined g:settings.kanban_board_path above). function! g:Kanban_file(stage) return g:settings.kanban_board_path . a:stage endfunction let $KBsoon=g:Kanban_file('soon.md') let $KBdoing=g:Kanban_file('doing.md') let $KBtoday=g:Kanban_file('today.md') let $KBdone=g:Kanban_file('done.md') let $KBarchive=g:Kanban_file('archive.md') " Close board tab map <leader>bc :tabclose<CR> " Main board: soon, doing, today, done map <leader>bb :tabnew $KBsoon<CR>:vnew $KBdoing<CR>:vnew $KBtoday<CR>:vnew $KBdone<CR> ...
- adrianrocamora 7y agoLovely, it was a bit of a hack I came up with that I was trying out, but your cleaned up version makes it look wonderful so into my init.vim it goes! Thanks :)
- fourier_mode 7y agoIs there any reason for not using Tmux instead of using panes in Vim?
- Scarbutt 7y agoThey are orthogonal?
- jteppinette 7y agoUtilizing cross-window copy/paste, cross-window repeat, opening a new file (window) with a single command vs new tmux pane then initializing vim. Those are just a few of the many reasons. IMO, using a new tmux pane for each vim instance would be a HUGE anti-pattern. Most people with the tmux/vim setup will use a single tmux pane for vim, then N number of other tmux panes for other required needs (compiling, tests, etc...).
- nextlevelwizard 7y agoDo people usually have multiple vim splits open? At least I usually just have one terminal with new tmux splits and usually one vim with multiple buffers I switch between if needed. However if I'm looking for something or doing something in another split and I need to view a file or edit a file I don't go back to my vim split and open it there I just open vim right there where I am.
- jteppinette 7y agoIn standard usage, I am using splits (horizontal). The only real time I am using buffers is when I open up multiple files from command line in some type of ‘vim ‘git grep -l “<search>” .’‘ scenario where I will do an action against all opened buffers in vim. Regarding your second point, I behave similarly. If I am off in one of my non main editor tmux panes and I need to open a quick file, I will do it there instead of moving back to my main editor vim session. This is usually due to the file needing to be opened is outside the cwd of the main vim session.
- boomlinde 7y ago
- goblin89 7y agoAs far as Vim split navigation goes (and especially for those of us using Tmux), check out https://github.com/christoomey/vim-tmux-navigator https://github.com/christoomey/vim-tmux-navigator. It simply allows you to use Ctrl+{h,j,k,l} to navigate across Vim and Tmux splits as if they all were part of one cohesive IDE. Additionally, it spares you from having to maintain a configuration blob in your .vimrc thanks to being bundled as a plugin. I don’t think it auto-creates splits, though.
- kpremote 7y agoI've noticed that there are not as many Vim/Emacs related posts on HN during the past two years than before. And the discussions and upvotes have been less enthusiastic. If it's indeed the case (I might well be off the mark), I can think of a few possible reasons, Maybe because VS Code has won. It is much easier for beginners than Vim/Emacs (duh) but still powerful, so less questions and issues are raised. Its default setup is very good so customization is minimum, its plugins system are both vast and easy to use, etc. Or, Vim itself has become easier to operate since version 8, tutorials are better than before, plugins are better, Or on HN people these days have much more interests in talking about other topics. What do you think?
- lone_haxx0r 7y agoMaybe everything to be said about vim has already been said. You can look at those threads from 3 years ago and read about it if you want.
- yinyang_in 7y agoI really like how his website displays so well in mobile. Beautiful work