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?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
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.