In VI or VIM, you can insert the current date and time by using the following command:
- Press the
Esc
key to enter normal mode. - Type
:
to enter command mode. - Type
r
followed by the current date and time in the format you want to use. For example, to insert the current date and time in the formatYYYY-MM-DD HH:MM:SS
, use the following command:
:r!date +"%Y-%m-%d %T"
- Press
Enter
. The current date and time will be inserted into the file at the current cursor position.
Note: The !
character before the date
command allows you to run a shell command from within VIM. The date
command is used to display the current date and time, and the +"%Y-%m-%d %T"
option is used to specify the desired format for the output.