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.
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 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.
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.
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. 🫠
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.
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.
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)
Had not heard of block mode. I need to try this.
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…
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 immenselyI 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
.That’s why
rnu
(i.e. relative numbering) is mentioned, thoI’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.
The real question is why you’re torturing yourself by manually fixing that stuff? Don’t you terraform your Ansibles?
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. 🫠
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.
lol @drudgesentinel@fedi.seriousbusiness.international