Heve an exemple function called Preserve: https://github.com/voyeg3r/dotfiles/blob/5337ab759fe09bff018e0b11a97b0f1bbd9236ad/rcfiles/vim/vimrc#L470-L478 This function Should be used when te command does not changes the number of lines like in: https://github.com/voyeg3r/dotfiles/blob/5337ab759fe09bff018e0b11a97b0f1bbd9236ad/rcfiles/vim/vimrc#L429-L433 I think you will like this feature