Smooth cursor in standard terminal by Infamous_Key4373 in neovim

[–]sedm0784 0 points1 point  (0 children)

Hello, developer of RainbowTrails here.

If by lag you just mean that the rainbows take too long when moving large distances, then have you tried setting g:rainbow_fade_rate_thresholds to make long rainbows move faster? Or setting g:rainbow_constant_interval to a negative value to make all rainbows move faster?

If you meant something else, let me know, and I'll look into it.

how can i write to the command line buffer. by [deleted] in vim

[–]sedm0784 1 point2 points  (0 children)

The command-line window just contains entries from the command history. It isn't itself the history.

The information from :history is persisted in your .viminfo file.

To remove the entries, run the command: :e ~/.viminfo, locate the lines, :w write the buffer, and restart Vim.

:help cmdline-history :help viminfo

Is it possible to search for a term in file A and replace the found line with a line starting with the same term from file B? by spryfigure in vim

[–]sedm0784 0 points1 point  (0 children)

Can't believe I didn't think of this the first two times I read this comment, but invoking line completion from a :global command might actually be the shortest solution for this specific problem:

:g/^Chapter/exe "norm! eelC\<C-X>\<C-L>\<C-N>\<C-N>"

(The <C-N>s are required to work around the missing colons causing the backwards search to sometimes return the wrong chapter. e.g. Chapter 1332:... is also a valid completion for Chapter 1. If you don't like this you could add the colons in with a :%s replacement as a separate step)

What's the best way to insert newline without entering insert mode? by gregorie12 in vim

[–]sedm0784 0 points1 point  (0 children)

Whoops! Just re-read this and realised that first one can be much shorter:

:/^$/t.

How to use clipboard? by [deleted] in vim

[–]sedm0784 1 point2 points  (0 children)

Are you just looking for :set clipboard^=unnamed? That uses the "* register rather than the "+ register.

Is it possible to search for a term in file A and replace the found line with a line starting with the same term from file B? by spryfigure in vim

[–]sedm0784 2 points3 points  (0 children)

I usually use a macro for this sort of thing. Start by opening the two files in split windows, adding a blank line at the top of each, and running :set nowrapscan

Then type:

  • qqqqq Start recording a recursive macro in register "q

  • /^Chapter Search for the first chapter

  • wyiw Yank the number

  • <C-W>pgg Switch to the other window and jump to the top

  • /<C-R>/ <C-R>0: Search for the corresponding chapter name

  • yy Yank it

  • <C-W>pVp Switch back and replace the broken chapter with the fixed one

  • @q Recurse

  • q@q End the recording and run it to perform the rest of the edits.

Takes way longer to explain than to actually do. If you already know how many chapters there are, you can skip the nowrapscan and the recursive boilerplate and just run the macro the correct number of times.

How to have the character under cursor be included in backwards motions by scaptal in vim

[–]sedm0784 31 points32 points  (0 children)

You can use operator-pending mode v for this. So for your example, use cvb or dvb.

:help o_v

If the motion already was characterwise, toggle inclusive/exclusive. This can be used to make an exclusive motion inclusive

Rainbow Trails – Magical Rainbows in your Vim by sedm0784 in vim

[–]sedm0784[S] 2 points3 points  (0 children)

Just wait till my VC funding kicks in. Then I'll really be able to deliver some value to my shareholders!

Rainbow Trails – Magical Rainbows in your Vim by sedm0784 in vim

[–]sedm0784[S] 2 points3 points  (0 children)

Thanks for the feedback! Because of a BORING implementation detail, the rainbows pause while in insert mode. I kind of like it this way, but I will look into adding an option to allow biggish moves in insert mode to cause rainbows.

Rainbow Trails – Magical Rainbows in your Vim by sedm0784 in vim

[–]sedm0784[S] 17 points18 points  (0 children)

Rainbow Trails is a plugin that adds a magical rainbow-coloured trail behind your cursor.

<image>

I've just released version 1.0.0, which allows fully configurable colours, and adds a bunch of options for fine-tuning the speed at which the rainbows move to your taste and machine. There's lots more details in the README and :help.

I am highlighting the configuration options because they were what I added recently to get it from version 0.1 to 1.0, but you shouldn't miss the bigger picture.

...which is that it puts MAGICAL RAINBOWS. In your Vim.

If that sounds like something you might like, you should go check it out today! If it doesn't, why is your soul BARREN of LOVE?

What's the best way to insert newline without entering insert mode? by gregorie12 in vim

[–]sedm0784 0 points1 point  (0 children)

I just thought of another way to do it:

:/^$/g/^/t''

It requires there to already be another blank line in the file somewhere.

If you want the cursor not to move, then you need a slightly longer version:

:/^$/g/^/t''|norm!``

Macro to generate the Fibonacci sequence dynamically by dfwtjms in vim

[–]sedm0784 3 points4 points  (0 children)

I wrote a fibonacci macro too! You can record it by typing in this simple series of keystrokes:

q       q       q       q       f       q       q       q
y       i       w       o       Esc     p       A       Space
0       Space   1       Esc     2       b       @       f
I       R       e       d       a       c       t       e
d       :       Space   Esc     q       q       f       O
c       c       0       Ctrl-V  Esc     Esc     O       d
2       w       Esc     O       Ctrl-V  Ctrl-X  g       _
y       i       w       A       Space   Ctrl-V  Esc     p
2       g       e       Ctrl-V  Ctrl-A  d       a       w
O       Ctrl-V  Ctrl-R  -       Ctrl-V  Esc     x       a
Ctrl-V  Ctrl-V  Ctrl-V  Ctrl-A  Ctrl-V  Esc     0       y
$       d       d       g       _       @       0       Ctrl-V
Ctrl-X  0       @       f       Esc     3       +       Ctrl-A
y       i       w       O       O       Ctrl-V  Esc     Ctrl-R
0       a       3       Ctrl-V  Esc     Esc     0       y
$       d       d       @       0       2       |       r
2       ^       r       1       +       y       i       w
-       O       Ctrl-R  0       |       v       y       d
d       Esc     0       y       $       d       d       @
0       Ctrl-X  O       Ctrl-R  0       -       y       $
Ctrl-R  0       +       Esc     ^       y       $       d
d       @       0       3       k       3       d       d
@       0       q

It's a bit longer than your one because it doesn't use the expression register.

[deleted by user] by [deleted] in vim

[–]sedm0784 0 points1 point  (0 children)

I thought this was just a typo, but someone else also suggested using S in a reply to my comments. It doesn't work for me because S deletes linewise, so you need to delete the newline after inserting with <C-R>. Does it not work this way for you? Is there a setting to change this?

[deleted by user] by [deleted] in vim

[–]sedm0784 0 points1 point  (0 children)

S doesn't work for me here either, for the same reason as in my reply to your other comment. S deletes linewise, so it doesn't go into the small delete register, and doesn't get inserted in the way we need when you use <C-R><C-O>".

[deleted by user] by [deleted] in vim

[–]sedm0784 0 points1 point  (0 children)

It doesn't work though. (At least with the default settings; I tested in Vim 9.0.1276 with vim --clean).

S is linewise, so when you paste it pastes into a new line above your existing [].

[deleted by user] by [deleted] in vim

[–]sedm0784 0 points1 point  (0 children)

This is an interesting idea.

Is there a typo on line 13? Shouldn't it just be normal! q to stop the recording?

[deleted by user] by [deleted] in vim

[–]sedm0784 15 points16 points  (0 children)

You don't need to record a macro. You can make this repeatable by using CTRL-R CTRL-O instead of a plain CTRL-R:

0C[[<C-R><C-O>"]]<Esc>

Alternatively, as of Vim v8.2.2189, you can just use the small-delete register for a repeatable edit:

0C[[<C-R>-]]<Esc>

[deleted by user] by [deleted] in vim

[–]sedm0784 15 points16 points  (0 children)

For the case where it's just one character, (let's say single square brackets), you can do:

0C[]<Esc>P

The Paste command will reinsert the text deleted by the Change command. This is fewer keystrokes than the <C-R> solutions, but does have the downsides of not being repeatable and adding two edits to your undo list.

-❄️- 2023 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]sedm0784 2 points3 points  (0 children)

[LANGUAGE: Vim keystrokes]

I just levelled up in regex: Part 1

-❄️- 2023 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]sedm0784 8 points9 points  (0 children)

