this post was submitted on 26 Oct 2024
637 points (97.0% liked)

Programmer Humor

32375 readers
599 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Ephera@lemmy.ml 71 points 1 week ago (4 children)

Recently had to edit the hosts-file on a remote host, and I don't know if using two proxy jumps to SSH into it broke it, but it just wouldn't let me select text with the mouse.
I had to duplicate seven lines and edit the IP addresses, and without being able to copy-paste, I already saw myself manually typing it out.

Then I remembered that in Vim, you can do d5↓ to delete 5 lines. Surely that would also work with copying/yanking. And yep, a y7↓ and a paste later and I had duplicated the lines.

Then use the multi-line cursor like I routinely do for changing all 7 IP addresses...
...and now I feel like I've crossed the line where people will think I'm just a wizard.

[–] SpaceNoodle@lemmy.world 29 points 1 week ago (4 children)

Ctrl-K and Ctrl-U in nano, a sane editor that does not hate you

[–] eager_eagle@lemmy.world 30 points 1 week ago (3 children)

Ctrl-X Ctrl-V in micro, if you appreciate a sane editor with sane keybindings.

[–] SpaceNoodle@lemmy.world 8 points 1 week ago

That's cool, and I can't wait for it to gain widespread adoption, but nano is already more commonly installed by default.

[–] Blisterexe@lemmy.zip 6 points 1 week ago (2 children)

How does micro compare to nano?

[–] SpaceNoodle@lemmy.world 33 points 1 week ago (1 children)
[–] eager_eagle@lemmy.world 7 points 1 week ago
[–] eager_eagle@lemmy.world 5 points 1 week ago* (last edited 1 week ago) (1 children)

better ootb experience with syntax highlighting, sane keybindings, plugin system, and other little things nano lacks.

[–] SpaceNoodle@lemmy.world 3 points 1 week ago* (last edited 1 week ago) (1 children)

Nano has had syntax highlighting for quite a while.

Its keybindings also make sense if your brain is still stuck in the '90s. If not, they're literally printed at the bottom of the terminal.

If I need plugins, I'm not gonna be fucking around with a terminal text editor.

What are these "other little things?" Certainly not "probably already installed on your system."

[–] eager_eagle@lemmy.world 1 points 1 week ago (1 children)
[–] SpaceNoodle@lemmy.world 1 points 1 week ago

Oh, the irony.

[–] fl42v@lemmy.ml 2 points 1 week ago (1 children)

"Sane" keybindings are questionable given Ctrl's location (painful to press with both pinky and thumb fingers). It's standard, I'll give it that, but those in helix or vim are mostly (I'm looking at you, navigation between splits) much saner all things considered

[–] eager_eagle@lemmy.world 1 points 1 week ago (2 children)

or maps your caps to Ctrl, like vim users map it to esc

[–] fl42v@lemmy.ml 1 points 1 week ago

Or build yourself a crkbd, yeah. That's beside the point.

[–] computergeek125@lemmy.world 1 points 1 week ago

Which is exactly where Sun Unix keyboards place it, in a same spot

[–] mosiacmango@lemm.ee 18 points 1 week ago (1 children)

Vim doesn't hate you. It loves who you could be.

[–] SpaceNoodle@lemmy.world 7 points 1 week ago

I wish I could :q! you

[–] Ephera@lemmy.ml 3 points 1 week ago (2 children)

Doesn't that just cut one line at a time? Or is this Emacs-like, where it buffers the lines?

That host doesn't have internet access, though, so installing a different editor wasn't really an option to begin with...

[–] SpaceNoodle@lemmy.world 5 points 1 week ago

If the host doesn't already have nano, you fucked up super early

But yeah, it buffers the lines.

[–] clb92@feddit.dk 2 points 1 week ago* (last edited 1 week ago)

Doesn’t that just cut one line at a time?

Move the cursor to the start of what you want to cut, press ALT+A, then move the cursor with arrow keys (you'll see text be highlighted from where the cursor was to where you move your cursor), then once you've moved the cursor to where you want, press CTRL+K to cut.

[–] nickwitha_k@lemmy.sdf.org 3 points 1 week ago (1 children)

How do I do regex or connect to an LSP with nano?

[–] SpaceNoodle@lemmy.world 7 points 1 week ago (1 children)

That's the neat part: you don't.

[–] nickwitha_k@lemmy.sdf.org 2 points 1 week ago (1 children)

Fair enough. Those are things that I like to be able to use, however. Which makes nano/pico/micro a non-starter for me. Different strokes for different folks.

[–] SpaceNoodle@lemmy.world 3 points 1 week ago (1 children)

Well, they're not necessary for 99.999% of what you need a quick CLI text editor for.

[–] fl42v@lemmy.ml 1 points 1 week ago

The use-cases for unquick GUI text editors are merely a subset of those solved by quick TUI text editors :P

[–] Coolcoder360@lemmy.world 9 points 1 week ago (3 children)

Just switch to visual mode and select the text and yank it.

Press v where you want to start the selection from (switches to visual mode), hjkl (or arrow keys) to move the cursor to the end, then you can yank it from there. It'll highlight what you're selecting just like you're using your mouse, but you're using the keyboard.

If you want to get really fancy there are 3 different kinds of visual mode, but lower case is the most often one that I use because it's char by char, V is line by line, Ctrl+v is "block" (you can select chunks across several lines omitting things at the beginning or end of lines).

Ctrl+V to do the block mode is nice if you need to edit the same part of several lines that all line up vertically, you just Ctrl+v, jk to select the lines, then I (shift+i) to insert on all those lines (if you're in vim you can delete things in insert mode also, if you're in vi you'll need to delete first then insert)

[–] jaybone@lemmy.world 6 points 1 week ago

Had not heard of block mode. I need to try this.

[–] Ephera@lemmy.ml 3 points 1 week ago

Yeah, when I then used Visual Block mode to do the multi-line cursor, I realized I probably could've selected+yanked it that way, too.

But that is some good info nonetheless. I wasn't actually aware of the different Visual modes...

[–] fl42v@lemmy.ml 2 points 1 week ago (1 children)

y6jjp is generally faster, tho, as long as you know you need exactly 7 lines or happen to have :set nu rnu in your config. Also, if using nvim, having yanks highlighted helps immensely

[–] dQw4w9WgXcQ@lemm.ee 3 points 1 week ago (1 children)

I might be in a minority of this, but using numbers that way breaks my flow for 2 reasons: Firstly, any number of lines greater than around 3 or 4 means I have to stop and manually count. Not that counting to 6 takes a long time, but it does use some mental capacity while I want my mind focused on the actual code. Secondly, I don't have touch typing in my fingers for the number line on my keyboard. If I need to type a number, I either have to look down at my keyboard, or move my hand over to the numpad. In both cases it would be quicker for me to Vjjjjjy.

[–] fl42v@lemmy.ml 2 points 1 week ago

manually count

That's why rnu (i.e. relative numbering) is mentioned, tho

[–] nickwitha_k@lemmy.sdf.org 5 points 1 week ago

I've been using vim as my primary text editor and IDE for near a decade. I forgot that this was a thing so, I've been using visual mode like a peasant.

[–] leisesprecher@feddit.org 4 points 1 week ago (2 children)

The real question is why you're torturing yourself by manually fixing that stuff? Don't you terraform your Ansibles?

[–] JoYo@lemmy.ml 2 points 1 week ago

lol @drudgesentinel@fedi.seriousbusiness.international

[–] Ephera@lemmy.ml 2 points 1 week ago (1 children)

That is a very good question. It all started as a dainty test setup, and I guess, we had lost the routine of always scripting hardware setups, because our previous project hadn't required it.

Obviously, the second-best time to start doing it is now, but I'd need to properly learn one of these first to be able to lead the way on that.
Which collides with me not really wanting to use any of the ones I've experienced so far (Ansible, Puppet) in my freetime. 🫠

[–] leisesprecher@feddit.org 2 points 1 week ago

Ansible is actually pretty nice, if you get the hang of it. Not perfect, but better than triple tunnel ssh.

You could simply automate step by step, each time you change something, you add that to the playbook and over time you should end up with a good setup.

Flakey dev setups are productivity killers.