I am looking to insert list items
to-buy > apple > milk >
but I would like to insert a constant string (" > ") on each newline
is there a way to do this?
Well maybe it is not exactly what you want, but why not use such subst command after insert finished:
'[+1is second inserted line number
']is last inserted line number
s- subst command
^- start of line (position after "enter")
>- replacement text
You can map this to key for example:
nnoremap <F4> :'[+1,']s/^/> /<CR>
You can remap the behaviour of
<cr> in insert-mode to a custom function that checks whether you are on a line starting with any amount of whitespace, then
> then any other characters. If so, enter a new-line and start with
>, otherwise enter a new-line as normal.
function! MakeNewLine() if getline(line('.')) =~# "^\s*>.*$" execute "normal! a\<cr>> " startinsert! else execute "normal! a\<cr>" normal! ^ startinsert endif endfunction inoremap <cr> <esc>:call MakeNewLine()<cr>
Put this in your
~/_vimrc or equivalent so it is run every time you run vim. When you enter a new-line in a
> list in the middle of an entry, this also has the effect of splitting it into two entries.