The “remote” feature of flash.nvim is handy: it acts in “operator pending mode” to perform operations and then return to the original position. It took me some time to understand what it was doing, so I’m writing about it.
I’m using it in the LazyVim distribution, which enables “flash” by default (and also “which-key”, which is the window showing possible commands to complete the sequence).
Let’s take this buffer (note the current position of the cursor):
Let’s assume I want to copy (“yank”) the line containing “the very first…”. I press “y”, which goes into “operator pending mode”:
Then “r” for “remote flash”, and start typing something in that line, e.g., “location”; I type “l”,
Labels appear in the occurrences (remember that with “flash”, you should look at the word you want to jump to while you’re typing); in this example, a single letter allows you to have useful labels for jumping to the desired occurrence. You might need to type a few more letters in more complex files. I press the label corresponding to the occurrence of “location” in the interested line (“h”)
The cursor temporarily goes to the desired occurrence of “location”; then, I press “a” for around:
Finally, “p” for “paragraph”. Now the desired line has been yanked, and the cursor automatically goes back to the original position:
I could then paste the line there, for example.
Let’s see another example with “d” for deleting a remote line.
Let’s see the starting point, in particular, the current cursor position on line 18:
Let’s say I want to delete the word “very” a few lines above.
I enter “operator pending mode” with “d”
Then “r” for “remote flash”, and start typing “very”; I type “v”,
Labels appear in the occurrences (remember that with “flash”, you should look at the word you want to jump to while you’re typing), and press the label corresponding to the occurrence of “very” in the interested line (“d” in this case)
The cursor temporarily goes to the desired occurrence of “very”; then, I press “a” for around:
Finally, “w” for word. The “very” word is removed, and the cursor automatically goes back to the original position:
Try to do the same with “c” for change, to change something in a “remote” location and automatically return to where you were.
Pretty useful! 🙂