From 8a4e26c6fe7530a0e24268cd373f0d4e53fe81e1 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Tue, 17 Aug 2021 15:56:37 +0200 Subject: feat(autocmd): add Recording autocmds feat(eval): add reg_recorded() This function is used the get the last recorded register. style(Recording): rename handler to match suggestions fix(RecordingLeave): send autocommand earlier This makes the autocommand fire just before setting reg_recorded to reg_recording, this way we clearly show that we are actually just before actually quitting the recording mode. --- runtime/doc/autocmd.txt | 8 ++++++++ runtime/doc/eval.txt | 6 ++++++ runtime/doc/intro.txt | 4 ++-- runtime/doc/repeat.txt | 3 +++ runtime/doc/vim_diff.txt | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 242631d98c..3cdf979e54 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -828,6 +828,14 @@ RemoteReply When a reply from a Vim that functions as SearchWrapped After making a search with |n| or |N| if the search wraps around the document back to the start/finish respectively. + *RecordingEnter* +RecordingEnter When a macro starts to be recorded. + The pattern is the current file name, and + |reg_recording()| is the current register that + is used. + *RecordinLeave* +RecordingLeave When the is the end of a macro recording. + The pattern is the current file name. *SessionLoadPost* SessionLoadPost After loading the session file created using the |:mksession| command. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 75b782fbff..0e002179e3 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2588,6 +2588,7 @@ readdir({dir} [, {expr}]) List file names in {dir} selected by {expr} readfile({fname} [, {type} [, {max}]]) List get list of lines from file {fname} reg_executing() String get the executing register name +reg_recorded() String get the last recorded register name reg_recording() String get the recording register name reltime([{start} [, {end}]]) List get time value reltimefloat({time}) Float turn the time value into a Float @@ -7825,6 +7826,11 @@ reg_executing() *reg_executing()* Returns an empty string when no register is being executed. See |@|. +reg_recorded() *reg_recorded()* + Returns the single letter name of the last recorded register. + Returns an empty string string when nothing was recorded yet. + See |q|. + reg_recording() *reg_recording()* Returns the single letter name of the register being recorded. Returns an empty string string when not recording. See |q|. diff --git a/runtime/doc/intro.txt b/runtime/doc/intro.txt index a89263861b..0e0156ac6b 100644 --- a/runtime/doc/intro.txt +++ b/runtime/doc/intro.txt @@ -563,8 +563,8 @@ The command CTRL-\ CTRL-G or can be used to go to Insert mode when make sure Vim is in the mode indicated by 'insertmode', without knowing in what mode Vim currently is. - *gQ* *Q* *mode-Ex* *Ex-mode* *Ex* *EX* *E501* -Q or gQ Switch to Ex mode. This is like typing ":" commands + *gQ* *mode-Ex* *Ex-mode* *Ex* *EX* *E501* +gQ Switch to Ex mode. This is like typing ":" commands one after another, except: - You don't have to keep pressing ":". - The screen doesn't get updated after each command. diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index 7e8d93aa71..60e9b6bed4 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -147,6 +147,9 @@ q Stops recording. *@@* *E748* @@ Repeat the previous @{0-9a-z":*} [count] times. + *Q* +Q Repeat the last recorded register [count] times. + *:@* :[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex command. First set cursor at line [addr] (default is diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index bc59ea785e..154b18add7 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -218,6 +218,7 @@ Input/Mappings: Normal commands: |gO| shows a filetype-defined "outline" of the current buffer. + |Q| replays the last recorded macro. Options: 'cpoptions' flags: |cpo-_| -- cgit From 684c782546c04c453a12376bd5d6f57da3948235 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Fri, 1 Oct 2021 09:40:22 +0200 Subject: docs(autocmd): update docs to match implementation docs(reg_recorded): add links to relevant docs docs(Recording): update docs to match implementation docs(Q) update references of Q to be gQ docs(autocmd) add description about state of reg_record{ing,ed} for RecordingLeave docs(vim_diff) add Recording{Enter,Leave} to features docs(index) removed duplicate gQ docs(options) removed line about gQ erroring in visual mode Update runtime/doc/vim_diff.txt Co-authored-by: zeertzjq docs(vim_diff) removed double mention of Q --- runtime/doc/autocmd.txt | 12 ++++++++---- runtime/doc/eval.txt | 4 ++-- runtime/doc/index.txt | 2 +- runtime/doc/options.txt | 1 - runtime/doc/quickref.txt | 3 ++- runtime/doc/repeat.txt | 3 ++- runtime/doc/vim_diff.txt | 6 ++++-- 7 files changed, 19 insertions(+), 12 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 3cdf979e54..3df8d5ced4 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -829,13 +829,17 @@ SearchWrapped After making a search with |n| or |N| if the search wraps around the document back to the start/finish respectively. *RecordingEnter* -RecordingEnter When a macro starts to be recorded. +RecordingEnter When a macro starts recording. The pattern is the current file name, and |reg_recording()| is the current register that is used. - *RecordinLeave* -RecordingLeave When the is the end of a macro recording. - The pattern is the current file name. + *RecordingLeave* +RecordingLeave When a macro stops recording. + The pattern is the current file name, and + |reg_recording()| is the recorded + register. + |reg_recorded()| is only updated after this + event. *SessionLoadPost* SessionLoadPost After loading the session file created using the |:mksession| command. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 0e002179e3..aef303195d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -7202,7 +7202,7 @@ mode([expr]) Return a string that indicates the current mode. Rvc Virtual Replace mode completion |compl-generic| Rvx Virtual Replace mode |i_CTRL-X| completion c Command-line editing - cv Vim Ex mode |Q| or |gQ| + cv Vim Ex mode |gQ| r Hit-enter prompt rm The -- more -- prompt r? A |:confirm| query of some sort @@ -7829,7 +7829,7 @@ reg_executing() *reg_executing()* reg_recorded() *reg_recorded()* Returns the single letter name of the last recorded register. Returns an empty string string when nothing was recorded yet. - See |q|. + See |q| and |Q|. reg_recording() *reg_recording()* Returns the single letter name of the register being recorded. diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index baa7bc1992..d8689e2c65 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -339,7 +339,6 @@ tag char note action in Normal mode ~ insert text, repeat N times |P| ["x]P 2 put the text [from register x] before the cursor N times -|Q| Q switch to "Ex" mode |R| R 2 enter replace mode: overtype existing characters, repeat the entered text N-1 times @@ -401,6 +400,7 @@ tag char note action in Normal mode ~ |q| q{0-9a-zA-Z"} record typed characters into named register {0-9a-zA-Z"} (uppercase to append) |q| q (while recording) stops recording +|Q| Q replay last recorded macro |q:| q: edit : command-line in command-line window |q/| q/ edit / command-line in command-line window |q?| q? edit ? command-line in command-line window diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 097cd38400..b75dd78b57 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -953,7 +953,6 @@ A jump table for the options with a short description can be found at |Q_op|. error Other Error occurred (e.g. try to join last line) (mostly used in |Normal-mode| or |Cmdline-mode|). esc hitting in |Normal-mode|. - ex In |Visual-mode|, hitting |Q| results in an error. hangul Ignored. insertmode Pressing in 'insertmode'. lang Calling the beep module for Lua/Mzscheme/TCL. diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index 8cabf05053..a229c8742f 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -489,6 +489,7 @@ In Insert or Command-line mode: |q| q{a-z} record typed characters into register {a-z} |q| q{A-Z} record typed characters, appended to register {a-z} |q| q stop recording +|Q| Q replay last recorded macro |@| N @{a-z} execute the contents of register {a-z} (N times) |@@| N @@ repeat previous @{a-z} (N times) |:@| :@{a-z} execute the contents of register {a-z} as an Ex @@ -997,7 +998,7 @@ Short explanation of each option: *option-list* |:version| :ve[rsion] show version information |:normal| :norm[al][!] {commands} execute Normal mode commands -|Q| Q switch to "Ex" mode +|gQ| gQ switch to "Ex" mode |:redir| :redir >{file} redirect messages to {file} |:silent| :silent[!] {command} execute {command} silently diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index 60e9b6bed4..c7481ad290 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -103,7 +103,7 @@ Which is two characters shorter! When using "global" in Ex mode, a special case is using ":visual" as a command. This will move to a matching line, go to Normal mode to let you -execute commands there until you use |Q| to return to Ex mode. This will be +execute commands there until you use |gQ| to return to Ex mode. This will be repeated for each matching line. While doing this you cannot use ":global". To abort this type CTRL-C twice. @@ -149,6 +149,7 @@ q Stops recording. *Q* Q Repeat the last recorded register [count] times. + See |reg_recorded()|. *:@* :[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 154b18add7..4fcaf15717 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -180,6 +180,8 @@ Commands: |:match| can be invoked before highlight group is defined Events: + |RecordingEnter| + |RecordingLeave| |SearchWrapped| |Signal| |TabNewEntered| @@ -218,7 +220,6 @@ Input/Mappings: Normal commands: |gO| shows a filetype-defined "outline" of the current buffer. - |Q| replays the last recorded macro. Options: 'cpoptions' flags: |cpo-_| @@ -357,7 +358,8 @@ Motion: The |jumplist| avoids useless/phantom jumps. Normal commands: - |Q| is the same as |gQ| + |Q| replays the last recorded macro instead of switching to Ex mode. + Instead |gQ| can be used to enter Ex mode. Options: 'ttimeout', 'ttimeoutlen' behavior was simplified -- cgit