Skip to content

Instantly share code, notes, and snippets.

@skreuzer
Created August 22, 2014 16:13
Show Gist options
  • Save skreuzer/96e5d8c0c93fa4de7564 to your computer and use it in GitHub Desktop.
Save skreuzer/96e5d8c0c93fa4de7564 to your computer and use it in GitHub Desktop.
" <F2> Run 'perl -cw' over the code currently being edited
" <F3> Close current window
" <F4> Run code currently being edited as a perl script
" <F5> Load these keybinds even if vim doesn't think it is a perl script
" perl -cw buffer, open output in a new window
function! PerlCWBuffer()
let l:tmpfile1 = tempname()
let l:tmpfile2 = tempname()
execute "normal:w!" . l:tmpfile1 . "\<CR>"
execute "normal:! perl -cw ".l:tmpfile1." \> ".l:tmpfile2." 2\>\&1 \<CR>"
execute "normal:new\<CR>"
execute "normal:edit " . l:tmpfile2 . "\<CR>"
endfunction
" run buffer as a perl script, open output in a new window
function! PerlBuffer()
let l:tmpfile1 = tempname()
let l:tmpfile2 = tempname()
execute "normal:w!" . l:tmpfile1 . "\<CR>"
execute "normal:! perl ".l:tmpfile1." \> ".l:tmpfile2." 2\>\&1 \<CR>"
execute "normal:new\<CR>"
execute "normal:edit " . l:tmpfile2 . "\<CR>"
endfunction
function! PerlSettings()
if !did_filetype()
set filetype=perl
endif
if version >= 730
set relativenumber
endif
set cindent
set comments=:#
set formatoptions=croql
set keywordprg=perldoc\ -f
noremap <F2> <Esc>:call PerlCWBuffer()<CR><Esc>
noremap <F3> <Esc>:close<CR><Esc>
noremap <F4> <Esc>:call PerlBuffer()<CR><Esc>
endfunction
noremap <F5> <esc>:call PerlSettings()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment