7 ms·
For those who do not understand why people are fanatical about vi, here are some reasons: Vi is keyboard only. This means that actions with the mouse are optim
by nouveaux 6y ago
For those who do not understand why people are fanatical about vi, here
are some reasons:
Vi is keyboard only. This means that actions with the mouse are optimized through the keyboard. There are "hotkeys" for most
tasks you use with a mouse.
Vi has the idea of objects. Words, lines and paragraphs are objects you
can operate on.
Vi defines a "language" for operating on objects. For instance, 'd' is
delete. You can delete a word using 'dw'. You can delete 5 words with
'5dw'. Another example: deleting a line is 'dd'. Delete 5 lines with '5dd'
It is a modal editor. At a basic level there is an "edit" (insert) mode,
a "navigation" (normal) mode, and a "selection" (visual) mode. The power
of a modal environment means that commands and hotkeys now have a context
and do slightly different things in different modes. While this may be
overwhelming, once all these modes are ingrained in you, it allows you to
be extremely efficient since you do not have to remember new hotkeys. For
example, in the navigation mode, you can apply the 5dd to delete 5 lines.
In selection mode, use '5w' to select five words. 'd' now deletes
everything in the selection. If you've ever struggled to manage and
remember your hotkeys, modal environment is your friend. (set this up in
mac using something like hammerspoon.)
It includes some really nice out of the box features: Macro system to save
you time with repetitive tasks, regular expressions search and replace,
time travel through your edits, it stores your edits in a tree so you can
navigate to your changes even after multiple undo/redo. "." repeats the last change. You can also apply a number before it to
repeat the change n number of times. I am surprised how often I use this
that this is and this is first thing I miss when using another editor.
Vi is worth learning as it will improve your productivity. This is
especially important if you have to edit a file on a remote server. Vi is
installed on every unix distribution. Many cli tools and shells have a vi
mode. This allows you to take the vi 'language' to all these cli tools for
more productivity.
For those who struggle to learn, I highly recommend Vim Adventures. After
that, force yourself to use vi for your every day edits and it'll be
second nature in a couple of weeks.
https://vim-adventures.com https://vim-adventures.com
- bdamm 6y agovi also builds its concepts together in a great way. Navigation keys are powerful, but combined with actions, they become monumentally powerful in a way few IDEs seem to replicate well. Something simple like "copy the next 10 lines to the clipboard" is just 10yj or 10Y or even y10j. No awkward reaching for control keys. Now combine those actions into macros and things get really fun. One of the most fun navigation keys is the under-reported "f" key. If the cursor isn't where you want it to be, you can easily put it on the right line (perhaps with 55G or something if you want line 55) and then to move the cursor over the character you are actually looking at you just type f( assuming that ( is the character you want the cursor on. It's just great... it's about having the computer work around your human experience of looking at the screen in a nice way.
- u801e 6y ago> One of the most fun navigation keys is the under-reported "f" key. If the cursor isn't where you want it to be There's also the t key which will place the cursor on the character just before it. There are also the F and T keys that will search backward in the same line and the ; and , keys that allow you jump from character to character in that line. But, if you want more flexibility and the ability to jump across multiple lines, a / or ? search will allow you to select text up to and including the multiple characters you search for.
- bdamm 6y agoThere are so many navigation keys and combinations, that's kind of what is great about it. A lifetime's worth, in the case of vim and neovim. I personally have got a lot of mileage out of f, F, t, T, /, ?, G, 0, W, w, e, E, b, B, }, and %.
- mrlowk 6y agoI have switched to doing most of my work on IDEs like IntelliJ, VSCode, etc and the first plugin I always install is vim keybindings. It makes editing and navigating much better.
- grisha 6y agoI’d also add https://www.vimgolf.com/ https://www.vimgolf.com/ as very powerful way to improve vim skills.
- tgb 6y agoI've always thought that doing 5dd and such was a bad demonstration of Vi(m) since I never know how many lines to delete. I'll just dd multiple times. More powerful vim commands are like daw (delete all of a paragraph), di) (delete inside of a set of parentheses), and dtX (delete until the character X).
- gen220 6y agoMy shorthand when I don’t know the number of lines is dj followed by a bunch of .’s :)
- pletnes 6y agoIf you use relative line numbers, 5dd makes total sense.
- tgb 6y agoI tried this for a while but it never clicked for me. I prefer using semantically-meaningful groupings like paragraphs or parentheses, it just seems nicer. And relative line numbers wouldn't make, say, 5dw any easier to count.
- lenkite 6y agoYou can use: df<char> to delete forward (including char), dt<char> to delete forward until char. (excluding char) d/<search><Enter> to delete until search pattern is found In case you wish to type immediately after deleting, replace 'd' with 'c' in the above.
- leephillips 6y agodaw deletes the word you are in (delete a word). But dap deletes a paragraph. And you can tell vi what you mean by "word" and "paragraph" (I think) in your settings file.
- tgb 6y agoGood catch, I meant dap.
- supernova87a 6y agoUnfortunately, the barrier I faced with even trying VI is that you cannot discover any functionality intuitively. Exaggerating (but just a little) I could not even figure out how to type without someone giving me a tutorial. That was enough to make me stop.
- gen220 6y agoI agree. You need to use vimtutor to get the basics: the simplest modes (insert, normal), the simplest normal-mode motions (hjkl), the simplest normal-mode actions (d, c, f/t), and the concept of "adverbs" (8j, 4dw, 2df]). Once you have mastered these simple concepts, most of the magic comes from (1) combining them (2) googling the things that you intuitively know must be possible, and discovering how they're done, which in turn gives you more basic concepts. At that point, your feedback loop gives you escape velocity, and you'll never willingly go back to a standard text editor again. :) Getting escape velocity is really tough, though.
- derekp7 6y agoFor me, learning came when I was on an IBM RT/PC (pre RS-6000), in something like 90 or 91. I used IBM's editor from the console, but one time I had to edit something from a terminal back in the shop. Which didn't have full support for the IBM editor (Ined I think it was called), due to the way the keyboard was mapped. Something about left cursor was the same as backspace (ctrl-h). Well, that did it -- I went back to my desk, and pulled up vi-tutor.txt, then never looked back.
- gfodor 6y agoWhen given a tradeoff between intuitivity and other benefits, vi almost always breaks against intuitivity. It's this design philosophy taken to its logical extreme.
- appleflaxen 6y agoThere's a better fit than "intuitive" Vim is extremely intuitive in its compositional behavior; I have never used "67w", but I know exactly what it would do because of composition. I think "discoverability" is closer.
- zerr 6y agoWhat I observe is that most vim fans who swear by it use it as a bare bones editor, syntax highlighting at most. No auto-completion, go to definition or any other IDE stuff. Yes, it is possible to make vim IDE-like but very few do so.
- acqq 6y agoThe existence of "modes" is also opposite to the approach which is know for decades to be less prone to accidental errors: having no modes and always being able to perform more undo steps. There were even the games of considering what plain text typed in wrong mode would cause the most of the damage. The main reason Vim and Emacs have their current followers is that the competing editors on Linux or Unix platforms are significantly worse (on average), not that these two are by any means any kind of the possible optimum. And boy, is the competition worse. (Personally, I use console editors only if I have to, and then prefer to use vim, but otherwise I prefer my customized low-footprint programmable GUI.)
- nouveaux 6y agoThe power that vim has out of the box is pretty incredible. The macro system is very easy to use and powerful. That said, it is hard to learn all these features and modern GUI IDEs are pretty amazing. You can still use vi in many of these editors.
- u801e 6y ago> The existence of "modes" is also opposite to the approach which is know for decades to be less prone to accidental errors: having no modes and always being able to perform more undo steps. vim has had the multi-level undo and redo for a number of years. If I really screw up, I can always run something like :earlier 5m to get back to the state I was at 5 minutes ago. The only problem I have with some of the normal mode keystrokes is when I want to use some of the window based shortcuts and accidently press ctrl-w while my browser window is open (which closes the tab) :)
- gen220 6y agoI used to be like you describe, mostly because language-specific plugins were a dumpsterfire of hidden complexity, that really slowed down your editing experience. While some plugins are brilliantly-designed, it takes a long time to learn how to configure one language plugin to your tastes, and that learning is generally non-transferable to other language plugins. (vim-go fits this to the T, ime). https://github.com/dense-analysis/ale https://github.com/dense-analysis/ale (along with the language-server movement in general) changed my perspective. I now do at least the go-to and autocomplete half of IDE things, now.
- deleted 6y ago[deleted]
- sacks2k 6y ago"This is especially important if you have to edit a file on a remote server" This may have been true a decade ago, but editors like Visual studio code now have remote editing abilities over SSH. I regularly have 50+ files open at a time for editing/compiling and I've never found editors like VI very helpful. If I need to make a quick edit to a config file, it does the job.
- aftbit 6y agoI'd love to hear more about this. What VS Code plugin are you using to accomplish edits over SSH? I checked out Remote Development, but it is actively unable to function with the open-source version of VSCode: https://github.com/VSCodium/vscodium/issues/240#issuecomment-521692835 https://github.com/VSCodium/vscodium/issues/240#issuecomment...
- stnmtn 6y agoSomething that I always find lacking in these discussions is that the VIM evangelists never mention the way that I use vim: strictly as a keyboard-only editor plugin. I tried using vim-only setups but there's so much configuring and weird things. Nothing to me has worked as great as my current VSCode + Vim plugin setup. It's the best of both worlds, as I get the quite frankly absurd speed improvements of VIM while also the great user-friendliness and ease of VScode
- nouveaux 6y agoVSCode is great and has a lot of advantages. I still use vim in a terminal because of tmux. Unfortunately that means I have to give up some of vscode's advantages.
- kmarc 6y agoNow imagine that SSH going from a Citrix windows desktop running on a Windows 10 VM on your linux laptop. Every key press reacts in around a second. Welcome to banking "security"! Now let's say I want to `d5}`, to delete the next 5 paraghraph. In vi(m) I can do this by telling it "hey vim, delete those 5 damn paragraph!" In fancy VScode I have to say more like... "Hey editor, wait a sec, I'm moving my cursor over there and select a couple lines which happens to be 5 paragrahs, OOOPS, I went a bit too far, now let's go back. YES, now delete them!". Other examples: - "increment this number by 5" - "delete this html tag recursively" - "indent the next 20 lines" - "remove all the arguments from this function call" - etc. Vim has a language, _that_ is the powerful part. To be fair, thankfully VSCode (and any of the other fancy IDEs) have basic vim-functionality providing plugins.
- Scarbutt 6y agoMany of those features are Vim features and not Vi correct?
- nouveaux 6y agoYes. I believe vim and neovim is what most people use these days.
- shortlived 6y ago>> Vi defines a "language" for operating on objects. And the objects are text-centric (word, sentence, etc). Add on top of that a powerful macro system, and you get a really powerful tool for text manipulation.
- HanP77 6y agoI've been coding for a bit more than two years, then I decided to finally learn vim. I honestly don't know how I did before, it's just so satisfying! It's not even as hard as they say. +1 for vim adventure, definitely great learning ressources!
- k4ch0w 6y agoBind your caps lock to ctrl+left/esc too. It's so much better than reaching for esc/ctrl all the time.
- u801e 6y agoI do use CAPS LOCK from time to time when typing. I find that using ctrl-[ works (left pinky for ctrl and right pinky for [) for me.