" Title: FancyTerm " Author: g0zar " All glory goes to our heavenly father and Jesus Christ " Description: A plugin that lets you send commands from any buffer to " an active terminal instance. " Dependency: +perl " Version: 2.0.0 " License: MIT if has('perl') " Variables{{{ if !exists('g:fancyterm_map_keys') let g:fancyterm_map_keys = 1 endif if !exists('g:fancyterm_term_pos') let g:fancyterm_term_pos = 'top' endif if !exists('g:fancyterm_term_height') let g:fancyterm_term_height = 10 endif "}}} " "Public domain, stackoverflow, FocusedWolf function! s:get_visual_selection()"{{{ " Why is this not a built-in Vim script function?! let [line_start, column_start] = getpos("'<")[1:2] let [line_end, column_end] = getpos("'>")[1:2] let lines = getline(line_start, line_end) if len(lines) == 0 return '' endif let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)] let lines[0] = lines[0][column_start - 1:] return join(lines, "\n") endfunction "}}} function! TermLoadFunctions() "{{{ "FIXME: Ironically doesn't work for perl itself "since perl doesn't really have a repl program "that allows it to parse more than one line. "So our commands can only work for programs/repls that "are capable of doing multiline parsing perl <Buffer()->Name() =~ m/$ENV{SHELL}/i; } @windows)[0]; undef $ok; my ($ok, $height) = VIM::Eval('g:fancyterm_term_height'); $TERMINAL ->SetHeight($height); EOF endfunction "}}} function! TermSendCurrentLine() "{{{ perl <Buffer(); my $bufnum = $termbuf->Number(); my ($cur_row, $cur_col) = $main::curwin->Cursor(); my $line = $main::curbuf->Get($cur_row); $line = replace_leading_tabs($line); $line = '"'.escape_basic($line)."\n".'"'; VIM::Eval("term_sendkeys($bufnum, $line)"); EOF endfunction "}}} function! _Internal_TermSendVisual(line)"{{{ perl <Buffer->Number; if($ok){ $cmd = replace_leading_tabs($cmd); $cmd= escape_basic($cmd); $cmd= "\"$cmd\n\""; VIM::Eval("term_sendkeys($termbufnum, $cmd)"); }else{ print "Error: $cmd"; } EOF endfunction "}}} " function! TermSendBuffer()"{{{ perl <Buffer()->Number(); my ($ok,$cmd) = VIM::Eval("getline(0,".($main::curbuf->Count()).")"); my $cmd = replace_leading_tabs($cmd); $cmd = escape_basic($cmd); $cmd= "\"\n$cmd\""; VIM::Eval("term_sendkeys($bufnum,$cmd)"); EOF endfunction "}}} " function! TermSetActive()"{{{ perl <a :call TermSendBuffer() vnoremap v :call TermSendVisual() nnoremap . :call TermSendCurrentLine() endif else echo "Perl support must be enabled for this plugin to work" endif .