Lowest number of keystrokes to modify part of a line

8 views
Skip to first unread message

Ottavio Caruso

unread,
Nov 1, 2022, 6:50:13 AM11/1/22
to vim...@googlegroups.com
Hi,

I'm Italian hence knowingly lazy.

I have a file that I use as a log for my morse learning.

The structure is:


qrq Wed 26/10 11:18
Groups Thu 27/10 20:00
WT Thu 27/10 21:37
qrq2 Thu 27/10 10:24
morse Fri 28/10 20:17
qrq Fri 28/10 22:15
Groups Sat 29/10 19:46
WT Sat 29/10 21:21
qrq2 Sun 30/10 18:48
morse Sun 30/10 22:07[x]
qrq Mon 31/10 10:19
Groups Mon 31/10 19:42

See that [x]? That's where the cursor is.

I want to modify the line just below that (starting with qrq), remove
that timestamp and put a new one.

The timestamp is mapped to 'mydate' :

$ grep mydate .vim/vimrc
iabbrev mydate <C-R>=strftime("%a %d/%m/%Y")

I want to find the lowest number of keystrokes I need to modify that
timestamp.

What I'm doing at the moment is:

[w] [w] [R] cwd [:wq]

That is: one word forward, one word forward, Replace to the end; save
and quit, but I wonder if there is a lazier and more elegant way.

M. v. g.


--
Ottavio Caruso

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Tim Chase

unread,
Nov 1, 2022, 9:37:46 AM11/1/22
to 'Ottavio Caruso' via vim_use
On 2022-11-01 10:50, 'Ottavio Caruso' via vim_use wrote:
> morse Sun 30/10 22:07[x]
> qrq Mon 31/10 10:19
> Groups Mon 31/10 19:42
>
> See that [x]? That's where the cursor is.
>
> I want to modify the line just below that (starting with qrq),
> remove that timestamp and put a new one.

My first thought is to map a key to do a substitution using
sub-replace-special like

nnoremap Q :s@ \<lt>\zs.*@\=strftime("%a %d/%m/%Y")<cr>

or, if you always do this from the line above, you can add a "+"

nnoremap Q :+s@ \<lt>\zs.*@\=strftime("%a %d/%m/%Y")<cr>

which, while it has more keystrokes initially to create, reduces
the "update the timestamp on the next line" to a single keypress
("Q" in this instance, but whatever you want to map it to).

(also, it looks like your strftime() format string differs from the
format in the existing data, so tweak accordingly)

-tim

Reply all
Reply to author
Forward
0 new messages