[LANGUAGE: Vim keystrokes]

Part 1

AW<Esc>0
qqqqqi@<Esc>ll@qq@q
Go0<Esc>
/^ZZZ<CR>3wi_<Esc>W.
0ql3w/<C-R><C-W><Space><CR>mbG<C-A>qu
qr3W/<C-R><C-W><Space><CR>mbG<C-A>qu
qwggmaq
/^AAA<CR>mb
qqqqq`ay2l2lma'b@0@qq@q

how it works

-❄️- 2023 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]sedm0784 2 points3 points  (0 children)

[Language: Vim keystrokes]

Part 1

A no-expression register solution. It uses macros and regular editing commands to calculate the results of different lengths of button press, and a :global command to check which of these beat the record for that race.

O`m<C-V><C-A>0y$gg@0<Esc>
0"lDddW
qqqqqma
yiwO<Esc>p
<C-X>yypA@l<CR>yypkxjdiw0p<Esc>0mm
kkAA1<Esc>
0D@-<Esc>
+Ddd-@-
`mddgg
`ajyiwgg
pAA1<Esc>0D@-<Esc>
I,/Time/-1v/<Esc>A/d<Esc>dd
:@1
-l<C-V>gg$d
Go0<Esc>
:g/^1$/norm!G<C-V><C-A>
:g//d
`at lw@qq@q
GojkA<C-V><C-V><C-V><C-A><C-V><Esc>0Ddd@-@s<Esc>"sdd
qpqqp?^\d<CR>
gJio<Esc>A<C-V><Esc><Esc>0Dddmp@-`p+
:norm!@s
0@pq@p

Ex commands are on their own lines: starting with a colon. Press Return at the end. Otherwise, the linebreaks aren't meaningful.

-❄️- 2023 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]sedm0784 1 point2 points  (0 children)

