Last active
May 3, 2025 12:30
-
-
Save crh0831/37e657384052ce7a64bbea7ffd6de437 to your computer and use it in GitHub Desktop.
Vim function to insert datestamp with <leader>m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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