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.
“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
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.
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)
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
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.
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, ay7↓
and ap
aste 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.
Ctrl-K and Ctrl-U in nano, a sane editor that does not hate you
Ctrl-X Ctrl-V in micro, if you appreciate a sane editor with sane keybindings.
“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
That’s cool, and I can’t wait for it to gain widespread adoption, but nano is already more commonly installed by default.
How does micro compare to nano?
It’s 1,000 times larger.
oh, you…
better ootb experience with syntax highlighting, sane keybindings, plugin system, and other little things nano lacks.
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.”
How do I do regex or connect to an LSP with nano?
That’s the neat part: you don’t.
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.
Well, they’re not necessary for 99.999% of what you need a quick CLI text editor for.
The use-cases for unquick GUI text editors are merely a subset of those solved by quick TUI text editors :P
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…
If the host doesn’t already have nano, you fucked up super early
But yeah, it buffers the lines.
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)
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 immenselyHad not heard of block mode. I need to try this.
The real question is why you’re torturing yourself by manually fixing that stuff? Don’t you terraform your Ansibles?
lol @[email protected]
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.