vimtricks.wiki Concise Vim tricks, one at a time.

How do I open another file without saving the current modified buffer first?

Answer

:hide edit {file}<CR>

Explanation

Normally, trying to :edit another file from a modified buffer triggers a warning and blocks the switch unless you save or force the command. :hide gives you a safer middle path: you can leave the current buffer unsaved, keep its changes in memory, and move to a different file immediately. This is useful during investigation and refactor sessions where you need to hop around before deciding what to write.

How it works

  • :hide executes the following command while allowing the current buffer to become hidden, even if modified.
  • edit {file} opens the target file in the current window.
  • The original modified buffer remains loaded and recoverable through buffer commands (:ls, :b, :buffer N).
  • This avoids destructive :edit!, which discards unsaved changes.

Example

You are editing main.go, have unsaved changes, and need to inspect config.go right away.

:hide edit config.go

Now config.go opens in the same window, while your unsaved main.go changes remain in memory. Later you can jump back:

:ls
:buffer main.go

Tips

  • Pair with :set hidden if this behavior is your default preference across all buffer switches.
  • Use :wall when you are ready to persist all modified buffers at once.
  • If you only need a quick peek, :hide split {file} can be a cleaner workflow than replacing the current view.

Next

How do I open another file without changing the alternate-file mark (#)?