Assigning to a:current_time is kind of a strange thing to do. The a: space is intended for function arguments. I’m actually surprised Vim allows writing to this at all! It doesn’t work when you’re actually using it as arguments:
In :help a:var it’s mentioned that “The a: scope and the variables in it cannot be changed, they are fixed”, so this actually sounds like a bug(?)
Using local scope l:current_time is much more standard (you don’t actually need a variable there, you can \<C-r>=strftime(..) directly).
You may also want to consider making g:time_stamp_enabled a buffer-local variable, instead of a global one. That way enabling the timestamp insertion will only work on the current buffer, and not that other Python buffer you have or whatnot.
I actually didn’t know about reltime(), so thanks for pointing that out.
However, I think it would add complexity here, rather than remove it. It looks like it would give me better-than-second level precision, so I’d need some code to deal with that extra precision (in my case, just throwing it away) and I think that would more than make up for the savings in terms of computing the relative time.
Still glad I learned about reltime(), though—vim is full of surprises.
That’s too simple for a plugin? I’m definitely not going to write all that code. If left-pad is a npm package, that can definitely be a vim plugin.
Assigning to
a:current_time
is kind of a strange thing to do. Thea:
space is intended for function arguments. I’m actually surprised Vim allows writing to this at all! It doesn’t work when you’re actually using it as arguments:In
:help a:var
it’s mentioned that “The a: scope and the variables in it cannot be changed, they are fixed”, so this actually sounds like a bug(?)Using local scope
l:current_time
is much more standard (you don’t actually need a variable there, you can\<C-r>=strftime(..)
directly).You may also want to consider making
g:time_stamp_enabled
a buffer-local variable, instead of a global one. That way enabling the timestamp insertion will only work on the current buffer, and not that other Python buffer you have or whatnot.Thanks—I didn’t realize that (I’m definitely not a vimscript expert!). I’ll update the code accordingly.
Have you considered using
reltime()
? Then you could just doI actually didn’t know about
reltime()
, so thanks for pointing that out.However, I think it would add complexity here, rather than remove it. It looks like it would give me better-than-second level precision, so I’d need some code to deal with that extra precision (in my case, just throwing it away) and I think that would more than make up for the savings in terms of computing the relative time.
Still glad I learned about
reltime()
, though—vim is full of surprises.