Wednesday, August 15, 2012

Vim Scratch Buffer

Opening a scratch buffer in Vim can come in handy. The following vimrc addition works well: nnoremap <Leader>sc :e scratch<CR>:setlocal readonly<CR>

It is especially useful in combination with the run shell command shortcut once Vim is configured to change to the directory of the current file with the following vimrc addition: autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

The advantage this named buffer has over the [No Name] buffers created by :enew is that newly created scratch buffers will not affect the path of existing buffers. This can be useful if you later want to save the contents of your scratch buffer.

No comments:

Post a Comment