David Woodfall wrote:

I would like to make a command that would insert at cursor todays date,
and also a command to insert some custom text.

In the help file it shows how to make a keybind to do this but I would
rather use a command - eg :date
I typically use insertion mode maps:

imap <Leader>ymd    <C-R>=strftime("%y%m%d")<CR>
imap <Leader>mdy    <C-R>=strftime("%m/%d/%y")<CR>
imap <Leader>ndy    <C-R>=strftime("%b %d, %Y")<CR>
imap <Leader>hms    <C-R>=strftime("%T")<CR>

However, you've stated that you wish to insert a date using a command. User commands must begin with a capital letter, so ":date" isn't going to work, but ":Date" could.

So, here's a conversion of the imaps into commands:

com! YMD :norm! i<C-R>=strftime("%y%m%d")<CR>
com! MDY :norm! i<C-R>=strftime("%m/%d/%y")<CR>
com! NDY :norm! i<C-R>=strftime("%b %d, %Y")<CR>
com! HMS :norm! i<C-R>=strftime("%T")<CR>

Note that these commands insert the date before the cursor. To substitute *after* the cursor,
change the "norm! i..." to "norm! a...".

I'm afraid that you need to choose to insert before or append after the cursor, not "insert at" the cursor.

Regards,
Chip Campbell

Reply via email to