Skip to content

Instantly share code, notes, and snippets.

@kshenoy
Last active December 17, 2015 19:39
Show Gist options
  • Save kshenoy/5661853 to your computer and use it in GitHub Desktop.
Save kshenoy/5661853 to your computer and use it in GitHub Desktop.
Function to execute commands without modifying the original settings like cursor position, search string etc.
function! Preserve( command )
" Description: Function to execute commands without modifying the original settings like cursor position, search string etc.
" Save last search, and cursor position.
let currview = winsaveview()
" Do the business
silent! execute a:command
" Restore previous search history, and cursor position
call winrestview( currview )
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment