How can I get vim to preserve marks when I delete the line the mark is on (i.e., automatically move the mark to the line immediately above or below the marked line)
One addition to @Kurt Hutchinson answer: there is a possibility to define an operator function. In this case you don’t need to define a mapping for every deletion command, but instead redefine d:
let s:typetochar={
\ 'char': 'v',
\ 'line': 'V',
\'block': "\",
\}
function! DeleteOperator(type)
execute 'lockmarks normal! `["'.v:register.'d'.s:typetochar[a:type].'`]'
endfunction
function! s:Delete()
set opfunc=DeleteOperator
return 'g@'
endfunction
nnoremap d Delete()
nnoremap dd Delete().'g@'
vnoremap d :lockmarks normal! gvd
Note the dd mapping: as d is actually using g@, there should be dg@ (expanded to g@g@) where you type dd. So in order to use cleaner dd you have to create a mapping.