I'd like to use ftplugin/mail.vim
to execute a normal command after opening an email in Mutt.
Specifically, when replying to an email, I'd like move the cursor after the header fields (I have set edit_headers
in my muttrc) and before the text of the email I reply to:
From: Me <[email protected]>
To: Recipient <[email protected]>
Cc:
Bcc:
Subject: Re: The mail subject
Reply-To:
In-Reply-To: <id@example>
On 2021-01-01 at 09:13:16, Recipient ([email protected]) wrote:
> The email
> I'm
> replying to
In other words, I want to jump to the empty line after In-Reply-To: <id@example>
.
I know that the normal command }
should suffice to jump over the paragraph of headers, thus I added this to ftplugin/mail.vim
:
normal }
Unfortunately, that takes me to the bottom of the buffer, not to the empty line.
This works though:
- Adding
normal }
toafter/syntax/mail.vim
instead offtplugin/mail.vim
. I could go with that, but it seems to me thatnormal }
doesn't belong inafter/syntax/mail.vim
- Adding
normal }
toafter/ftplugin/mail.vim
instead offtplugin/mail.vim
. - Adding this to my muttrc:
set editor="vim -c 'normal }'"
. Like above, I feel it would be cleaner to add that command toftplugin/mail.vim
My questions:
- Is
ftplugin/mail.vim
the right place fornormal
commands? - If so, how can I jump to the first empty line in an email?
I'm using Neovim v0.4.4 on Arch Linux 5.9.14.
I encountered some strange behavior while testing normal
commands: When adding normal iABCDE
to ftplugin/mail.vim
I see "ABCDABCDEE" is written to the file. As if ftplugin/mail.vim
was executed twice.
Cause of the issue
I figured out the issue thanks to filbranden's answer.
My ftplugin/mail.vim
was indeed sourced twice due to this in my init.vim
(Neovim's equivalent to vimrc):
let vimDir = '$XDG_CONFIG_HOME/nvim'
let &runtimepath.= ',' . vimDir
The problem was the second line that appended my config directory, effectively making ~/.config/nvim
appear at the beginning and the end of the runtime path.
Addendum
Although using normal }
in ftplugin/mail.vim
works now, I still put my mail config in after/ftplugin/mail.vim
since I want to override the textwidth config in /usr/share/nvim/runtime/ftplugin/mail.vim
. The contents of after/ftplugin/mail.vim
are now:
setlocal textwidth=0
" Thanks for the tip, B Layer
normal! }
normal!
is almost always the better command to use thannormal
due to the fact that the former will ignore any mappings you've defined that happen to appear in the arguments? May or may not be the reason for}
not going where you expect but regardless it's good to keep in mind.:h restore-cursor
(perhaps, from:h defaults.vim
).