Vim Tips - Convert Unix Date to a Human Readable Date
Related to:: Vim - Date and Time Manipulation
I have a shell history file that logs all the commands I do on my terminal with a timestamp.
The problem is that the timestamp is in Unix format.
Example of my history file:
...
: 1702041549:0;brew install gh
: 1702041563:0;gh auth login
: 1702041669:0;gh copilot
: 1702041760:0;brew install gh beta
: 1702041784:0;brew install gh@beta
...
Then I had to search some commands by a specific date, and instead of coping the Unix date and pasting it into some online conversion tool, I selected the lines that I needed to search and applied the following command in Vim:
'<,'>s/\([0-9]\+\)/\=strftime('%c', submatch(1))
This converted all the Unix dates with Human Readable dates, making my search much easier.
...
: Fri Dec 8 10:19:09 2023:0;brew install gh
: Fri Dec 8 10:19:23 2023:0;gh auth login
: Fri Dec 8 10:21:09 2023:0;gh copilot
: Fri Dec 8 10:22:40 2023:0;brew install gh beta
: Fri Dec 8 10:23:04 2023:0;brew install gh@beta
...