Last active
February 2, 2023 12:25
-
-
Save ram535/b1b7af6cd7769ec0481eb2eed549ea23 to your computer and use it in GitHub Desktop.
Revisions
-
ram535 revised this gist
May 12, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function! MonkeyTerminalOpen() if !bufexists(s:monkey_terminal_buffer) " Creates a window call monkey_terminal new monkey_terminal " Moves to the window the right the current one wincmd L let s:monkey_terminal_job_id = termopen($SHELL, { 'detach': 1 }) -
ram535 renamed this gist
Dec 13, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ram535 revised this gist
Dec 13, 2017 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,10 +12,7 @@ function! MonkeyTerminalOpen() new monkey_terminal " Moves to the window below the current one wincmd L let s:monkey_terminal_job_id = termopen($SHELL, { 'detach': 1 }) " Change the name of the buffer to "Terminal 1" silent file Terminal\ 1 @@ -30,9 +27,7 @@ function! MonkeyTerminalOpen() if !win_gotoid(s:monkey_terminal_window) sp " Moves to the window below the current one wincmd L buffer Terminal\ 1 " Gets the id of the terminal window let s:monkey_terminal_window = win_getid() -
ram535 created this gist
Dec 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ " With this function you can reuse the same terminal in neovim. " You can toggle the terminal and also send a command to the same terminal. let s:monkey_terminal_window = -1 let s:monkey_terminal_buffer = -1 let s:monkey_terminal_job_id = -1 function! MonkeyTerminalOpen() " Check if buffer exists, if not create a window and a buffer if !bufexists(s:monkey_terminal_buffer) " Creates a window call monkey_terminal new monkey_terminal " Moves to the window below the current one wincmd L " resize the high of the window " exec 'resize 7' let s:monkey_terminal_job_id = termopen($SHELL, { 'detach': 1 }) " Change the name of the buffer to "Terminal 1" silent file Terminal\ 1 " Gets the id of the terminal window let s:monkey_terminal_window = win_getid() let s:monkey_terminal_buffer = bufnr('%') " The buffer of the terminal won't appear in the list of the buffers " when calling :buffers command set nobuflisted else if !win_gotoid(s:monkey_terminal_window) sp " Moves to the window below the current one wincmd L " resize the high of the window " exec 'resize 7' buffer Terminal\ 1 " Gets the id of the terminal window let s:monkey_terminal_window = win_getid() endif endif endfunction function! MonkeyTerminalToggle() if win_gotoid(s:monkey_terminal_window) call MonkeyTerminalClose() else call MonkeyTerminalOpen() endif endfunction function! MonkeyTerminalClose() if win_gotoid(s:monkey_terminal_window) " close the current window hide endif endfunction function! MonkeyTerminalExec(cmd) if !win_gotoid(s:monkey_terminal_window) call MonkeyTerminalOpen() endif " clear current input call jobsend(s:monkey_terminal_job_id, "clear\n") " run cmd call jobsend(s:monkey_terminal_job_id, a:cmd . "\n") normal! G wincmd p endfunction " With this maps you can now toggle the terminal nnoremap <F7> :call MonkeyTerminalToggle()<cr> tnoremap <F7> <C-\><C-n>:call MonkeyTerminalToggle()<cr> " This an example on how specify command with different types of files. augroup go autocmd! autocmd BufRead,BufNewFile *.go set filetype=go autocmd FileType go nnoremap <F5> :call MonkeyTerminalExec('go run ' . expand('%'))<cr> augroup END