From 5bd71dd921a098fe035d28a495e492ff188f4b73 Mon Sep 17 00:00:00 2001 From: ManjaroOne666 Date: Thu, 29 Mar 2018 21:41:18 +0100 Subject: [PATCH] Shell command --- vimrc.functions.vim | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/vimrc.functions.vim b/vimrc.functions.vim index 0a03b85..7895338 100644 --- a/vimrc.functions.vim +++ b/vimrc.functions.vim @@ -80,6 +80,63 @@ function! LinterStatus() abort "{{{ endfunction "}}} +" Shell command +" based on +" http://vim.wikia.com/wiki/VimTip1599 +command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand() +let g:shell_scratch_buffer_nr = -1 + +function! s:RunShellCommand(cmdline) abort +"{{{ + let l:expanded_cmdline = a:cmdline + for l:part in split(a:cmdline, ' ') + if l:part[0] =~ '\v[%#<]' + let l:expanded_part = fnameescape(expand(l:part)) + let l:expanded_cmdline = substitute(l:expanded_cmdline, l:part, l:expanded_part, '') + endif + endfor + + if g:shell_scratch_buffer_nr > -1 + let l:win_nr = bufwinnr(g:shell_scratch_buffer_nr) + if l:win_nr < 0 + execute 'bdelete' g:shell_scratch_buffer_nr + top new + let g:shell_scratch_buffer_nr = bufnr('%') + else + execute l:win_nr. ' wincmd w' + setlocal modifiable + %delete _ + endif + else + top new + let g:shell_scratch_buffer_nr = bufnr('%') + endif + + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap + nnoremap q :bdelete + augroup ResetShellBufferNr + autocmd! * + autocmd BufUnload let g:shell_scratch_buffer_nr = -1 + augroup END + + " call setline(1, 'You entered: ' . a:cmdline) + " call setline(2, 'Expanded Form: ' .l:expanded_cmdline) + " call setline(3,substitute(getline(2),'.','=','g')) + execute '$read !'. l:expanded_cmdline + 1 + + setlocal nomodifiable + if !exists('b:shell_line_count') + let b:shell_line_count = line('$') + if b:shell_line_count > 25 + let b:shell_line_count = 20 + endif + execute 'resize' b:shell_line_count + 1 + endif + + wincmd p +endfunction +"}}}