├── plugin └── backscratch.vim ├── LICENSE ├── autoload └── backscratch.vim ├── doc └── backscratch.txt └── README.md /plugin/backscratch.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_backscratch') 2 | finish 3 | endif 4 | let g:loaded_backscratch = 1 5 | 6 | command! Scratchify setlocal nobuflisted noswapfile buftype=nofile bufhidden=delete 7 | command! -nargs=* -complete=command Scratch call backscratch#open(, ) 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Łukasz Jan Niemier 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /autoload/backscratch.vim: -------------------------------------------------------------------------------- 1 | function! backscratch#open(mods, cmd) abort 2 | if a:cmd is# '' 3 | let l:output = '' 4 | elseif a:cmd[0] is# '@' 5 | if strlen(a:cmd) is# 2 6 | let l:output = getreg(a:cmd[1], 1, v:true) 7 | else 8 | throw 'Invalid register' 9 | endif 10 | elseif a:cmd[0] is# '!' 11 | let l:cmd = a:cmd =~' %' ? substitute(a:cmd, ' %', ' ' . expand('%:p'), '') : a:cmd 12 | let l:output = systemlist(matchstr(l:cmd, '^!\zs.*')) 13 | else 14 | let l:output = split(execute(a:cmd), "\n") 15 | endif 16 | 17 | execute a:mods . ' new' 18 | Scratchify 19 | call setline(1, l:output) 20 | endfunction 21 | -------------------------------------------------------------------------------- /doc/backscratch.txt: -------------------------------------------------------------------------------- 1 | *backscratch.txt* Open scratch buffer 2 | 3 | Commands: 4 | *:Scratchify* 5 | :Scratchify 6 | Change current buffer into scratch buffer. For more 7 | information check |scratch-buffer|. 8 | 9 | *:Scratch* 10 | :Scratch 11 | :Scratch {cmd} 12 | Open new scratch buffer. If {cmd} is specified it run provided 13 | Vim command and load output into |scratch-buffer|. 14 | 15 | *:Scratch@* 16 | :Scratch @{reg} 17 | Load content of {reg} into new |scratch-buffer|. 18 | 19 | *:Scratch!* 20 | :Scratch !{cmd} 21 | Execute {cmd} and insert its standard output into 22 | |scratch-buffer|. It uses |systemlist()| to read output of 23 | command. 24 | 25 | vim:tw=78:ts=8:noet:ft=help:norl: 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Back scratch 2 | 3 | Open new scratch window. Additionally allows to load output of Vim command, 4 | shell command of register into such buffer. 5 | 6 | ## Thanks 7 | 8 | Based on -romainl- script - https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7 9 | 10 | ## Usage: 11 | 12 | :Scratch "open new, empty, scratch window 13 | :Scratch ls " show the full output of command :ls in scratch window 14 | :Scratch !ls -la " show the full output of command :!ls -la in scratch window 15 | :Scratch @+ " show the full output of '+' register in scratch window 16 | 17 | ## Additions: 18 | 19 | - by default use :new instead of :vnew 20 | - accepts modifiers like :vertical or :aboveleft to control where the 21 | scratchpad will be positioned 22 | - adds support for opening scratchpads for registers via @ prefix 23 | - adds :Scratchify to change any buffer into scratchpad 24 | 25 | ## TODO: 26 | 27 | - support for specifying filetype via +ft 28 | --------------------------------------------------------------------------------