Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ You can use the following command to open/edit the scratch buffer:

:Scratch

To open the scratch buffer in a new split window, use the following command:
To open the scratch buffer in a new horizontal split window, use the following command:

:Sscratch

To open the scratch buffer in a new vertical split window, use the following command:

:Vscratch

When you close the scratch buffer window, the buffer will retain the
contents. You can again edit the scratch buffer by openeing it using one of
the above commands. There is no need to save the scatch buffer.
Expand Down
24 changes: 17 additions & 7 deletions plugin/scratch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ let ScratchBufferName = "__Scratch__"

" ScratchBufferOpen
" Open the scratch buffer
function! s:ScratchBufferOpen(new_win)
function! s:ScratchBufferOpen(new_win,vertical_split)
let split_win = a:new_win
let vertical_split = a:vertical_split

" If the current buffer is modified then open the scratch buffer in a new
" window
Expand All @@ -67,7 +68,11 @@ function! s:ScratchBufferOpen(new_win)
if scr_bufnum == -1
" open a new scratch buffer
if split_win
exe "new " . g:ScratchBufferName
if vertical_split
exe "vnew " . g:ScratchBufferName
else
exe "new " . g:ScratchBufferName
endif
else
exe "edit " . g:ScratchBufferName
endif
Expand All @@ -84,7 +89,11 @@ function! s:ScratchBufferOpen(new_win)
else
" Create a new scratch buffer
if split_win
exe "split +buffer" . scr_bufnum
if vertical_split
exe "vsplit +buffer" . scr_bufnum
else
exe "split +buffer" . scr_bufnum
endif
else
exe "buffer " . scr_bufnum
endif
Expand All @@ -104,7 +113,8 @@ endfunction
autocmd BufNewFile __Scratch__ call s:ScratchMarkBuffer()

" Command to edit the scratch buffer in the current window
command! -nargs=0 Scratch call s:ScratchBufferOpen(0)
" Command to open the scratch buffer in a new split window
command! -nargs=0 Sscratch call s:ScratchBufferOpen(1)

command! -nargs=0 Scratch call s:ScratchBufferOpen(0,0)
" Command to open the scratch buffer in a new horizontal split window
command! -nargs=0 Sscratch call s:ScratchBufferOpen(1,0)
" Command to open the scratch buffer in a new vertical split window
command! -nargs=0 Vscratch call s:ScratchBufferOpen(1,1)