2

I am trying to write a Vim command to append the date to the end of line. Right now I have the following, and it is not working.

nnoremap <F5> "=strftime("%c")<CR>A

What's wrong with this? It just throws me back into insert mode.

2
"=strftime("%c")<CR>A

means "put the date in the expression register then enter insert mode at the end of the line".

Here is what you wanted to do:

nnoremap <F5> A<C-r>=strftime("%c")<CR>

"enter insert mode at the end of the line and use the expression register to insert the date".

Here is another method, I'm sure there are others:

nnoremap <F5> :call setline(".", getline(".") . strftime("%c"))<CR>
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.