The intent of a vim scratch buffer is to provide a temporary area to store or edit text which gets discarded when you exit vim. The buffer will be retained as long as the vim session is on. Even if you are a heavy user of vim copy paste registers, the scratch buffer comes in handy to deal with reminders or code snippets you want to refer to later. There was a old plugin that does this. However, it’s not being maintained for 4 years (at the time of writing).
scratch.vim is a new vim plugin inspired by the original project and adds some nice features:
- Auto-hide on inactivity.
- Mappings for note taking and selection pasting directly into the scratch buffer.
Usage in vim
:Scratchopens the scratch buffer window using top 20% of the screen (configurable via
g:scratch_top). The window automatically closes when inactive. The contents will be available the next time it is opened during the same session.
gsin normal mode opens the scratch window and enters insert mode. The scratch window closes when you leave insert mode. This is especially useful for quick notes.
gsin visual mode pastes the current selection (character-wise, line-wise or block-wise) into the scratch buffer.
gSin normal/visual mode clears the scratch buffer before opening it.
:help Scratchshows detailed list of configuration options.
Auto-closing features require
hidden to be set (and can be disabled via the
Install pathogen.vim (required)
$ mkdir -p ~/.vim/autoload ~/.vim/bundle && \ $ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
$ cd ~/.vim/bundle $ git clone https://github.com/mtth/scratch.vim