Learn Vim (the Smart Way): a book to learn the good parts of Vim
github.com
github.com
1. Remap your "capslock" key to "escape." Vi was written using an ADM-3A terminal and its keyboard, which you can see here: https://catonmat.net/why-vim-uses-hjkl-as-arrow-keys has the escape-key in a sane place. On modern keyboards, if you can, remap "capslock" to "escape" when pressed alone, and "ctrl" when pressed with another key.
2. Make your leader key something easy like the comma character "," E.g. to make a horizontal split, I press (not including quotation marks) ",h" or ",v" to make a vertical one.
Once I did those two things it all made so much more sense... It's also great because most editors these days support vim bindings, so even if you don't want to use vim you can still benefit from its really-awsome-once-you-figure-it-out UX.
I've since remapped caps lock to control, and use ctrl-[ as escape (this is default behavior). I find having an easily accesible control key is very useful, even outside Vim. You can see in your link that it is actually the control key that used to be in the position we now put the caps lock key.
It does seem like remapping caps lock to escape when pressed alone and control when pressed with another key would be nice, but that wasn't an option for me (on wayland) as far as I know.
I bring this up only because there was a week or two transition period when I made this change, and I probably would have been better off if I had mapped caps lock to control from the start.
IMHO chording the 'j' and 'k' keys simultaneously [1] is a severely underutilized solution for escape.
Try it. You'll love it.
If you're going to rebind capslock to something — and this is particularly true if you're on macOS — rebind it to backspace. Capslock escape isn't useful outside of Vim. Backspace is useful everywhere, including inside Vim.
No, rebind it to Compose. Makes life a lot easier.
I think it's no good for Japanese, but I know very little about Japanese input. Romanji is still Japanese, right?
Also ctrl-h is backspace so mapping caps to ctrl gives you a convenient escape and backspace shortcut.
(It also gives you a heap more terminal shortcuts but that’s another story).
- Tab functions as Escape, Caps Lock as Control. That makes both keys well in reach of my pinky, and I can still use ^I for Tab.
- I remapped symbols according to an illustration[2] of the ADM-3A layout on Wikimedia (with some small adjustments). Aside from not having to press shift to enter command-mode, this also has the advantage of being more similar to the German layout, which I often have to use.
- And finally I changed ^H and ^I to work outside of terminal emulators (i.e. they send keycodes for Backspace and Tab, respectively).
While this layout is somewhat inconvenient for navigating CUA-derived UIs, I've found it great for use with vi clones and other TUIs.
[1] https://qmk.fm/
[2] https://upload.wikimedia.org/wikipedia/commons/a/a0/KB_Termi...
Otherwise it's very practical though.
Haven’t touched that part of my vimrc in years
inoremap jk <ESC>
I learned it through Spacemacs and it's one of the things that really made modal editing work for me, so I was thrilled to discover that Vim itself also supports it. (I'd tried to learn Vim before, but always having to jump over to the Escape key was a huge downer for me, and coming from Emacs I'd already mapped my CapsLock to Ctrl--though the idea of having it be Esc if pressed by itself is intriguing and I need to look into it more!)ctrl-[ is escape in terminals by default.
It’s often easier to map caps to ctrl than escape when pressed and ctrl when held. Most OSs support that without extra software.
Even in Vim it’s still very useful to have a convenient ctrl key. A lot of useful features make use of Ctrl in Vim.
On remapping leader:
Remapping to spacebar means your thumbs are dedicated to that operation. That’s more balanced left-right for touch typing.
Also you get to keep the default behaviour.
I hear this recommendation a lot. You can do that, but much better is to get a keyboard with a proper thumb cluster like a kinesis[1], maltron[2], dactyl[3], ...
Much better to put such a common key on the thumb than stress out a pinky. I have a kinesis, and have esc mapped to the 'end' key there; similar positioning is possible on other keyboards. The keyboards I linked are also much more ergonomic than most flat keyboards—important, if you rely on your hands and wrists for your livelihood. Bit expensive, but well worth it.
So, while I like the style of those keyboards, I can't justify spending that much if I am likely to develop RSI again.
---
I'm one of those weirdo's that has remapped caps to Lctrl/esc, tab to hyper/tab, \| to alt/\|, return to Rctl/enter. It's comfortable. (Ralt is now Compose/Dead Greek and Rctrl is Caps Lock)
I would love more buttons to the left of the keyboard. I currently use a 10-keyless but would love a cluster of 10-15 keys to the left of my left hand. and possibly 6 keys under the thumb area. And a real dedicated hyper key. Maybe another row of F-Keys too...
Ctrl-c breaks all kinds of things including repeats, so ctrl-[ is usually a better choice.
I would do this but I use the comma and semicolon keys all the time. I find them so useful. Gosh vim is weird. Everyone uses it differently!
" 0: F is backward search, and repeating f after F searches in the same direction
" 1: F is backward search, and repeating F after F searches in the same direction
let g:clever_f_fix_key_direction = 1
[1] https://github.com/rhysd/clever-f.vimI think a lot of people who use vim end up with a ton of unnecessary plugins and they aren’t even aware of half the functionality of plain vi. I might just be a weird minimalist though.
Isn't it possible to configure vim to just use the actual CapsLock status for the mode switch?
For example: I switch between dozens of computers, some are transient VMs or cloud instances, and I cannot afford the time (or simply cannot alter the system) to set each one up to my personal VI specs.
(Ironically, I'm a mac fan, but this is my biggest gripe going between every OS and Apple: the command key is absurd; I tried to remap to make everything work like Ctrl but that hoses the entire system and screws up VNC/RemoteDesktop...)
Emacs is an operating system, and vi is a language, which is widely "spoken". But if you invent your own dialect, you have an MxN problem, of getting M changes to register across the N programs which will listen to you when you speak to them in vi.
And I simply must nibble the bait in your last line: As a Mac native user, the command key, and consistency in commands across every native application, is one of the great features. It means, among other things, that Ctrl-whatever won't be intercepted when I send it to a program that uses it, or alternately, that it won't shadow the OS level affordance.
Back when I was spending five days a week inside a Linux VM, the context switch between Cmd-X and Ctrl-X for cut was pretty rapid and painless. Sure, I'd get the occasional cache miss, but that's harmless.
It’s very little to cp .vimrc. I do a lot more, have dotfiles git repo scripted to self install.
But yes transient vms are problem. But I’m willing to suffer a little on them to have 20x more enjoyable and productive were I do 90% of my writing.
This stackoverfow post explains how the vi/vim "grammar" works:
https://stackoverflow.com/questions/1218390/what-is-your-mos....
A fun way to develop the muscle memory for the normal mode movement keys is to play Nethack (https://www.nethack.org/) with the number_pad option set to 0 so that hjkl are used for movement, the same basic keys for vi/vim normal mode (https://nethackwiki.com/wiki/Options#number_pad).
I definitely second playing nethack, whether you want to improve your vim skills or not.
That said I'm probably only an intermediate user, because I haven't put in the time to really make things like markers and macros part of my editing habits.
— ThePrimeagen (YouTube): https://www.youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw
— Vim Tricks (newsletter/Twitter): https://vimtricks.com/
— and humbly, myself, Semicolon&Sons: https://www.youtube.com/watch?v=futay9NjOac&list=PLpkoC9yJXD...
I thought of it as an exercise in constraint, with the aim of getting better at vim. Like vanilla vim without plugins, but Nightmare Difficulty.
I've now completely fallen for it. It's missing most mainstream features and still, I... like it more? I feel like a hipster typing this, but there really is a difference in brainfeel between using a ''huge'' editor I'll never grasp fully versus a tiny one I can learn completely. Tiny sparks joy.
Wikipedia entry on nvi: https://en.wikipedia.org/wiki/Nvi
Edits: grammar, punctuation.
It just opens vim to a txt file that incrementally explains how to make basic edits. I was instantly hooked when I realized how much time "o" and "O" alone would save me over.
I almost never use Vim these days because I was too lazy to port my .vimrc + Vundle plugins to a new laptop at some point, but I use a Vim-mode in every editor I use, even the browser.
But, any time I'm working on something more than a single doc [eg. a website, or a coding project] I reach for something else. I've just never been able to find a way to use Vim comfortably in a multi-document project, without feeling like I'm being a lot less productive than I would be using a GUI, such as TextMate with its built-in project file browser and excellent project wide find/replace.
I'm learning Flutter at the moment and just got into using IntelliJ [in its Android Studio guise] and, at first I installed the IdeaVim plugin, thinking this would give me the best of both worlds; the speed of moving about within single documents of Vim, combined with the project management & code completion capabilities of a dedicated IDE. I ended up disabling it after a couple of days. The mental context switching caused by jumping back and forward between keyboard driven and menu driven operation was just slowing me down, rather than speeding me up.
As an aside: I don't really get why the "Vim saves you having to hunt for menu items" mantra is still so prevalent in this day and age anyway. Maybe in the past when people had to reach for their mouse to find a menu item, it was a valid point in Vim's favour. But a lot of us are working on laptops these days and, frankly, accessing a menu item by tapping on a trackpad right under your fingers is hardly more hassle than recalling some arcane keyboard incantation to do the same in Vim. Plus, most regularly used menu items have keyboard shortcuts which pretty soon become muscle memory anyway. I've not needed to use a menu to access an Open / Close / Save / Save As / Print / Copy / Cut / Paste / Find / Replace / Undo / Redo / Quit... etc. etc. command in decades.
list buffers w/ vim-buftabline
`nnoremap ; :Buffers<cr>`
- Quines: those are dark magic, but not very useful.
- Deep learning: A fancy word for multi-layerd neural network. Interesting concept, but nothing scary.
- Production-quality Haskell: You would be surprised how low-quality some production codes are.
- Boston dynamics: that happens when a group of smart people focus on a subject with no hinderance.
- Header (code)
- Data blob (string variable) that encodes the header and footer
- Footer (code)
Since the data blob is a variable, the header/footer simply decode the data blob and write out the decoded header, original blob, and decoded footer.
Vim not worth learning to use as adult. Time too valuable. Takes too long to become extension of body. Best learned as child/teenager. Time worthless then. Maybe if you can learn it fast. Took me years of teenage to get unthinking proficiency.
The learning curve is admittedly steep, but you get past the curve pretty quick.
I started off with a bunch of mappings, then you can remove them as you get comfortable. Now I only really have mapped "nmap H :nohlsearch<CR>" and "xmap S :sort<CR>".
Whats really tricky is using Vim without the Arrow keys. Normally I am on a desktop so it doesnt matter, but when I use a laptop it makes more sense to use HJKL. Again its just something that you need to force yourself to do or you wont get comfortable with it.
H and L are just about OK for left and right, but up and down being another left/right positioned key combo, nestled in between, just doesn't work with the way my brain's wired, at all.
Conversely, on my MacBook Air keyboard, the arrow keys are nicely grouped together in an inverted T formation at bottom right corner of the keyboard, with some space around them. Piss-easy to find and piss-easy to feel which one points in which direction, without even looking at the keyboard.
Strange that almost every tutorial on Vim I've ever read begins with "Don't be tempted to use the arrow keys instead of HJKL.." which, in my opinion is just about the "worst advice evarrr!", especially given the rest of the learning curve which awaits you.
*YMMV --depending on your own particular keyboard layout.
I guess the thinking is, if you open up some existing document, youre already at the top, so the more important key is going down, which the "J" sits right under your index finger.
I totally agree that its awkward, but I also feel that if you can get good with it, youll be way faster than using the arrow keys. Think about it like this: with the arrow keys, you must move your hand. With HJKL, you dont have to move your hand from the home row.
I can type pretty fast, though I've never actually measured my WPM speed. But I'm not a touch typist --I still have to look at the keys-- and I don't type 'properly' using all my fingers. I seem to get by with the first three on each hand. So there's no real advantage for me in having my fingers resting on the home row. In pauses for thought [my equivalent of resting on the home row] I usually find I'm waiting with the heels of my hands on the empty space below the keyboard, either side of the trackpad and my fingers just kind of very lightly touching the keys, wherever they happen to fall.
From that position, it really is far more convenient for me to just curl in the fingers of my right hand , which puts the inverted T of the cursor keys right under my finger tips and which I can do without looking, than it is for me to look down at the keys to find HJKL.
fzf is also really useful outside of Vim. I like to use it to fuzzy find git branches among other things.
In any case my config is compatible with both and I can use them interchangeably.
If I could humbly add, one of the hardest things about learning Vim isn't reading a list of commands, but rather _practicing_ them. So I wrote a list of Vim exercises (or études for the musicians), files requiring various edits, and a daily practice schedule that can be used to drill each distinct skill. Once you've mastered it, you can drop it from your schedule. I found it was really the only way to actually commit some of the more esoteric skills to muscle memory.
Here's a sample for how to practice muscle memory around named registers for yank and put, a skill almost no one I know regularly uses because it's hard to learn just by reading. After writing this and working through the ten minute exercise daily for a couple weeks, it became second nature, and now I can't live without it.
https://github.com/steveshogren/10-minute-vim-exercises/blob...
Personally, I can't imagine being productive without windows and buffers. although when I have 3+ buffers open, I usually "cheat" by fzf-finding the file (rather than `:bn`-ing my way there, or `:b` `:b x`).
If MS made an official set of vim keybindings that had better editor support, or even if there was some sort of kill switch that let me turn off vim key bindings quickly, I would be 100% sold on VSCode, but until then, I'll stick to the terminal.
A word of advice, though, if you plan to check this out... I'd recommend maintaining a separate neovim install specifically for the VS Code integration and make sure that it has fairly basic vimrc with limited plugins. You have to take care with this because (neo)vim plugins don't always play nicely with VS Code and vice versa.
It just reminds me of serious men with beards working on mainframes and AIX power systems when I started my career.
I think this might be only superficially true. One of the meta-features of vim/emacs is, over months and years of use, they slowly teach you how IDEs "work", and invite you to tweak how yours works to your whim.
example: I notice a process is slow in vim. I'm able to profile the problem, identify the binary responsible, replace it with a faster equivalent program, and enjoy that improvement for the rest of my life. Such a thing may be possible in VS Code, but it's against the norm of "just install this plugin", whereas it is the norm in vim/emacs-world.
Some other scattered ideas:
I also think that, since vim and emacs are fundamentally cli tools also gives them an advantage, because you can hook them in to your terminal workflows (git add -p, git commit -v, etc). also, you can dispatch terminal commands seamlessly from inside vim (I get `make build` in two keystrokes: `,d`).
vim (I can't speak for emacs, don't use it) is also more responsive with a much smaller resource footprint and an equivalent feature set. my work laptop can run a web browser and vim for 6+ hours. With vs code, maybe 3 hours.
Because it integrates so well into this environment it can be used as the editor step in other scripts/tools like how it is used in git commit messages. As a quick example of how this can be used here is a script I made for working with tab separated files:
tmpout="$1.tmp"
cat $1 | sed "s/\\t/~|/g" | column -t -s~ | \
vim -c 'set nowrap' - +"file $tmpout"
if [[ -f $tmpout ]]; then
<$tmpout sed "s/\\s*|\\s*/\\t/g" > $1
rm $tmpout
fi
In 7 lines of code I made it a half decent tsv editor in part of a larger system, replacing the million excel windows others were using.Another reason is that I really enjoy that vim runs in my terminal. I can easily toggle in and out of vim while doing heavy terminal work, and if I want to rapidly open and close different files while looking around for things vim makes it simple.
There might be an aesthetic or comfort aspect to it, but most tools don't stay as relevant as vim has for mere style points.
ci" == delete everything within these quotes, and put me in insert mode. vi{:%s/old_var_name/new_var_name/g == rename a variable within a block qaI"<ESC>A",<ESC>jq == make a new macro to quote a line of text and add a comma at the end. Great for taking a bunch of strings I've copied from a text file and putting them into a list in code. But the point here is not this specific macro; I can do all sorts of minor text processing macros for the dumb thing I have to do, and not manually process 100 lines of text to turn it into a piece of json.
However, there's also times when I don't have the luxury of using an IDE or when I just need to make quick edits to a single file. In these circumstances, I can just fire up vim and quickly do what I need to do because vim is ubiquitous and editing with it is efficient.
Also, the dot operator is king.
:help