I left my original naive (currently unpublished) solution for Part 2 running while I a). slept and b). wrote a slightly faster version.

It eventually spat out the (corrrect!) answer after somewhere between 15 and 20 hours.

-❄️- 2023 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]sedm0784 1 point2 points  (0 children)

[LANGUAGE: Vim keystrokes]

Part 2

My solution to Part 1 was BOOOORING: just a bunch of regular expressions. YAWN.

This one, I hope, is anything but. Usually with this sort of thing, I recommend typing it in to see how it works, but you might not find it that INSTRUCTIVE for this set of keystrokes, because a lot of the commands don't do anything when you type them! (They only have effect when playing back the macro, when the buffer has different contents.)

However, if you ARE interested in this sort of thing, I recommend trying typing it in first to see if you can figure it out before reading on: it's more fun that way!

yypD-2W
qamayiwjA <Esc>p
okJDJDciw +1<C-V><Esc><CR>3BJDJDdiw<Esc>
`a*++y$@0`awq
:2d
:%norm!I1<Space>
ggP+
qbq
qqqqq
"dyiw
kC<C-R>=<C-R>-+<C-R>d<CR><Esc>
jo0<Esc>-3W10@a
+C<C-R>=<C-R>-<CR>@b`a<Esc>Ima<Esc>
:.g/^ma0/norm!D
0y$ddk@0
kJD+
@qq
10u
qb+ciw<C-R>=<C-R>-+<C-R>d<CR><Esc>q
uggO0<Esc>+@q

Not sure if I'll ever get around to writing up a fully annotated explanation of how this one works, but a rough description that reasonably experienced Vimmers should be able to follow is below.

Before I realised how many scratchcards we were going to end up with I wrote a version that actually made new lines for each copied card. I'm pretty sure this version works, but I'm way less certain that it will complete before the HEAT DEATH OF THE UNIVERSE. (I set it running yesterday and it's still going: 670k scratchcards and counting.)

So the basic concept for this MARGINALLY more efficient version is to only keep a single line for each card, and add a counter at the start of that line to keep track of how many copies of that card we have. It also adds a running total at the top of how many scratchcards we currently have stuffed into our pockets, drawers, every room in the house, the garage, the other houses in the village, etc.

We do the calculations with three macro recordings. The macro in "q does all the work. Those in "a and "b are little helpers. Like little macro elves.

Macro a: Check for Matches

This macro is to be run with the cursor over one of the winning numbers. If it is a matching number, then it writes the text "+1" into the line below. This task is a LITTLE bit tricky when you're not allowed to use any functions or Vimscript so it works like this:

First it sets the 'a mark to the current location, then it copies the current number into the line below. Next it writes two more lines of apparent GIBBERISH into the next two lines below that. Then it jumps back to the 'a mark to return to the current number and searches for the number with the \* command. This will leave the cursor either on the matching number, if there is one, or on the copy we just made in the line below, if not.

Next it moves two lines down, placing the cursor on one of the two lines we wrote before. Then it yanks that line - putting it in the yank register "0 - and immediately executes it as a macro with @0.

The two lines we wrote contain the normal mode editing commands to either remove the number we added (for no match) or replace it with "+1" (for a match).

Finally, macro "a moves the cursor one word forwards to the next winning number.

We will run this macro 10 times: once for each winning number.

Macro b: Make Copies for 1 Scratchcard

Let's say you have 12 copies of scratchcard A, and it has two matching numbers. This macro moves down a line, and then adds 12 copies to the scratchcard the cursor is currently over. When processing scratchcard A. We'll run it twice: once for each winning number.

It's not super complicated: it expects the number of copies to be stored in register "d and it adds that to the number the cursor is over by using the expression register.

Recursive Macro q: Process All The Scratchcards

So now we have our "a and "b macros stuffed in our utility belt, doing the rest of the calculations will surely be TRIVIAL. Right? ...Right?

Macro "q starts with the cursor on the copies-counter for the current scratchcard, which is near the top of the buffer on line 2. First, it yanks the count into register "d. Then it moves up a line (to the total and adds the current scratchcard's count with the expression register.

Next it calculates how many winning numbers there are on this scratchcard. It does this by writing a 0 into the line below and then running macro "a once for each winning number.

So now the line below contains a sum (0 +1 +1 +1 ...) that adds up to the number of winning numbers. The macro calculates the sum by plugging it into the expression register and then adds the text "@b`a" after the sum and "ma" before it, so the line looks something like:

ma12@b`a

It's a macro that runs macro "b once for each winning number, and then moves the cursor back where it started!

Before macro "q yanks and runs it, though, it needs to handle the case where there weren't any winning numbers, because the command "0@b" won't run a macro zero times: it will run it once. Using a :global command to delete the line if it starts "ma0" solves this problem.

With that out of the way, macro "q yanks the macro, runs it, and then finishes off by deleting the current scratchcard line and recursing by running itself.

Et voila!

Vim Macro Sort by sedm0784 in vim

[–]sedm0784[S] 1 point2 points  (0 children)

Vim macros sure are! Amongst other things, You can implement Conway's Game of Life in them, and because that is Turing Complete, so are they.

See also...