From 4ceb9b896760e900caf12237a94b6c837746edeb Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 19 Aug 2024 23:32:02 +0200 Subject: Make scratch.vim a plugin --- .config/nvim/init.lua | 24 ++++-------------------- .config/nvim/plugin/scratch.vim | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 .config/nvim/plugin/scratch.vim (limited to '.config/nvim') diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index a13d87c..e0d399d 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -40,18 +40,6 @@ vim.opt.tabstop = 4 vim.opt.undodir = os.getenv('XDG_STATE_HOME') .. '/nvim/undo' vim.opt.undofile = true -function mk_scratch_buffer() - vim.cmd [[ - if bufexists('scratch') - buffer scratch - else - noswapfile hide enew - setlocal buftype=nofile bufhidden=hide - file scratch - endif - ]] -end - vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', @@ -92,14 +80,10 @@ vim.keymap.set('n', 'gJ', function() ]] end, { desc = '[J]oin lines without whitespace' }) -vim.keymap.set('n', 's', function() - vim.cmd 'vsplit' - mk_scratch_buffer() -end, { desc = 'Open the scratch buffer in a vertical split' }) -vim.keymap.set('n', 'S', function() - vim.cmd 'split' - mk_scratch_buffer() -end, { desc = 'Open the scratch buffer in a horizontal split' }) +vim.keymap.set('n', 's', ':VScratch', + { desc = 'Open the scratch buffer in a vertical split' }) +vim.keymap.set('n', 'S', ':Scratch', + { desc = 'Open the scratch buffer in a horizontal split' }) if vim.loop.os_uname().sysname ~= 'Darwin' then vim.keymap.set({'n', 'x'}, '', 'V', diff --git a/.config/nvim/plugin/scratch.vim b/.config/nvim/plugin/scratch.vim new file mode 100644 index 0000000..a6a7a07 --- /dev/null +++ b/.config/nvim/plugin/scratch.vim @@ -0,0 +1,18 @@ +if &cp || exists('g:loaded_scratch') + finish +endif +let g:loaded_scratch = v:true + +function! scratch#New(cmd) + execute a:cmd + if bufexists('scratch') + buffer scratch + else + noswapfile hide enew + setlocal buftype=nofile bufhidden=hide + file scratch + endif +endfunction + +command! -nargs=0 Scratch call scratch#New('split') +command! -nargs=0 VScratch call scratch#New('vsplit') -- cgit v1.2.3