5

I've the file, like:

name = foo
# unknown number of lines ...
features_exclude[rules_config][] = rule1 
features_exclude[rules_config][] = rule2 
features_exclude[rules_config][] = rule3 
features_exclude[rules_config][] = rule4

and I'd like to run :/_exclude/s/// command on it and repeat it one more time (@:).

I've tried things suggested in here, however it doesn't work.

So when using @: to repeat the last command-line change, it gives me the error:

E30: No previous command line

So it seems it doesn't recognise what was the previous command line.

Here is example:

$ ex '+:/_exclude/s///p' '+@:' -scwq -V1 foo.txt 
"foo.txt" 
"foo.txt" 10 lines, 375 characters
search hit BOTTOM, continuing at TOP
features[rules_config][] = rule1 

Error detected while processing command line:
E30: No previous command line
"foo.txt" 
"foo.txt" 10 lines, 367 characters written

Why is that? Are there any other reliable ways of repeating the last Ex command?

5

:help E30 states

The command-line is only stored in this register when at least one character of it was typed. Thus it remains unchanged if the command was completed from a mapping.

It seems like Vim is not considering commands specified via + (or -c) to be typed, so ": isn't updated.

I'm not sure if that's expected behavior or just an oversight.

3

I imagine there must be an easier way. Since @: is accessing a special register, you can use registers yourself:

$ vim -Nesc ":let @a = '/_exclude/s///p'" +@a +@a +wq foo    
features[rules_config][] = rule1 
features[rules_config][] = rule2 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.