Issue
I often create new files with the name of today's date. So, I would like to make this a command that calls the shell date
command. The date
command I use is:
class="lang-bash prettyprint-override">date +%Y-%m-%d-%B%d).md
I tried to call this same shell command from within Vim with this custom command in my .vimrc
:
command Post e !date +%Y-%m-%d-%B%d.md
But that doesn't work because %
means the current filename in Vim and the desired filename isn't created.
Solution
You can use the built-in :help strftime()
function instead of the date
command. This makes the command a little bit more portable and, since the function is evaluated before :edit
is executed, you don't get the unwanted side-effects of :help cmdline-special
.
:command! Post execute 'edit ' .. strftime('%Y-%m-%d-%B%d') .. '.md'
Answered By - romainl Answer Checked By - Katrina (WPSolving Volunteer)