News for hackers. Stuff that matters.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @01:19PM (#23093697)
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

Re:Bill Joy's greatest gift to man – the vi editor (2003) by bdamm on Wednesday May 06, 2020 @01:43PM (#23094011)
vi 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by u801e on Wednesday May 06, 2020 @11:32PM (#23099424)
> 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by bdamm on Thursday May 07, 2020 @10:12AM (#23103164)
There 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 %.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by supernova87a on Wednesday May 06, 2020 @02:05PM (#23094315)
Unfortunately, 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by gen220 on Wednesday May 06, 2020 @02:20PM (#23094503)
I 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by derekp7 on Wednesday May 06, 2020 @09:01PM (#23098452)
For 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by gfodor on Wednesday May 06, 2020 @03:45PM (#23095446)
When given a tradeoff between intuitivity and other benefits, vi almost always breaks against intuitivity. It's this design philosophy taken to its logical extreme.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by appleflaxen on Thursday May 07, 2020 @06:28AM (#23101491)
There'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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @06:10PM (#23096942)
I understand the frustration since even as a veteran users of Vim, there are lots I do not know about.

Vi is a completely different way of thinking. I would compare it to learning to program. When you first start, there isn't very much that is discoverable. You just have to sit through the learning. Once you do, you have access to a lot of power.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by mrlowk on Wednesday May 06, 2020 @01:49PM (#23094092)
I 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by tgb on Wednesday May 06, 2020 @01:57PM (#23094218)
I'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).
Re:Bill Joy's greatest gift to man – the vi editor (2003) by leephillips on Wednesday May 06, 2020 @02:29PM (#23094597)
daw 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by tgb on Wednesday May 06, 2020 @08:03PM (#23098012)
Good catch, I meant dap.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by pletnes on Wednesday May 06, 2020 @02:06PM (#23094316)
If you use relative line numbers, 5dd makes total sense.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by tgb on Wednesday May 06, 2020 @02:14PM (#23094428)
I 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by lenkite on Saturday May 09, 2020 @02:28AM (#23122748)
You 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by ecnahc515 on Wednesday May 06, 2020 @04:03PM (#23095631)
Also to add to this, dt/pattern_string_here is really handy for deleting until the occurrence of some pattern.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by gen220 on Wednesday May 06, 2020 @02:15PM (#23094440)
My shorthand when I don’t know the number of lines is dj followed by a bunch of .’s :)
Re:Bill Joy's greatest gift to man – the vi editor (2003) by mikelward on Wednesday May 06, 2020 @04:44PM (#23096073)
I prefer Vim's visual mode (Shift+V) for that.

But yes, `dap` and friends are options too.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by grisha on Wednesday May 06, 2020 @01:56PM (#23094189)
I’d also add https://www.vimgolf.com/ as very powerful way to improve vim skills.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by HanP77 on Wednesday May 06, 2020 @04:40PM (#23096032)
I'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!
Re:Bill Joy's greatest gift to man – the vi editor (2003) by shortlived on Wednesday May 06, 2020 @04:26PM (#23095866)
>> 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by sacks2k on Wednesday May 06, 2020 @03:08PM (#23095018)
"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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by kmarc on Wednesday May 06, 2020 @03:27PM (#23095228)
Now 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by gruturo on Thursday May 07, 2020 @01:05PM (#23105335)
> Now 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"!

Oh god are you one of my colleagues?

Re:Bill Joy's greatest gift to man – the vi editor (2003) by Redoubts on Wednesday May 06, 2020 @08:38PM (#23098290)
So if you have an incredibly shitty setup, and have no idea how vscode works, then it might be worth it. Got it.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by kmarc on Thursday May 07, 2020 @02:32AM (#23100319)
I have a quite good setup, in general.

Unfortunately this is some external requirement I cannot do anything about. Also, as opposed to many people, I actually got to work and know both the IDE-world (including VScode), and the vim world. I have a base for comparison.

Hopefully you "got that" too.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by u801e on Wednesday May 06, 2020 @11:37PM (#23099451)
There are also times when the available bandwidth is limited, so just having to use fewer keystrokes to edit a file speeds up the process. I was able to connect to remote linux servers over dial-up and edit files on those servers with vim without issue. Editing and saving over ssh was more of a hassle since it took longer to save the file (and I save pretty often).
Re:Bill Joy's greatest gift to man – the vi editor (2003) by wbkang on Wednesday May 06, 2020 @05:29PM (#23096532)
vscode remote will actually perform better than vim over laggy ssh because the UI portion is completely local.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by kmarc on Thursday May 07, 2020 @02:37AM (#23100336)
So it is with vim.

Anyway, unfortunately given setup won't even be viable with anything running "local", since in the mentioned citrix environment we cannot install anything, so no vscode, no local vim, no nothing...

Re:Bill Joy's greatest gift to man – the vi editor (2003) by stnmtn on Wednesday May 06, 2020 @03:22PM (#23095176)
Something 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

Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @06:18PM (#23097030)
VSCode 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by aftbit on Wednesday May 06, 2020 @03:22PM (#23095173)
I'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...

Re:Bill Joy's greatest gift to man – the vi editor (2003) by byte1918 on Wednesday May 06, 2020 @03:32PM (#23095292)
> This may have been true a decade ago, but editors like Visual studio code now have remote editing abilities over SSH.

VS Code and vi have different use cases. Contrary to what you said, most people are not going to open VS Code to make a quick edit to a config file. If that works for you, fine, but the overhead of starting electron is significant.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @06:16PM (#23097003)
You are right that it is not as necessary as before but there are still plenty of times where vi was still the faster option. Since Vi is so lightweight, opening large files remotely might be useful vs vscode remote ssh.

But yea vscode remote is really good.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by zerr on Wednesday May 06, 2020 @02:30PM (#23094609)
What 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by u801e on Wednesday May 06, 2020 @11:39PM (#23099460)
> No auto-completion, go to definition or any other IDE stuff.

vim has had those features for many years now, so I'm not sure why people wouldn't make use of those features unless they aren't aware of them.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by j2kun on Wednesday May 06, 2020 @11:46PM (#23099498)
Tags! I do wish I knew how to use that feature better...
Re:Bill Joy's greatest gift to man – the vi editor (2003) by acqq on Wednesday May 06, 2020 @02:55PM (#23094899)
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.

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.)

Re:Bill Joy's greatest gift to man – the vi editor (2003) by u801e on Wednesday May 06, 2020 @11:42PM (#23099472)
> 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) :)

Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @06:25PM (#23097108)
The 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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by gen220 on Wednesday May 06, 2020 @06:08PM (#23096917)
I 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 (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.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by cercatrova on Wednesday May 06, 2020 @11:08PM (#23099272)
Have you tried language server implementations like coc.nvim? They seem to be superior to ale and others that don't use the Language Server Protocol.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by gen220 on Wednesday May 06, 2020 @11:18PM (#23099326)
I know some people at work use it, but I haven’t gotten around to trying it. What’s the advantage over using ale to compose gopls or python-language-server? Is it the fancy windows? :)

I took a cursory look at their repo. I might be understanding this incorrectly, but it looks like you have to run node as a sidecar to use it? Isn’t that really intensive vs ALE? I figure if I wanted to run V8, one might as well use VSC, which after all is an electron app. :)

Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @06:22PM (#23097066)
Yea the dark side of Vim is that it is at best IDE light. With coc, it has gotten better but still far behind vscode.

It is a trade off I gladly accept to use vim and tmux. Aside from that, vim plugin for vscode is pretty good for doing pair programming with the team.

Re:Bill Joy's greatest gift to man – the vi editor (2003) by k4ch0w on Wednesday May 06, 2020 @08:34PM (#23098264)
Bind your caps lock to ctrl+left/esc too. It's so much better than reaching for esc/ctrl all the time.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by u801e on Wednesday May 06, 2020 @11:34PM (#23099437)
I 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.
Re:Bill Joy's greatest gift to man – the vi editor (2003) by Scarbutt on Wednesday May 06, 2020 @04:02PM (#23095624)
Many of those features are Vim features and not Vi correct?
Re:Bill Joy's greatest gift to man – the vi editor (2003) by nouveaux on Wednesday May 06, 2020 @06:26PM (#23097115)
Yes. I believe vim and neovim is what most people use these days.