14 ms·
Vim Reference Guide
Hello!
"Vim Reference Guide" is intended as a concise learning resource for beginner to intermediate level Vim users. I hope this guide would make it much easier for you to discover Vim features and learning resources than my own blundering experience.
To celebrate the release, ebook version is free to download till 31-Mar-2022:
* https://learnbyexample.gumroad.com/l/vim_reference_guide https://learnbyexample.gumroad.com/l/vim_reference_guide
* https://leanpub.com/vim_reference_guide https://leanpub.com/vim_reference_guide
Some of my other ebooks and bundles are on sale and I'm currently creating short 1-3 minute videos to highlight Vim features. You can find these details in the above links.
Visit https://github.com/learnbyexample/vim_reference https://github.com/learnbyexample/vim_reference for markdown source and other details related to the book.
Hope you find these resources useful. Let me know your feedback.
Happy learning :)
- gigatexal 5y agoThis is a fine resource. For those who love vim already but want to really understand it this was shared by my team internally: https://github.com/mhinz/vim-galore https://github.com/mhinz/vim-galore
- asicsp 5y agoYeah, Vim galore is a nice resource. Was discussed a couple of months back: https://news.ycombinator.com/item?id=30084913 https://news.ycombinator.com/item?id=30084913
- mrpotato 5y agoNeat stuff! Nowadays, I mostly use Cheatsheet[1] to quickly look up things I want to do, but resources like this are always nice for learning new stuff you didn't know about. One piece of feedback is that I would include "+p and "+yy in the copy and paste section. I feel like that's the first place where people will go to look for "How to copy and paste using clipboard". [1] https://github.com/sudormrfbin/cheatsheet.nvim https://github.com/sudormrfbin/cheatsheet.nvim
- asicsp 5y agoThanks. And that's a good feedback, I'll add something to that effect in the next version. The interactive cheatsheet looks so cool! Gotta try it out. Could be extended to programming languages too.
- m1keil 5y agoOh, wow. This type of command discovery with fuzzy search and human readable description is what I've been looking for to enable sublime/vscode/atom/intelij cmd-shift-p type of functionality. This is a must IMHOfor a feature heavy editor nowadays. Thanks for the link.
- doix 5y agoHi, great work releasing this! Trying to explain vim concisely is always an interesting challenge and I had a great time reading your attempt in this book. I always find it really interesting on how people try to group certain vim functions in a way that makes sense to people that don't use vim. Whenever I try to explain vim to other people, I always start super abstract, i.e 'vim grammar is all (count)? verb then object. Learn actions and then the movements to apply the action where you want'. I think you cover that idea pretty well in your 'Vim philosophy and features' section whilst not making it overly abstract and keeping it relatable. Some things I noticed, you mention registers in the insert mode section before explaining what they are. It seemed odd to me that you used the word before explaining what it meant, but maybe it is unavoidable? I also noticed you completely left out folds (z, :help fold). Personally, I aggressively fold code I'm not working on so I think they are super important :D. There was a plugin posted recently thats a cool alternative to folding though (similar to emacs narrow) [0] [1]. [0] https://github.com/hoschi/yode-nvim https://github.com/hoschi/yode-nvim [1] https://news.ycombinator.com/item?id=30305011 https://news.ycombinator.com/item?id=30305011
- asicsp 5y agoThanks for your feedback. And your point about 'Vim philosophy and features' section is interesting. I find it difficult to explain abstractly and I wondered if I should copy-paste some sections from the famous "you don't grok vi" answer (https://stackoverflow.com/a/1220118 https://stackoverflow.com/a/1220118). >Some things I noticed, you mention registers in the insert mode section before explaining what they are. It seemed odd to me that you used the word before explaining what it meant, but maybe it is unavoidable? Yeah, my chapter structuring ended up in many cases like that. For example, I mention how to modify behavior of left/right arrow keys to move across lines using a setting. But, Command-line mode chapter comes later and use of vimrc comes even later. For cases like registers in Insert mode chapter, I linked to the Normal mode section after the bullet points (may be I could move it to the start of section). >I also noticed you completely left out folds I knew that there's a fold feature but haven't used them. I think I cover only about three commands with `z` in Normal mode chapter. I don't use multiple buffers in same window, tags, third-party packages, etc - so details on them are light too (or entirely missing).
- deleted 5y ago[deleted]
- uhtred 5y agoI always use https://vim.rtorr.com/ https://vim.rtorr.com/
- johncoltrane 5y agoAnother predator preying on newbies. Don't waste your money on this. Doing $ vimtutor and then going through the user manual is all it takes to learn Vim. Easy, free, and built-in.
- yash1th 5y agoit’s really harsh to say that. I’m sure many people appreciate the material and effort
- ketanmaheshwari 5y agoNot to take away anything from this but I think there are plenty more valuable resources available for free on the web on this topic.
- sundarurfriend 5y agoThe author (OP of this post) has a page listing some of those free resources available on the web: https://learnbyexample.github.io/curated_resources/vim.html https://learnbyexample.github.io/curated_resources/vim.html
- johncoltrane 5y agoPeople appreciate lots of pointless things, and people like to profit from it. Such is life.
- ketanmaheshwari 5y agovim user manual in pdf form is surprisingly difficult to find. Here is one I found: https://begriffs.com/pdf/vim-user-manual.pdf https://begriffs.com/pdf/vim-user-manual.pdf
- johncoltrane 5y agoIt's already in Vim, where it matters, so there is no need for such a thing. First, because it may not be up to date (current version is 8.2, with 9.0 around the corner), second, because the links to the reference manual are dead.
- rendall 5y agoGreat job on this! > what is all this need for complicated editing features? Why does a text editor require programming capabilities? Why is there even a requirement to learn how to use a text editor? Isn't it enough to have the ability to enter text, use Backspace/Delete/Home/End/Arrow/etc, menu and toolbar, some shortcuts, a search and replace feature and so on? A simple and short answer — to reduce repetitive manual task. For me, the entry way, what convinced me to try Vim, was the advantage of not needing to move the mouse. That back and forth movement - lifting my hand, grasping for the mouse, moving the cursor to where it needs to be, clicking and dragging to highlight text, ctrl-x, moving the cursor to where it needs to be, ctrl-v, repeated throughout the day just felt inefficient. But what really makes it feel like a super power is the repetitive tasks thing. Convert hundreds of dates from dd.mm.yyyy to ISO 8601? No problem! Alphabetize those lines? Can do. Convert that Jira ticket title to a git branch name? It's done already. But "repetitive tasks" would never have convinced me to try it. "Just use cut and paste", I would have countered.
- chockchocschoir 5y agoWhat finally made me switch was not seeing people editing with vim, but rather how they moved around and navigated, which seemed so much faster than any other editor.
- systemvoltage 5y agoWhat's the best way to rapidly move around without having to count lines? I sometimes use Ctrl + U and Ctrl + D to move entire pages but always found it a bit more laborious to move around in Vim. 13j seems like it would require me to count exactly 13 lines before I can get there. I use vim + mouse unfortunately because it is quicker unless there is a better way?
- StuckBoy 5y ago#G (i.e. 20G) would put the cursor on line 20, but that's only useful if you have line numbers in your editor. If you have relative line numbers then #j movement is easy since the number you need to jump up or down should already be calculated.
- cassepipe 5y agoWhen I was first introduced to Vim I thought : Modal editing is a great idea! I also thought why the hell do I have to hit Esc to get into normal mode!? You couldn't make a key further for the home row. So I refused to use it for a month until I stumbled on a Reddit post on how to swap the Esc key and Caps Lock : "setxkbmap -option caps:swapescape" on Linux. Somewhere in the settings for MacOs. For Linux you don't have to swap, there are other clever options. Turns out that Esc on old "Unix" keyboards use to sit where Caps Lock is on modern keyboards Another popular option is to have "jk" switch to normal mode as you are unlikely to need to insert that combination of letters. How almost all introductions to Vim do not mention that historical fact and the fix for it, is beyond me.
- peakaboo 5y agoI use Ctrl-c instead of esc, works really nice for me. I prefer it to jk actually. But that's the thing, choice. That's the best thing about our tools and operating systems. Respect for the user choice.
- cassepipe 5y agoI am all for choice. But the default is just plain bad and introductions generally don't even mention Ctrl+c
- dwmbt 5y agoi think that's what first turns people off from vim. the defaults are (subjectively) terrible from an ease-of-use perspective. usability wise, nothing beats it. maybe emacs competes, but i've never given it a go. i think most introductions would do well with showing people how to change their configurations first. that's why i use neovim anyway. i took a unix course my third semester at uni and we had an entire 2 weeks dedicated to vim and how to feel more comfortable in our environments. we were only allowed to ssh into our development environments and the professor noted he's had a lot of success after ensuring everyone felt a-okay at the command line. at the end, we had an extra credit assignment where we got to show off our configs and present to the class why we made the choices we made. some kid even got me to start using some cool plugins (goyo, if i remember correctly), he introduced me to neovim!
- asciimov 5y agoI always feel that how to exit and quit vim should be at the very top of the first page. With a quick explanation for the various ways to do it. ZQ - in normal mode, quits (notice no colon and capital) ZZ - in normal mode, saves only if file was modified and quits :x - same as ZZ :w - write the file :wq - writes the file regardless of changes and quits :q - quit, if no changes :q! - quit, regardless of changes :w !sudo tee % - For when you need to save a file you don't have permission to and you forgot to start vim with sudo. Edit: Also note the difference between 'ZZ' and ':wq'. While 'ZZ' doesn't make any changes to the file system if the file hasn't been modified, ':wq' will at minimum change the date of last modification to the time that save was ran even if the file was not modified.
- JNRowe 5y agoMight also want to note :cq[uit] to quit with an error code. This can often be useful when you're using vim as your $EDITOR and wish to tell the calling process that you want to abort.
- asciimov 5y agoGood call, I think I've only used :cq once(?).
- JNRowe 5y agoOops, I probably could've offered examples. So, when writing a mail I can choose to simply give up instead of dropping me in to a dialog for "save draft/quit?", or to drop out of an edit session in `git add --interactive`, etc. The reason it can be useful in these specific instances is that you don't need to unwind your changes if you've run filters to modify the text for example.
- DerSaidin 5y ago:cq is very handy for aborting merges
- sundarurfriend 5y ago
- thisisauserid 5y agoI can't be the only one to use :x instead of :wq but I never see it in tutorials. It's 50% fewer keys!
- qiskit 5y agoZZ also does the trick, but I always do :wq out of habit. After all, you only write and quit once per file.
- opan 5y agoZZ and ZQ are both very nice. On the note of saving/quitting and things not being mentioned enough, I only recently learned about :up to only save the file if there were actually changes (probably short for "update). Saves some time, especially with remote files, if you're one to save a lot and not remember if you saved recently already. I think this is closer to how emacs saving works by default. I bind space-f-s to save files, and tend to use that more than :w or similar, so in my case I just updated what that keybind did.
- shirro 5y agoZZ is the same as :x which are both what I would normally want to do - only write if changed. I would use :wq! to overwrite readonly files more than I would use :wq The only use case I can think of writing when not changed is if there is a process watching the file that I want to trigger. I think the problem with teaching people how to save and quit in vim is that there are so many ways they might want to do it and nobody wants to dumb it down to a single default. It is a bit like how Zig doesn't have a simple print macro because in real code do you want your output buffered or unbuffered, etc.
- asicsp 5y agoI have mapped F2 to save and F3 to save and quit ;) Probably I should add something about alternate ways, there's another comment with more variations that I didn't cover.
- LamJH 5y agoI learnt regular expression by reading your books, thank you for the great work.
- asicsp 5y agoThat's great to hear, thanks a lot for your feedback :)
- jzer0cool 5y agoNever reached being a vim power user. Somehow I always end back up to an IDE especially when it involves a bigger project. Could someone share some power user examples when only using vim it really shines for programming?
- drekipus 5y agoI use "recorded on the fly" macros all the time. But other than that, I use vim to avoid using an IDE as much as possible. I keep in the terminal, have all my tools available, don't have to click around or wait for load times, etc. Vim opens instantly and I can navigate to where I need to go instantly. For instance, just yesterday, I had a test failed that was comparing two (big) classes of objects, and the test suite spits them out as single long lines as a diff. But looking at long lines are super hard to read, so I can just do something once (ie: take a vertical chunk of text between zero and the next comma, and append it to end of file) then run that macro 70 times, and suddenly that long line I had to scroll through is all divvied up and I can easily spot where the issue is. All of this is a bit simpler (believe me!) Compared to trying to remember where a certain menu item or action is. I'd probably have to pull up excel if I didn't have vim. But you've heard this all before
- agentwiggles 5y agoI like Vim's editing model. Vim itself is a truly awesome piece of software. BUT - it doesn't have IDE style features, which I have come to rely on to do my job effectively, built in. Luckily for me, Vim's editing model exists in the IDEs I use via Vim 'emulation' plugins. In Jetbrains IDEs and in VSCode, the emulation is quite good. In the incredibly rare instance where I need a macro or some similar 'power user' Vim feature, I just pop that file open in Vim. For me this approach strikes the best balance. I get to use the powerful modal editing that I've come to enjoy, while also getting to take advantage of the many powerful features of IDEs.
- scns 5y agoIdeaVim by JetBrains does macros. Slower than Vim but still.
- 5y ago
- silent_cal 5y agoWhat is the point of Vim? I have used it before and to me it just looks like an antiquated text editor. But I'm sure I must be missing something.
- phailhaus 5y agoYou probably don't need it. I like it because it's lightweight and always available in my terminal, and the modal paradigm of editing is very well suited to editing code. It's more like modifying the structure of the code rather than working at the character-level. However, I've spent years finding the right set of plugins, shortcuts, and keybindings that work best for me. I've basically turned it into an IDE for myself, but one that I can navigate much more efficiently than something like Pycharm (even with vim mode).
- shirro 5y agoIt isn't just the look, it really is an antiquated text editor, based on even more antiquated text editors. Though a well maintained one with a very active fork in neovim. There are arguably better IDEs for programming and easier text editors that are still very powerful and support customisation and extensibility. Being a reasonably small editor with a text based UI I can easily use it to edit files anywhere and on any sort of hardware with great performance and opening up a file to make a quick change is practically instant. And then being able to navigate around, edit and change different types of text objects isn't something all that common outside of the vi world I think. It is probably most suited to people who want quick mouseless editing of text and already work in a *nix command line environment. First impressions aren't great and I am sure lots of people give up and use something else including myself. But then my needs changed and I found vim (now neovim) was a surpsiingly good fit. Like most editors it needs a few plugins installed and customised to support more complex needs and they aren't a point and click thing like vscode.
- syngrog66 5y agopro-tip: the "Hello World" for any vi/vim reference is to start by showing the user how to exit it. safely, quickly, ideally with no loss of edit state please, we beg you, for the love of humanity. there have been anecdotal tales of folks trapped inside vi sessions for weeks, months, even years, ultimately passing from lack of water or food
- shmerl 5y agoI use nvim in general and it's good but I'd appreciate an editor with modal idea but free of some decades old legacy logic that's not really intuitive (and requires tweaks to bring things in shape). Are there some modern alternatives that fill that role and are decent out of the box?
- DerSaidin 5y agoIf you're thinking about learning Vim, take a look at https://kakoune.org/why-kakoune/why-kakoune.html https://kakoune.org/why-kakoune/why-kakoune.html I used vim for many years, and I prefer kakoune because: 1) Object-verb is better than verb-object (gives visual feedback, and makes it easier to compose commands) 2) Great support for multiple selections
- schrectacular 5y agoThanks for sharing! Interesting to me given that I already tend to use vim this way - my tendency is to use visual selection followed by verb. How was the learning curve as an experienced vim'er?
- justaj 5y agoI enter my e-mail on that Gumroad link but it doesn't give me the free eBook. Is this perhaps a cunning way of the OP to collect e-mail addresses?
- asicsp 5y agoAfter you enter the email, you'll see "View Content" button on the web page itself. You'll also get an email having the same "View Content" button. From there, you can download PDF/EPUB versions.