Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add mapping and command to insert current date #1413

Open
fancsali opened this issue Jun 15, 2024 · 3 comments
Open

[feature] Add mapping and command to insert current date #1413

fancsali opened this issue Jun 15, 2024 · 3 comments

Comments

@fancsali
Copy link

I often need to insert the current date, to create a log of events on wiki pages other than the diary. For this, I thin it'd be great if we had a shortcut to avoid typing the same date all over again, if one has many projects running in parallel.

@qadzek
Copy link
Contributor

qadzek commented Jun 23, 2024

I'm not sure if this feature is directly related to Vimwiki, but you could try an abbreviation:

inoreabbrev cdate <C-r>=strftime("%F")<CR>

@tinmarino
Copy link
Member

tinmarino commented Jun 23, 2024

Hi, thank you @qadzek for sharing your snippet. It is pretty nice and usefull. One should never have to enter today's date by hand on a computer.

I agree to add it to Vimwiki. But it may take time to accepted a default keymap, accept it and merge.

So I would advice users to have their own map or abbrv like @qadzek in their vimrc (PS: I just did it myself lol, it is such a nice abbrv).

@qadzek
Copy link
Contributor

qadzek commented Jun 24, 2024

@tinmarino Happy to make your vimrc a little longer 😄

In this case, I feel like an abbreviation makes more sense than a mapping, as you are probably in insert mode when wanting to add a date. That's a personal choice of course.

Let me share this one as well, if you want to add a timestamp like 09:47:36 (mnemonic: Current TIME):

inoreabbrev <expr> ctime strftime("%T")

The <expr> syntax is a bit nicer than the <C-r> used above.

To avoid inserting a trailing space after expanding the abbreviation, I use this

" See :helpgrep Eatchar
function! Eatchar(pat)
  let l:c = nr2char(getchar(0))
  return (l:c =~ a:pat) ? '' : l:c
endfunc

inoreabbrev cdate <C-r>=strftime("%F")<CR><C-r>=Eatchar('\s')<CR>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants