0

I keep a sys.md file where I record a dated entry of every modification I make to my system (mostly installations of software, sometimes configuration changes) and based on an old Hacker News link about a did file I came up with the idea of an alias that would auto-insert the date and set me up with exactly the prompt I want for an entry to sys.md.

This command opens my sys.md file and inserts the date and the bottom:

nvim +'normal Go' +r!date' ~/notes/sys.md

I want to copy that line, paste it below, replace it with -'s as a markdown h2 heading, insert a new line and begin it with a dash-space -_ to start a bullet.

yypVr-o-_

However,

nvim +'normal Go' +'r!date' -c 'yypVr-o-_' ~/notes/sys.md

does not work. How can I auto-execute those commands?

5
  • 6
    You mean something like this: vim +'$pu_|r!date' +'norm yypVr-o-_' foo.txt? I think you are missing your :normal command. See :h :norm Aug 22, 2018 at 21:59
  • @PeterRincker If you'd put that as an answer I'll accept it. It worked.
    – mas
    Aug 23, 2018 at 12:46
  • @PeterRincker: what does the $pu_ do?
    – mas
    Aug 23, 2018 at 14:01
  • I had to eliminate $pu_ from the command and reform it as nvim +'normal Go' +'r!date' +'yypVr-o-_' ~/notes/sys.md Because the BASH aliasing system didn't like your $pu_, but the +'norm <commands>' synax was what I was looking for anyway. Thank you!
    – mas
    Aug 23, 2018 at 14:03
  • 1
    Using :put with the black hole register, "_, will create a blank line. Providing a range of $ will mean we put a blank line at the end of the file. See :h :range, :h quote_, and :h :put Aug 23, 2018 at 14:09

1 Answer 1

2

yypVr-o-_ are not ex-commands, but normal. Use :normal to execute normal commands.

vim +'normal Go' +'r!date' +'yypVr-o-_' ~/notes/sys.md

For more help see:

:norm
:h -c
:h :r!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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