From b89fda4fb1eaf3f2e42641828851f661fb8e1da7 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Wed, 26 Jul 2023 08:13:04 -0400 Subject: [PATCH] initial commit --- README.md | 1 + stt/cheat.sh | 6 ++++++ stt/common.vim | 3 +++ stt/stt.vim | 1 + stt/stt8.vim | 30 ++++++++++++++++++++++++++++++ stt/stt9.vim | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 README.md create mode 100644 stt/cheat.sh create mode 100644 stt/common.vim create mode 120000 stt/stt.vim create mode 100644 stt/stt8.vim create mode 100644 stt/stt9.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..f17bbbf --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# VIM snippets for fun and productivity diff --git a/stt/cheat.sh b/stt/cheat.sh new file mode 100644 index 0000000..41a7739 --- /dev/null +++ b/stt/cheat.sh @@ -0,0 +1,6 @@ +echo hi +date +VIMST sleep 4000 +date +echo bye +VIMST ctrl l diff --git a/stt/common.vim b/stt/common.vim new file mode 100644 index 0000000..415b80f --- /dev/null +++ b/stt/common.vim @@ -0,0 +1,3 @@ + +let g:mapleader = ' ' +set splitbelow splitright diff --git a/stt/stt.vim b/stt/stt.vim new file mode 120000 index 0000000..128c1fc --- /dev/null +++ b/stt/stt.vim @@ -0,0 +1 @@ +stt8.vim \ No newline at end of file diff --git a/stt/stt8.vim b/stt/stt8.vim new file mode 100644 index 0000000..19e93d5 --- /dev/null +++ b/stt/stt8.vim @@ -0,0 +1,30 @@ +def g:SendRangeToTerminal(start_line: number, end_line: number) + const terms = term_list() + if terms->empty() + echomsg "No Terminal windows found" + return + endif + var line_num = start_line + for line in getline(start_line, end_line) + line_num += 1 + const spl_cmd = line->matchlist('\vVIMST (sleep|ctrl) ([0-9]+|[a-z])') + if !spl_cmd->empty() + const [_, cmd, arg1; _] = spl_cmd + if cmd == "sleep" + timer_start(str2nr(arg1), (_) => g:SendRangeToTerminal(line_num, end_line)) + return + elseif cmd == "ctrl" + terms[0]->term_sendkeys(nr2char(char2nr(arg1) - 96)) + continue + endif + endif + terms[0]->term_sendkeys(line .. "\") + endfor +enddef + +command -range -bar SendToTerm :call g:SendRangeToTerminal(, ) +vnoremap s :SendToTerm +nnoremap s :SendToTerm + +autocmd BufNewFile,BufRead cheat.sh nnoremap :SendToTerm \| norm j +autocmd BufNewFile,BufRead cheat.sh nnoremap <2-LeftMouse> :SendToTerm diff --git a/stt/stt9.vim b/stt/stt9.vim new file mode 100644 index 0000000..939605c --- /dev/null +++ b/stt/stt9.vim @@ -0,0 +1,34 @@ +vim9script + +def SendRangeToTerminal(start_line: number, end_line: number) + const terms = term_list() + if terms->empty() + echomsg "No Terminal windows found" + return + endif + var line_num = start_line + for line in getline(start_line, end_line) + line_num += 1 + const spl_cmd = line->matchlist('\vVIMST (sleep|ctrl) ([0-9]+|[a-z])') + if !spl_cmd->empty() + const [_, cmd, arg1; _] = spl_cmd + if cmd == "sleep" + timer_start(str2nr(arg1), (_) => SendRangeToTerminal(line_num, end_line)) + return + elseif cmd == "ctrl" + terms[0]->term_sendkeys(nr2char(char2nr(arg1) - 96)) + continue + endif + endif + terms[0]->term_sendkeys(line .. "\") + endfor +enddef + +command -range -bar SendToTerm :call SendRangeToTerminal(, ) +vnoremap s :SendToTerm +nnoremap s :SendToTerm + +autocmd BufNewFile,BufRead cheat.sh { + nnoremap :SendToTerm \| norm j + nnoremap <2-LeftMouse> :SendToTerm +}