12 ms·
Learn Vim (the Smart Way): a book to learn the good parts of Vim
- DerSaidin 6y agoIf you're new to vim, also consider https://kakoune.org/ https://kakoune.org/
- naveguese 6y agoAbout a month ago, I forced myself to try and use nvi, an (almost) narrowly compatible classic vi clone. 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 https://en.wikipedia.org/wiki/Nvi Edits: grammar, punctuation.
- sergioro 6y agoLearn Vim (the builtin way): :help
- gbrown_ 6y agoYup, ":help user-manual" sadly often overlooked.
- JackMorgan 6y agoThis book looks really cool, and I appreciate what they're doing. 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/master/book_sample_history_registers.md https://github.com/steveshogren/10-minute-vim-exercises/blob...
- Normille 6y agoI'm not a Vim master, but I use it a fair bit --mostly for writing server admin, single doc coding, etc. I think I know enough to do the basics like moving chunks of text around, copying/pasting etc. so that I feel fairly productive in that I can do those things as fast [or faster] in Vim as I could in a GUI editor.. 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.
- bpanon 6y agoctrl-o/ctrl-i to move between buffers list buffers w/ vim-buftabline `nnoremap ; :Buffers<cr>`
- thesuperbigfrog 6y agoThe best way to understand and use vim is to learn the "grammar" of vim and then practice using it until you have muscle memory for common movement and editing commands. This stackoverfow post explains how the vi/vim "grammar" works: https://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim#:~:text=Your%20problem%20with%20Vim%20is,want%20to%20cut%20whole%20lines.&text=If%20you%20only%20understand%20basic,of%20%22notepad%22%20for%20you 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/ 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 https://nethackwiki.com/wiki/Options#number_pad).
- kyuudou 6y agoAnother fun game to play that focuses a bit more on vim itself: https://vim-adventures.com/ https://vim-adventures.com/ I definitely second playing nethack, whether you want to improve your vim skills or not.
- cheerlessbog 6y agoThat game is a labor of love by someone - I spent weeks playing it. So much fun solving puzzles and learning at the same time. If I had a criticism is that I'm not sure much has stuck with me. I still use the same 10-15 commands and all the obscure tricks it taught me are gone. Its worth the money just for the fun alone. Great to mess with on a laptop when you're on a plane.
- keithnz 6y agothe biggest problem is you buy the game for $25 and it only lasts 6 months, that seems a bit crap, doesn't really make sense to me to sell it as a limited time license, which is why I never bought it. But then I'm not exactly the target audience, I already know Vim, but I did enjoy the intro levels when I tried it a while back.
- wraithy 6y agoThe name could be a reference to learnvimscriptthehardway.stevelosh.com, which is an amazing resource.
- WalterGR 6y agoLink: https://learnvimscriptthehardway.stevelosh.com/ https://learnvimscriptthehardway.stevelosh.com/
- wintorez 6y agoAh Vim, one of the root causes of my imposter syndrome. (The others are CSS Grid, and Kubernetes)
- colordrops 6y agoAdd real-time safety critical systems, realistic 3D rendering, reverse engineering, quines, Paxos, deep learning, production-quality Haskell, and Boston Dynamics.
- CGamesPlay 6y agoQuines almost always have exactly the same structure: - 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.
- wintorez 6y ago- Realistic 3D rendering: start with Ray-Tracing. It's fun! - 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.
- renewiltord 6y agoKubernetes very easy to use, worth learning imho. One hour's worth effort yields great advantage for work. 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.
- I_complete_me 6y agoI also disagree. I learnt vim in my 50's and am using it daily now. In fact, I find that I use jk (which I've muscle-memoried to 'ESC' in nearly every application). Sometimes it doesn't work :-). But it did when I went on to learn org-mode during Covid-19 by parachuting with doom-emacs. There is no need to avoid learning the good stuff.
- bambam24 6y agoOver engineering
- Scarbutt 6y agoFZF(and its vim plugins) really leveled up the game for Vim.
- colordrops 6y agoAs well as neovim and LSP.
- unmole 6y agoI've had neovim installed for a while but really haven't found anything that would make me want to switch. Sure, I get the meta Neovim competition driving improvements in vim but I'd like to know what I'm missing out on.
- colordrops 6y agoIt's been quite a bit faster than Vim, but perhaps Vim has caught up. I haven't checked it out in a while. Neovim supported asynchronous updates well before Vim, so also much more responsive until recently. In any case my config is compatible with both and I can use them interchangeably.
- JoshMcguigan 6y agoI 100% agree with this. Using fzf.vim for finding/opening files, searching across files, searching within a file, etc had a definite positive impact on my productivity. For reference, I was previously using netrw. fzf is also really useful outside of Vim. I like to use it to fuzzy find git branches among other things.
- pwinnski 6y agoAs it is now, it seems to be a partial book.
- rubyn00bie 6y agoTwo things that helped me more than anything with "learning" vim and or ever wanting to use it: 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 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.
- johnfn 6y agoI just use ctrl-c instead of esc. Infinitely more accessible than esc or even ctrl bracket - it mystifies me why it’s not more commonly known. Only problem is that it quits you out of macros, so you need to use esc then, but that’s easy to remember and I use ctrl-c probably 4 orders of magnitude more than I use macros. (In fact, multi cursor mode in vscode vim obsoletes them for me entirely!)
- Lio 6y agoIt’s not that ctrl-c isn’t widely known it’s that Escape and ctrl-c are not equivalent in Vim. Ctrl-c breaks all kinds of things including repeats, so ctrl-[ is usually a better choice.
- atweiden 6y agoDie hard vimeleon here. 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. [1] https://github.com/kana/vim-arpeggio https://github.com/kana/vim-arpeggio
- semicolonandson 6y agoFor the vim enthusiasts reading, I'd like to bring to your attention some other resources released in the last few months — ThePrimeagen (YouTube): https://www.youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw https://www.youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw — Vim Tricks (newsletter/Twitter): https://vimtricks.com/ https://vimtricks.com/ — and humbly, myself, Semicolon&Sons: https://www.youtube.com/watch?v=futay9NjOac&list=PLpkoC9yJXDKkm4MStIQoieUPwNjO4Rb_M https://www.youtube.com/watch?v=futay9NjOac&list=PLpkoC9yJXD...
- sassyboy 6y ago+100 for ThePrimagen on Youtube. His videos are great for people looking to get started with Vim.
- haolez 6y agoIn my opinion, the greatest benefit of using Vim, Emacs or even Acme is how easy it is to create custom tools for your problem at hand, even for one-shot tasks. VSCode is very capable, but it can't compete in this regard (and maybe that's what they want and maybe it's a good call as well).
- ectoplasmaboiii 6y agoI've tried using the vim plugin for VSCode many times, and every time I come back to it, it just feels... off? The actual vim keybindings work fine when you're editing the document, but I find that when you want to use some of the other features of the editor, it becomes a bit more tricky/hacky. 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.
- scruple 6y agoHave you tried the neovim _integration_ VS Code extension? [0] It's not perfect (I'm still in a terminal 95% of the time, but my current VSCode set up is surprisingly not painful and I find myself using it more frequently) but it gets a lot further along than VsVim did for me (which is probably not a far comparison because I have not actually used VsVim in many years) or VSCodeVim when I tried it recently. YMMV, of course. 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. [0]: https://github.com/asvetliakov/vscode-neovim https://github.com/asvetliakov/vscode-neovim
- glouwbug 6y agoI recommend swapping your left CTRL and ALT keys when using vim, as well as CAPS and ESC to avoid RSI. Also, the dot operator is king.
- zrkrlc 6y agoWow, I had no idea about the dot operator. And TIL about `gd` (moves to the word's definition) and `gf` (for file imports) as well.
- 49531 6y agoI was using vim for years before discovering the dot operator. Truly a game changer.
- wyclif 6y agoYeah, I use combinations like 'dw...' and 'dd...' a lot. So simple, but a lot of people don't know that's built in.
- hombre_fatal 6y agoI started Vim when the internet went out once and, bored, I finally tried `vimtutor` on the debian command line. 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.
- askvictor 6y agoI partially learnt Vim some 20 years ago, but at some point stopped taking in new commands (possibly for lack of repetitive use), and am stuck in a sort of 'good enough' zone, but still awkward for certain things; the ctrl-c/v thing always throws me as I use windows primarily, gvim makes it easy to cheat using the GUI, so I do. Macros are amazing, but I feel there are probably easier ways of achieving most of the things I use them for (they, and regex search/replace are most if what I use Vim for outside of writing code).
- svnpenn 6y agoYou get over it if you use it enough. For me its now the opposite. For a while I keep accidentally trying to do Ctrl+C/Ctrl+V, but now I find myself trying to go into Visual mode or Normal mode in programs that dont support that. 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.
- Normille 6y agoHJKL makes no sense for me at all. It reminds me of the annoyingly designed computer games I used to play on my Oric as a kid, where the various direction keys to control my 'character' often bore no relation to their relative positions on the keyboard. 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.
- racl101 6y agoI know it sounds like a joke but any book on Vim should have have as its first lesson: how to quit Vim. That's the #1 question I get from vim beginners.
- adembudak 6y agoLol, I made kind of learning material on Vim, and that's exactly what I do. https://p1v0t.github.io/Doctor/ https://p1v0t.github.io/Doctor/
- AdmiralAsshat 6y agoBuffers are one of the few parts of vim I never really got the hang of. Neither that nor windows are things I can ever remember how to do without fudging it the first time, having to go look up the manual again for how to do it properly, realize I'm wasting more time than I'm saving by trying to learn it, and give up.
- gen220 6y agoWhich part of it do you struggle remembering? maybe the wisdom of hn's vim users can help :) 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`).
- stevebmark 6y agoI'm sorry to say it, but don't bother with this. It's unfinished and not in depth. The most important Vim resource is "Practical Vim" by Drew Neil. If you haven't read it you shouldn't be using Vim.
- cecida 6y agoI'm not trying to be contrarian here, but why would someone continue to use Vim and Emacs when all of its lovely features have been integrated into products like VCode? It just reminds me of serious men with beards working on mainframes and AIX power systems when I started my career.
- gen220 6y ago> all of its lovely features 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.
- chestervonwinch 6y agoI don't think most people suggest vim as a replacement for an IDE. In fact, personally I use vim bindings in my IDE because I think I think it's an efficient way to edit text, whereas the IDE provides things vim is not good at (e.g., navigating large code bases by easily jumping to definitions, doing automated refactoring, etc.). 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.
- flukus 6y agoVim is just one piece of the puzzle, it's the editor in the IDE that is unix. Tools like VSCode and IDE's take over too many responsibilities and usually do an inferior job. VSCode will do the window management for instance, opening new tabs for files, file list windows, terminal windows, etc. My desktop environment (dwm or tmux) is much better at this and universal for non development tasks as well. Another bug bear of mine (this one doesn't apply to VSCode) is IDEs that want to be the build system instead of my much more powerful Makefiles. 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.