Skip to content

Instantly share code, notes, and snippets.

@crh0831
Last active May 3, 2025 12:30
Show Gist options
  • Save crh0831/37e657384052ce7a64bbea7ffd6de437 to your computer and use it in GitHub Desktop.
Save crh0831/37e657384052ce7a64bbea7ffd6de437 to your computer and use it in GitHub Desktop.
Vim function to insert datestamp with <leader>m
" Vim mapping to insert the day and date as a header for notes, journals etc
function! InsertFormattedDate()
let day = strftime("%d")
let suffix = "th"
if day =~# "^02\\\|2\\\|22$"
let suffix = "nd"
elseif day =~# "^01\\\|1\\\|21\\\|31$"
let suffix = "st"
elseif day =~# "^03\\\|3\\\|23$"
let suffix = "rd"
endif
let datestring = strftime("%A ") . strftime("%B ") . day . suffix . strftime(" %Y")
put =datestring
silent! s/ 0/ /
normal! kJi##
endfunction
map <Leader>m :call InsertFormattedDate()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment