├── README.md ├── doc └── altscreen.txt └── plugin └── altscreen.vim /README.md: -------------------------------------------------------------------------------- 1 | Vim-altscreen 2 | ============== 3 | Altscreen automatically toggles alternate screen features on you terminal. 4 | 5 | No more `:!` output in the wrong place! 6 | 7 | If you are using Vim in a terminal, you have probably noticed that the output 8 | of external commmands doesn't go in the same "virtual screen" as Vim; Eg. if 9 | you type `:!ls`, it looks as though you pressed ``, ran `ls` in the 10 | shell, then resumed Vim once you pressed a key. And when you quit Vim, you 11 | can see the output of all external commands you ran in Vim, which is 12 | generally not what you want. 13 | 14 | This plugin ensures that the output of external commands run in Vim stays in 15 | Vim's "virtual screen", and doesn't pollute your main "shell screen". 16 | 17 | [![asciicast](https://asciinema.org/a/R7Dno07kILcTaOY704dFjnlDz.png)](https://asciinema.org/a/R7Dno07kILcTaOY704dFjnlDz) 18 | 19 | Installation 20 | ------------- 21 | Use your favorite method: 22 | * [Pathogen][1] - git clone https://github.com/fcpg/vim-altscreen ~/.vim/bundle/vim-altscreen 23 | * [NeoBundle][2] - NeoBundle 'fcpg/vim-altscreen' 24 | * [Vundle][3] - Plugin 'fcpg/vim-altscreen' 25 | * [Plug][4] - Plug 'fcpg/vim-altscreen' 26 | * manual - copy all of the files into your ~/.vim directory 27 | 28 | Help 29 | ----- 30 | Run :helptags (or :Helptags with Pathogen), then :help altscreen 31 | 32 | Pluginophobia 33 | -------------- 34 | 35 | If you don't like plugins, feel free to steal the code into your vimrc. 36 | 37 | License 38 | -------- 39 | [Attribution-ShareAlike 4.0 Int.](https://creativecommons.org/licenses/by-sa/4.0/) 40 | 41 | [1]: https://github.com/tpope/vim-pathogen 42 | [2]: https://github.com/Shougo/neobundle.vim 43 | [3]: https://github.com/gmarik/vundle 44 | [4]: https://github.com/junegunn/vim-plug 45 | -------------------------------------------------------------------------------- /doc/altscreen.txt: -------------------------------------------------------------------------------- 1 | *altscreen.txt* Alternate screen management *altscreen* 2 | 3 | Altscreen MANUAL 4 | 5 | 1. About altscreen |altscreen-about| 6 | 2. Quick Start |altscreen-quickstart| 7 | 3. Key Mappings and Commands |altscreen-keymappings| 8 | |altscreen-functions| 9 | 4. Changelog |altscreen-changelog| 10 | 5. Contribute |altscreen-contribute| 11 | 6. License |altscreen-license| 12 | 13 | ============================================================================= 14 | 1. ABOUT altscreen ~ 15 | *altscreen-about* 16 | 17 | When you run vim in a terminal, the screen is erased and vim displays its 18 | windows, buffers etc. When you quit vim, what was previously on screen (eg. 19 | shell commands and ouput) is restored: your terminal handles this, and it is 20 | called _alternate screen_. 21 | 22 | Vim knows how ask your terminal to switch to alternate screen, but 23 | unfortunately it's on an all-or-nothing basis: either vim stays on it own 24 | screen and all command ouput goes elsewhere eg. your shell, or vim don't set 25 | alternate screen and it overwrites your screen, meaning you "lose" what was 26 | displayed before. 27 | 28 | Altscreen basically disables alternate screen once vim has started, so that 29 | external command output stays in the same screen, and restores alternate 30 | screen before quitting or suspending. 31 | 32 | ============================================================================= 33 | 2. QUICK START ~ 34 | *altscreen-quickstart* 35 | 36 | 1. Install the plugin Eg. with Pathogen: 37 | > 38 | cd ~/.vim/bundle && git clone https://github.com/fcpg/vim-altscreen 39 | < 40 | 2. Work as usual; when you run external commands like `:!ls`, the output stays 41 | in the same screen. 42 | 43 | ============================================================================= 44 | 3. KEY MAPPINGS AND FUNCTIONS ~ 45 | *altscreen-keymappings* 46 | 47 | - 48 | Remapped to call |AltScreenControlZ|(). 49 | Won't clobber and existing map. 50 | 51 | *altscreen-functions* 52 | 53 | *UnsetAltScreen* 54 | 55 | Turns off alternate screen management from vim. 56 | 57 | *SetAltScreen* 58 | 59 | Restores alternate screen management from vim. 60 | 61 | *AltScreenControlZ* 62 | 63 | Restores alternate screen management just before suspending, then turns it 64 | back when resuming vim. 65 | 66 | ============================================================================= 67 | 4. CHANGELOG ~ 68 | *altscreen-changelog* 69 | 70 | [1.0] - 2017-02-16 71 | - Initial release 72 | 73 | ============================================================================= 74 | 5. CONTRIBUTE ~ 75 | *altscreen-contribute* 76 | 77 | Contribute on [Github](https://github.com/fcpg/vim-altscreen) 78 | 79 | ============================================================================= 80 | 6. LICENSE ~ 81 | *altscreen-license* 82 | 83 | [Attribution-ShareAlike 4.0 Int.](https://creativecommons.org/licenses/by-sa/4.0/) 84 | 85 | vim: set expandtab sts=2 ts=2 sw=2 tw=78 ft=help norl: 86 | -------------------------------------------------------------------------------- /plugin/altscreen.vim: -------------------------------------------------------------------------------- 1 | " altscreen.vim - alternate screen setup for terminal Vim 2 | if exists("g:loaded_altscreen") || &cp 3 | finish 4 | endif 5 | let g:loaded_altscreen = 1 6 | 7 | 8 | "---------------- 9 | " Functions {{{1 10 | "---------------- 11 | 12 | function! UnsetAltScreen() 13 | let g:altscreen_save_t_ti = &t_ti 14 | let g:altscreen_save_t_te = &t_te 15 | if get(g:, 'altscreen_reset', 1) 16 | let &t_ti = "" 17 | let &t_te = "" 18 | else 19 | let &t_ti = substitute(&t_ti, '\e\[?1049[hl]', '', '') 20 | let &t_te = substitute(&t_te, '\e\[?1049[hl]', '', '') 21 | endif 22 | endfun 23 | 24 | function! SetAltScreen() 25 | let &t_ti = g:altscreen_save_t_ti 26 | let &t_te = g:altscreen_save_t_te 27 | endfun 28 | 29 | function! AltScreenControlZ() 30 | try 31 | call SetAltScreen() 32 | if exists('#AltScreen#User#suspend') 33 | doauto AltScreen User suspend 34 | endif 35 | suspend! 36 | finally 37 | if exists('#AltScreen#User#resume') 38 | doauto AltScreen User resume 39 | endif 40 | call UnsetAltScreen() 41 | endtry 42 | endfun 43 | 44 | 45 | "----------- 46 | " Init {{{1 47 | "----------- 48 | 49 | " Autocmds {{{2 50 | augroup myNoAltScreen 51 | au! 52 | autocmd VimEnter * call UnsetAltScreen() 53 | autocmd VimLeave * call SetAltScreen() 54 | augroup END 55 | 56 | 57 | " Maps {{{2 58 | silent! noremap :call AltScreenControlZ() 59 | 60 | 61 | " vim: et sw=2: 62 | --------------------------------------------------------------------------------