Vim Tips Wiki

Open File, Go To Last Line, Add Blank Line, Change To Insert Mode

1,623pages on
this wiki
Add New Page
Add New Page Talk0

I often want to open a note file or log file, go to the last line, add a blank line, then begin entering some text.

It is handy to do all of this from the command line using an alias to call gvim with the -c command option.

alias note="gvim -c $ +foldopen +put_ +startinsert ~/path-to-file/"

This opens the Markdown file, goes to the last line ($), opens any folds, appends a blank line (put_), then starts insert mode.

The command :put_ (: is assumed with -c) inserts the contents of register _ linewise, after the current line. The black hole register (_) contains nothing so the put appends an empty new line.


Thanks for the cleanup! If anyone knows how, I'd like to also add a Markdown header, as in ## at the beginning of that newline? Thanks. Rick

Replacing +put_ with +put='##' or +"normal! o##" should do it. You may need to add a +"normal! $" as well if the cursor position is wrong. --Fritzophrenic (talk) 16:20, June 9, 2015 (UTC)

Also on Fandom

Random Wiki