Ctrl-o with ignore "No write since last change"

Viewed 991

I can press ctrlO to go to the last jump point. However, if there are any changes in the current document it warns me with:

E37: No write since last change (add ! to override)

Is there a way to ignore that message and do ctrl-o and either (1) discard any changes; or (2) save any changes and do ctrl-o?

2 Answers
  1. Discard any changes --- No.

  2. Save any changes --- set autowrite or set autowriteall

  3. Hide buffer but keep it in memory (can ask for saving it later) --- set hidden

  4. Ask if you want to save a buffer --- set confirm

Note: (2), (3) and (4) are global options and change Vim behaviour for many(!) commands.

2) Here is a simple command for your .vimrc that will save the file before jumping:

noremap <C-O> :update<C-M><C-O>

EDIT: Use :update instead of :w to avoid re-writing the file when it was not previously modified.

1) I looked for the equivalent solution to discard the changes instead of saving them, using :e! instead of :w, but that modifies the list of jump points in a way that break <C-O> completely.

Related