mtth / scratch.vim

Unobtrusive scratch window
MIT License
395 stars 32 forks source link

Window switching oddities #5

Closed mcandre closed 10 years ago

mcandre commented 10 years ago

I'm new to Vim, so maybe I'm doing this wrong, but...

When I try to switch from the Scratch window to the window I was on, I get weird behavior.

  1. Open code file for editing. vim hello.cpp
  2. Open scratch window. :Scratch
  3. Switch back to code file: Ctrl+w Ctrl+w
  4. Switch back to scratch window: Ctrl+w Ctrl+w

Step 4 does nothing, and step 3 does a strange thing: The scratch window visibly disappears, but the resulting hello.cpp window is mistakenly labelled "Scratch" [New File].

I come from Emacs, where the *scratch* buffer is builtin, designed to be more persistent (by default, open until Emacs quits) and it's natural for users to switch back and forth between scratch and the code file they're editing.

Is there a way we can make Vim Scratch switch back and forth more naturally like in Emacs?

mtth commented 10 years ago

What does the command set hidden? return when you run it (don't forget the question mark in the command)?

My suspicion is that it is not enabled for you. When it is, buffers can continue to exist even when they are not displayed (help 'hidden' for more information). In particular here, the scratch window is configured by default to automatically hide as soon as it loses focus (think of it as only taking real estate when it is needed). When you next reopen it (either via the :Scratch command or the gs mapping), its contents will still be there.

The autohide behavior can be toggled off by setting the configuration variable g:scratch_autohide to 0.

And I would also guess that the hello.cpp window isn't actually mislabeled, but that the screen just hasn't been redrawn. Try executing :redraw and let me know if it doesn't fix it.

mcandre commented 10 years ago

Thanks for taking the time to respond to each of my many requests :)

Yes, hidden? was returning nohidden. By adding set hidden and let g:scratch_autohide = 0 to my .vimrc, I was able to get the behaviour I wanted.

mtth commented 10 years ago

Glad I could help :).

I just switched the default for g:scratch_autohide to depend on the value of 'hidden'. It didn't make much sense otherwise.

mcandre commented 10 years ago

Yay! That means less configuration in my .vimrc!