I want insert the timestamp in the current line without ruin the content in that line. I've read this post. Basically it suggests:1). !r date which insert on the next line; 2). !!date which clear current line and insert the timestamp.
All you have to do is mapping F3:
inoremap <special> <F3> <c-r>=strftime('%c')<CR>
With this way whenever you press F3 button it will insert timestamp at current position during insert-mode.
[i][noremap] [<special>] [<F3>] [<c-r>=strftime('%c')<CR>]
| | | | |
| | | | |
| | | | |---> Whenever you press <F3> button it
| | | | |---> will execute this part
| | | | |---> it is like pressing ctrl-r
| | | | |---> then pressing = and typing
| | | | |---> strftime('%c') and then
| | | | |---> typing enter (<cr>) for execution
| | | |
| | | |---> The key that you want to map
| | |
| | |----> This argument is for avoiding side effect of 'cpoption'
| |
| |-----> The mapping (noremap) is not recursive
| |
| |-----> It means that it doesn't care about other mappings
|
|---------> (i) for insert-mode (n) for normal-mode (c) for command-mode ...
For more see :help map.txt
iab idate <c-r>=strftime("%c")<cr>
No need to use any shortcut, just type "idate" or any other word of your choice (iab stands for insert mode abbreviation)
If you have ultisnips plugin you can create a snippet like this:
snippet date "use tab to insert date" w
`date +%Y-%m-%d\ %H:%M` ${0}
endsnippet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With