├── sttdemo.gif ├── README.md └── plugin └── stt.vim /sttdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyitscassio/vim-stt/HEAD/sttdemo.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Togglable Terminal 2 | 3 | ![demo](sttdemo.gif) 4 | 5 | This plugin aims to add a basic togglable terminal to neovim (and partially vim), to make 6 | it more "IDE like". 7 | 8 | ## Commands 9 | 10 | You can toggle stt with the command: 11 | 12 | ``` 13 | :ToggleTerm 14 | ``` 15 | 16 | Or if you want to have multiple terminals you can execute `:ToggleTerm` with an 17 | argument: 18 | 19 | ``` 20 | :ToggleTerm term-1 21 | ``` 22 | 23 | And now `:ToggleTerm term-1` will only toggle term-1. 24 | 25 | ## Configuration 26 | 27 | The configurations only works in neovim, with vim they are ineffective. 28 | 29 | You can enable `g:stt_auto_insert` to automatically enter insert mode when 30 | entering a terminal. 31 | 32 | ``` 33 | let g:stt_auto_insert = 1 34 | ``` 35 | 36 | By enabling `g:stt_auto_quit` the terminal window will quit, when there is no other window. 37 | 38 | ``` 39 | let g:stt_auto_quit = 1 40 | ``` 41 | 42 | ### If you have enchantments ideas or issues, feel free to open a issue/pr 43 | 44 | ### Vim has to be compiled with terminal support to (partially) work 45 | 46 | This plugin is still a work in process, vim support is close to none, and there 47 | is still somethings I plan to implement on it. Everyday I try to work a little on it. 48 | -------------------------------------------------------------------------------- /plugin/stt.vim: -------------------------------------------------------------------------------- 1 | " stt.vim - Simple Togglable Terminal 2 | " Author: Cássio Ávila (AKA toniz4) 3 | " Version: 0.4 4 | " TODO: Better terminal resizing, make it possible to configure the size and 5 | " make it a fixed size when opening more then one terminal split 6 | " TODO: Better vim support 7 | " TODO: Fix this mess of a code 8 | 9 | if !exists('g:stt_auto_insert') 10 | let g:stt_auto_insert = 0 11 | endif 12 | 13 | if !exists('g:stt_auto_quit') 14 | let g:stt_auto_quit = 0 15 | endif 16 | 17 | 18 | if !exists('auloaded') 19 | let auloaded = 1 20 | augroup stt 21 | autocmd BufEnter term://* if g:stt_auto_insert == 1 | startinsert | endif 22 | autocmd BufEnter * if (g:stt_auto_quit == 1 && winnr("$") == 1 23 | \ && exists('s:termbufnums') 24 | \ && get(getwininfo(win_getid()),0).terminal) | q | endif 25 | augroup END 26 | endif 27 | 28 | function CleanBuffer() 29 | unlet s:termbufnums[s:termname] 30 | endfunction 31 | 32 | function UpdateBuffer() 33 | let s:termbufnums[s:termname] = bufnr(s:termname) 34 | endfunction 35 | 36 | function ToggleTerm(name) 37 | if a:name == '' 38 | let s:termname = 'term://terminal' 39 | else 40 | execute "let s:termname = " . "'term://" . a:name . ".stt'" 41 | endif 42 | 43 | if !exists('s:termbufnums') 44 | let s:termbufnums = {} 45 | endif 46 | 47 | if !get(s:termbufnums, s:termname) 48 | call OpenTerm(a:name) 49 | else 50 | for l:buf in getbufinfo({'buflisted':1}) 51 | let l:win = get(getwininfo(get(l:buf.windows, 0)), 0) 52 | 53 | if !l:buf.hidden 54 | if l:win.terminal && s:termname == buf.name 55 | let s:termbufnums[s:termname] = l:buf.bufnr 56 | execute l:win.winnr . 'hide' 57 | endif 58 | else 59 | if s:termbufnums[s:termname] == l:buf.bufnr 60 | execute 'sbuffer' . l:buf.bufnr | res 9 61 | endif 62 | endif 63 | endfor 64 | endif 65 | 66 | augroup CLEAN 67 | autocmd! 68 | if &hidden 69 | exec "autocmd BufHidden " . s:termname . " call UpdateBuffer()" 70 | else 71 | exec "autocmd BufDelete " . s:termname . " call CleanBuffer()" 72 | endif 73 | augroup END 74 | endfunction 75 | 76 | function! OpenTerm(name) abort 77 | if has('nvim') || has('terminal') 78 | setlocal splitbelow 79 | if has('nvim') 80 | 9sp | terminal 81 | else 82 | terminal ++close 83 | res 9 84 | endif 85 | setlocal number& 86 | setlocal relativenumber& 87 | setlocal nomodified& 88 | if g:stt_auto_insert == 1 89 | startinsert 90 | endif 91 | 92 | if a:name == '' 93 | let s:termname = 'term://terminal' 94 | else 95 | execute "let s:termname = " . "'term://" . a:name . ".stt'" 96 | endif 97 | 98 | execute "file! " . s:termname 99 | let s:termbufnums[s:termname] = bufnr("$") 100 | else 101 | echoerr "Vim has to be compiled with terminal support!" 102 | endif 103 | endfunction 104 | 105 | command! -nargs=? ToggleTerm call ToggleTerm('') 106 | --------------------------------------------------------------------------------