I have a template being used like so:
autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py
But earlier in my autocommands the cursor position is being set which annoyingly moves the cursor to the end of file in this vimwiki diary template. So I want to set it to a particular position.
Can I do something like :6<Enter>
at the end of my BufNewFile
command to then move the cursor to line#6?
Something like:
autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py && exe :6<Enter>
or maybe
autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py
\ normal 6gg|zt
or something else?
Is it possible to combine these two actions together?
solution: adding | normal 6G
instead of bash-like &&...
at the end of the autocmd works. And it can even be simply done with | 6
.
BufReadPost
applies there... (Update: It's probably through the:filetype detect
.) But, still, how will Vim have a location for the'"
mark if the file is new? Perhaps setting the mark (withnormal! m"
or similar) from theBufNewFile
would be a good approach.BufReadPost
does not apply here? I don't know why vim always puts the cursor at the end of the file here, I assumed it was because of how the template created the new file somehow emulated a cursor-position, but that's just my ignorant guess.augroup templates
... to theautocmd BufNewFile
? How does that get done? I don't know who commands can be combined like that.:read
command, Vim will leave the cursor at the end of the input that was read. Nevertheless, just setting the cursor after reading the input should be enough. Ben's solution below should work.