1

I want to put timestamp using Leaderts (\ts)

I am using the following script timestamp.bat(Windows 7):

@echo off
cls
echo|set /p=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%

and the result should be something like that:

Lorem ipsum.. 2018-02-25 21:43 lorem ipsum..

Unfortunately, when I am in the correct position to put the timestamp, insertion go to one line under. I think it is due to the <cr> character at the begining of output.

How to trim character from output if I have such a command:

nnoremap <leader>ts :r! timestamp.bat<CR>

or

 nnoremap <leader>ts :put =strftime(\"%c\")

Is there other solution to this problem?

  • 3
    Did you try: :nnoremap <leader>ts A<C-R>=strftime('%c')<cr><esc> ? – Christian Brabandt Feb 26 '18 at 9:06
  • It works a little better, but it should put timestamp between text. Right now it adds text at the end of the line. – lluke Feb 26 '18 at 16:51
  • 1
    Use a then instead of A – Christian Brabandt Feb 26 '18 at 19:29
  • Yes, this is exacly what I need :nnoremap <leader>ts a<C-R>=strftime('%c')<cr><esc> – lluke Feb 26 '18 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.