Reputation: 161884
After reading the vim doc about *:bar* *:\bar*
:
'|'
can be used to separate commands, so you can give multiple commands in one line.
I tried to clear history via this command:
:set history=0 | set history=20
I expect that, these two commands should be executed one by one, and the history should be cleared.
But it didn't. The history still there, and a new history was added.
Then I tried:
:set history=0
:set history=20
It works.
Why?
Upvotes: 1
Views: 114
Reputation: 53654
When you execute a command line that is what happens:
init_hist()
function call in getcmdline()
).getcmdline()
).add_to_history()
call in getcmdline()
).do_one_cmd()
in do_cmdline()
, happens after getcmdline()
call (called by getexline()
passed as fgetline
argument to do_cmdline()
)).Setting the option itself does nothing, it only changes p_hi
variable. Actual modification of history is done at step 1.
Now let’s see what happens in both cases (assuming that you typed second or third additional command):
p_hi
has old value, then it is changed two times and then when you do next command it is already set to 20
.p_hi
has old value, then it is changed once and initialized for the second time, being effectively truncated at this step and only then the value changes again. By the time you start typing third command it is already wiped out.Thus your assumption (commands are executed one by one) is true, but you have mistaken at which point history modification happens. I would rather suggest using histdel()
as @Michael advised because, at first, it clears history by itself and, at second, it does not have hardcoded 'history' value. I can’t say how you live with just 20 lines long history (I’ve set it to 65535 and am always sure I won’t lose anything small, but useful), but hardcoding this value will make changing history size to something else more painful.
Upvotes: 7