News for hackers. Stuff that matters.
Re:My Favorite Vim Oneliners for Text Manipulation by drtz on Saturday August 05, 2023 @11:03PM (#37018599)
I once did a lunch and learn at work where I tried to teach coworkers how to use vim efficiently. It turned out to be the absolute worst lunch and learn I ever did.

It's just so unintuitive and trying to teach it in a "here are some good shortcuts that will save you time" way was a near-total waste.

vim is the closest any editor comes to interfacing directly with my brain. Once you learn to make your neurons fire in the right way to move the cursor to the right spot, it's easy and there's no better way to edit code. Describing the neuron firing order to someone else, though, is futile.

It's like learning to to use your fingers to pick something up for the first time as a kid: you just have to try enough times until it sticks.

Re:My Favorite Vim Oneliners for Text Manipulation by arcanemachiner on Saturday August 05, 2023 @11:47PM (#37018818)
> vim is the closest any editor comes to interfacing directly with my brain.

It's funny you mention that. Just today, I had this moment where I realized that if someone asked me which key letters are used to move up/down/left/right, I'd have to pause and think about it.

I've been using Vim for years. Like, my index finger rests on the down key, so J is down. I think? And so on... My middle finger rests on the up key, so K goes up? Do I actually have to move my index finger to go left? What is my pinky doing most of the time?

It's just funny how all this stuff is burned into my brain but I wouldn't even be able to tell someone the basics without a keyboard in front of me.

Re:My Favorite Vim Oneliners for Text Manipulation by tylerhou on Sunday August 06, 2023 @12:26AM (#37018972)
j goes down because it looks like a down arrow.
Re:My Favorite Vim Oneliners for Text Manipulation by jolmg on Sunday August 06, 2023 @01:35AM (#37019261)
https://en.wikipedia.org/wiki/ADM-3A#Legacy

> The use of the HJKL keys for moving the cursor in the vi editor and its descendants originated from the ADM-3A [...] The ←, ↓, ↑, → and Home labels printed on the H, J, K, L, and ~ ^ keys were a visual reference to the control characters Ctrl+H, Ctrl+J, Ctrl+K, Ctrl+L, and Ctrl+~ ^ that were required to move the cursor left, down, up, right, and to the top/left corner (or "Home" position) of the terminal, respectively [...] The Ctrl+H and Ctrl+J functions were the standard ASCII backspace and line feed respectively, but the interpretations of Ctrl+K, Ctrl+L, and Ctrl+~ ^ were new to the ADM-3A.

Seems almost a happy accident. I personally like the placement because the most common movement in a document is down and it's placed right under the most dextrous finger, the index finger, by a coincidence between ASCII encoding and QWERTY layouts. Up being the second most common movement was put under the second most dextrous finger. Nice.

Re:My Favorite Vim Oneliners for Text Manipulation by yjftsjthsd-h on Sunday August 06, 2023 @01:37AM (#37019273)
It really is funny how much vi's odd-looking key choices aren't odd at all once you see the keyboard it was developed on:)
Re:My Favorite Vim Oneliners for Text Manipulation by gjvc on Sunday August 06, 2023 @12:48PM (#37023871)
The value of being taught something by an expert.
Re:My Favorite Vim Oneliners for Text Manipulation by tylerhou on Sunday August 06, 2023 @02:25AM (#37019480)
I didn't know about the history, thanks for sharing!

(j = downarrow was a mnemonic I used while learning vim.)

Re:My Favorite Vim Oneliners for Text Manipulation by semi-extrinsic on Sunday August 06, 2023 @03:59AM (#37019873)
Here is a direct link to the ADM-3A keyboard layout:

https://en.wikipedia.org/wiki/ADM-3A#/media/File:KB_Terminal...

Re:My Favorite Vim Oneliners for Text Manipulation by woleium on Sunday August 06, 2023 @05:06PM (#37026765)
Great, now I want a "here is" key
Re:My Favorite Vim Oneliners for Text Manipulation by arcanemachiner on Sunday August 06, 2023 @02:41AM (#37019541)
I just looked down at my keyboard... The letter 'j' has been rubbed off.
Re:My Favorite Vim Oneliners for Text Manipulation by taneq on Sunday August 06, 2023 @08:34AM (#37021274)
None of the keys on my keyboard have markings on them. :D
Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Sunday August 06, 2023 @02:45PM (#37025221)
Just worn out from use, or do you have a Das keyboard, the kind with blank keycaps?

I knew a developer who had one.

https://en.m.wikipedia.org/wiki/Das_Keyboard

Re:My Favorite Vim Oneliners for Text Manipulation by taneq on Sunday August 06, 2023 @08:15PM (#37028394)
Das Keyboard, yep.
Re:My Favorite Vim Oneliners for Text Manipulation by quickthrower2 on Sunday August 06, 2023 @11:23PM (#37029698)
Let me guess: Dvorak
Re:My Favorite Vim Oneliners for Text Manipulation by gsich on Sunday August 06, 2023 @12:27AM (#37018975)
easy, the arrow keys.
Re:My Favorite Vim Oneliners for Text Manipulation by Izkata on Sunday August 06, 2023 @02:42AM (#37019547)
> so J is down. I think? And so on... My middle finger rests on the up key, so K goes up?

Nope, j is down. J combines the current line with the next line, reducing whitespace between to 1 space.

Back when I first figured out what J was doing (having typo'd it regularly) I thought it was useless, then one day I just started reflexively using it when manipulating function arguments.

Likewise, k is up, K looks up the word under the cursor in a man page.

Re:My Favorite Vim Oneliners for Text Manipulation by pxeger1 on Sunday August 06, 2023 @03:03AM (#37019613)
I think they were using uppercase to make the keys stand out, but they know they're not used with the shift key.
Re:My Favorite Vim Oneliners for Text Manipulation by d-lisp on Monday August 07, 2023 @02:58AM (#37031136)
For their defence, keyboards are annotated with uppercase letters.
Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Sunday August 06, 2023 @06:39AM (#37020659)
>Nope, j is down. J combines the current line with the next line, reducing whitespace between to 1 space.

And so J stands for Join (the next line to the current line), IIRC.

Re:My Favorite Vim Oneliners for Text Manipulation by byttemos on Sunday August 06, 2023 @03:58AM (#37019865)
Pretty novice Vim user here. I FOR SURE think about it, and it costs me quite a bit of brain power to navigate. I made my own way pf remembering:

H = the leftmost key, so left L = the rightmost key, so right J = jeet (yeet), so down K = klimb (climb), so up

I look forward to the day this is just burned into my subconscious, but until then, this works I suppose

Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Sunday August 06, 2023 @04:22AM (#37019990)
That's exactly the reason the keys were assigned that way. Pat yourself on the back, kid ;-)
Re:My Favorite Vim Oneliners for Text Manipulation by fsckboy on Monday August 07, 2023 @02:47AM (#37031051)
exactly the reason starting with ^H is backspace (left) and ^J is linefeed (down)
Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Monday August 07, 2023 @05:56PM (#37041504)
Ha ha, good one.

Does the analogy hold for ^M which is carriage return?

Anyway, I remember that stuff. Had a lot of "fun" on Unixes back in the day using things like ^J, ^M, ^H, stty sane, stty -a, stty icrnl, stty onlcr (or is it the other way around), fiddling with termcap and terminfo, and much more ...

Re:My Favorite Vim Oneliners for Text Manipulation by Lio on Sunday August 06, 2023 @04:03AM (#37019887)
It's even weirder for me as I use the Colemak keyboard layout.

When I first switched to Colemak, around 2010, I remapped the movement keys so that they were in the same physical location as hjkl on qwerty.

Then I realised I'd lost compatibility with other readline based software. So I just learned to use the new, not particularly ergonomic, positions under Colemak.

At this point it's almost always from muscle memory now and couldn't tell you what I press half the time.

Vim is like the Great Glass Elevator, it has a button for moving in every direction and using it since the 90s has been like learning to play a musical instrument.

Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Sunday August 06, 2023 @04:19AM (#37019980)
>Vim is like the Great Glass Elevator, it has a button for moving in every direction

Actually vim is more like the Great Glass Elevator cum Excavator, because it has buttons and levers (to extend your simile) for moving in every direction and performing operations of every kind, and most importantly, all sorts of combinations of the two:

>https://news.ycombinator.com/item?id=37018215

So, if tomorrow, either more movements or more operations were added to vim, they would automatically play well with the older ones.

This is orthogonality (1), and genius, IMO :)

(1) As they mean in microprocessor ISA design (, I think, not being a hardware guy, but have just read about it a little here and there, while doing assembly language programming years ago).

Re:My Favorite Vim Oneliners for Text Manipulation by fsckboy on Monday August 07, 2023 @02:45AM (#37031041)
>Vim is like the Great Glass Elevator, it has a button for moving in every direction

vim is like the Great Glass Elevator, if the Great Glass Elevator was modal

Re:My Favorite Vim Oneliners for Text Manipulation by fragmede on Sunday August 06, 2023 @08:24AM (#37021215)
Passwords are the same way for me. I can type my password on a keyboard, but if I have to enter it on my phone, I have no idea what it actually is. Thankfully, a password manager deals with most of my passwords but there is a few that I don't use it for.
Re:My Favorite Vim Oneliners for Text Manipulation by arp242 on Sunday August 06, 2023 @04:26PM (#37026273)
A few weeks ago I was unsure of my PIN code because I got it wrong on the first try, the keypad somehow seemed different (I was getting cash, which I don't often do), and I just completely blanked. I got something from a store and paid by PIN there to make sure I got the right code, and then got my cash.

I've had the same PIN code for over 20 years.

Re:My Favorite Vim Oneliners for Text Manipulation by Aperocky on Sunday August 06, 2023 @12:51AM (#37019077)
I think all quick learning session of vim invariably turns into bootcamp style "learning to code". Jumps straight into what but not how and why.

To know what modal editing is and understand that first is going to help - but then your learning session is over like that without teaching any "tricks".

Re:My Favorite Vim Oneliners for Text Manipulation by linsomniac on Sunday August 06, 2023 @12:52AM (#37019082)
I like to think of vim as bytecode for text manipulation. You train your brain to emit the bytecode via your fingers.
Re:My Favorite Vim Oneliners for Text Manipulation by vram22 on Sunday August 06, 2023 @07:30AM (#37020897)
Ha ha. Vimcode, though.

And "vim" is pretty close to "vm" for virtual machine that runs that vimcode, or bytecode :)

Re:My Favorite Vim Oneliners for Text Manipulation by chongli on Sunday August 06, 2023 @12:53AM (#37019086)
Yeah, I think you'd have the same issue trying to teach people to play guitar over the lunch hour. It takes a lot of practice to learn vim but it's super rewarding once you do!
Re:My Favorite Vim Oneliners for Text Manipulation by hnlmorg on Sunday August 06, 2023 @01:47AM (#37019320)
I know exactly what you mean. At work people constantly ask me what keys do what and the moment they do my mind goes completely blank. To the point that I even forgot how to use vim for a short while until the conscious part of my brain is preoccupied with something else and suddenly I can use vim again.
Re:My Favorite Vim Oneliners for Text Manipulation by ecf on Sunday August 06, 2023 @02:07AM (#37019415)
The issue with Vim for me is that it takes years for the keybinds to be picked up as muscle memory. Learning takes effort, people can’t learn everything. And there’s an endless amount of things I can learn other than Vim that will give me a more fulfilling life.
Re:My Favorite Vim Oneliners for Text Manipulation by TheGreatCabbage on Sunday August 06, 2023 @05:07AM (#37020210)
In my case, it only took a few months to be more effective with Vim than without it. Since I spend most of my time working, Vim is a great improvement to my quality of life. The benefits of Vim include not just productivity, but also comfort.
Re:My Favorite Vim Oneliners for Text Manipulation by FreshStart on Sunday August 06, 2023 @08:12AM (#37021136)
It helps to design the yourself in neovim?
Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Monday August 07, 2023 @06:07PM (#37041610)
I think it's more of a needed mental shift than years or effort that is the stumbling block.

You don't need to pick up a lot of keybinds in order to be fairly productive at text editing in vim.

The extra stuff will just make you more productive, maybe asymptomatically.

Re:My Favorite Vim Oneliners for Text Manipulation by fuzztester on Monday August 07, 2023 @11:01PM (#37043999)
>asymptomatically

Heh, dang autocorrect or me, not sure.

I meant asymptotically.

Re:My Favorite Vim Oneliners for Text Manipulation by _the_inflator on Sunday August 06, 2023 @03:11AM (#37019640)
As a side note: "Lunch and learn" is work for me. I have a strikt rule, that whenever someone talks heavily about work at lunch, I consider it a meeting - just as "lunch and work". Therefore I will take a work break afterwards.

Lunch is !work for me.

Re:My Favorite Vim Oneliners for Text Manipulation by wycy on Sunday August 06, 2023 @06:18AM (#37020585)
Agreed completely. “Lunch and learns” and “brown bags”. I didn’t appreciate my old employer frequently co-opting my lunch breaks with more work.
Re:My Favorite Vim Oneliners for Text Manipulation by erfgh on Sunday August 06, 2023 @05:50AM (#37020430)
It's just different keyboard shortcuts than the other editors. That is pretty much it. You don't need to be so dramatic.

Also, in the GUI version of vim you have scrollbars, toolbar, and the standard keyboard shortcuts work, too. So you can use it like any other editor.

Re:My Favorite Vim Oneliners for Text Manipulation by quickthrower2 on Sunday August 06, 2023 @11:26PM (#37029711)
You can get vim simulators in most editors too. Even Emacs. The interesting question becomes whether you still prefer VIM as an editor. One advantage is you can use the same editor over SSH. If it is not there it is quick to install.
Re:My Favorite Vim Oneliners for Text Manipulation by gjvc on Sunday August 06, 2023 @05:54AM (#37020465)
You're a bad teacher. No shame in that.
Re:My Favorite Vim Oneliners for Text Manipulation by slim on Sunday August 06, 2023 @11:30AM (#37022991)
OTOH watching someone else use vim when you already know the basics of vim is enlightening
Re:My Favorite Vim Oneliners for Text Manipulation by systemvoltage on Sunday August 06, 2023 @12:37PM (#37023751)
Disagree. This article is not a good example. You have to teach the verbs. Then let people solve problems using those verbs.

If you give one liners like the article, it’s useless.