N.B. my question title might be poor, so feel free to improve it.
I want to write a command to move my cursor to the body of my email, add blank lines, and change to insert mode. Previously, I used the following for new emails.
nnoremap gb <C-Home>/^$<CR>:nohlsearch<CR>o
mutt would create a new email in
vim, then I'd press
gb. The cursor would move to the top of the email (
<C-Home>), find the first blank line and immediately stop highlighting (
/^$<CR>:nohlsearch<CR>), create a new line and start editing a new line (
However, I often reply to an email, and I wanted to automatically create another "buffer" empty line below my cursor position. Hence, I changed the command to this following.
nnoremap gb <C-Home>/^$<CR>:nohlsearch<CR>o<Esc>ko
This would do as above, then get into normal mode
<Esc>, move up (
k), and create another new line to edit
I wanted to create a conditional. After searching for the first blank line (
<C-Home>/^$<CR>:nohlsearch<CR>), if this were the last line of the email, I'd be editing a new email, so just
o. Otherwise, I'd be replying, so
o<Esc>ko. The following doesn't work, because I've mangled together different syntaxes, but it should give an idea of what I want.
nnoremap gb <C-Home>/^$<CR>:nohlsearch<CR>|if line('.') != line('$')|o<Esc>k|endif|o
nnoremap <expr> gb ... is useful, but I'm not sure how to use it.