« Vim » : différence entre les versions
De Mathux
Aucun résumé des modifications |
Aucun résumé des modifications |
||
(Une version intermédiaire par le même utilisateur non affichée) | |||
Ligne 1 : | Ligne 1 : | ||
== Edit Macro == | |||
The registers are used both for macros and for yank and delete commands. This has some advantages. | |||
Suppose you have recorded a few commands in register <code>n</code>. Then, when you run <code>@n</code>, you notice you did something wrong. You could try recording again, but perhaps you will make another mistake. Instead, use this trick: | |||
* <code>G</code> — Go to the end of the file. | |||
* <code>o<Esc></code> — Create an empty line. | |||
* <code>“np</code> — Put the text from the <code>n</code> register. You now see the commands you typed as text in the file. | |||
* <code>{edits}</code> — Change the commands that were wrong. This is just like editing text. | |||
* <code>0</code> — Go to the start of the line. | |||
* <code>“ny$</code> — Yank the corrected commands into the n register. | |||
* <code>dd</code> — Delete the scratch line. | |||
Now you can execute the corrected commands with <code>@n</code>. | |||
This trick is a great example of the Unix and Vim philosophies: If you know how to modify text, and if everything is made out of text, then you can do anything. | |||
N.b. :From https://sebastiancarlos.com/use-vim-macros-in-your-ide-and-unleash-its-hidden-power-3a17eda8400e | |||
== Configuration == | == Configuration == | ||
Ligne 21 : | Ligne 40 : | ||
"ay / "ap | "ay / "ap | ||
</code> | </code> | ||
== Other == | |||
*Substitute every occurrence of '0' with incremental values: | |||
:let @a=0 | %s/0/\=(@a+setreg('a',@a +1))/g | |||
* Delete all trailing whitespace (at the end of each line) with | * Delete all trailing whitespace (at the end of each line) with | ||
:%s/\s\+$// | :%s/\s\+$// |
Dernière version du 10 mars 2023 à 10:34
Edit Macro
The registers are used both for macros and for yank and delete commands. This has some advantages.
Suppose you have recorded a few commands in register n
. Then, when you run @n
, you notice you did something wrong. You could try recording again, but perhaps you will make another mistake. Instead, use this trick:
G
— Go to the end of the file.o<Esc>
— Create an empty line.“np
— Put the text from then
register. You now see the commands you typed as text in the file.{edits}
— Change the commands that were wrong. This is just like editing text.0
— Go to the start of the line.“ny$
— Yank the corrected commands into the n register.dd
— Delete the scratch line.
Now you can execute the corrected commands with @n
.
This trick is a great example of the Unix and Vim philosophies: If you know how to modify text, and if everything is made out of text, then you can do anything.
N.b. :From https://sebastiancarlos.com/use-vim-macros-in-your-ide-and-unleash-its-hidden-power-3a17eda8400e
Configuration
My configuration files are hosted here. A simplified version (more re-usable) is here
Copy
- Copy into the clipboard
"*y
- Past from the clipboard
"*p
- Copy/Past into/from the register "a"
"ay / "ap
Other
- Substitute every occurrence of '0' with incremental values:
:let @a=0 | %s/0/\=(@a+setreg('a',@a +1))/g
- Delete all trailing whitespace (at the end of each line) with
:%s/\s\+$//