0

I have the following function which opens a new file in vim but I want to insert a line of text into the first line of the new file.

function journ(){
  datestring=`date +"%Y-%m-%d - %H%M%S - Rx2_Px -"`
  notev $datestring Journal
}

notev calls this function:

function notev() {
    vim "$*.md"
}

I want the first line of the file to read:

# name_of_file

2
  • What is notev? Commented Apr 2, 2017 at 9:05
  • @merlin2011: see amended question. Commented Apr 2, 2017 at 9:18

2 Answers 2

2

You can use the + flag to execute arbitrary Ex commands:

function notev() {
    vim "$*.md" +normal\ i"# $*.md"
}
Sign up to request clarification or add additional context in comments.

1 Comment

@romaini: that was exactly what I was looking for. Thank you.
1

It seems that the easiest solution is to pipe the data to the file and then start vim.

function notev() {
    echo "# $*.md" >> "$*.md"
    vim "$*.md"
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.