Permalink
Browse files

Initial import

From 0c1ff307b465444 in my dotfiles repo
(https://github.com/wincent/wincent).
  • Loading branch information...
0 parents commit dea1df9edda1c99a061ab89502ce272d68fd4fb0 @wincent committed Jul 6, 2015
Showing with 367 additions and 0 deletions.
  1. +1 −0 README.txt
  2. +45 −0 autoload/terminus/private.vim
  3. +1 −0 doc/.gitignore
  4. +213 −0 doc/terminus.txt
  5. +107 −0 plugin/terminus.vim
@@ -0,0 +1,45 @@
+" Copyright 2015-present Greg Hurrell. All rights reserved.
+" Licensed under the terms of the BSD 2-clause license.
+
+function! s:escape(string) abort
+ " Double each <Esc>.
+ return substitute(a:string, "\<Esc>", "\<Esc>\<Esc>", 'g')
+endfunction
+
+function! terminus#private#wrap(string) abort
+ if strlen(a:string) == 0
+ return ''
+ end
+
+ let l:tmux_begin="\<Esc>Ptmux;"
+ let l:tmux_end="\<Esc>\\"
+
+ return l:tmux_begin . s:escape(a:string) . l:tmux_end
+endfunction
+
+function! terminus#private#focus_lost() abort
+ let l:cmdline=getcmdline()
+ let l:cmdpos=getcmdpos()
+
+ silent doautocmd FocusLost %
+
+ call setcmdpos(l:cmdpos)
+ return l:cmdline
+endfunction
+
+function! terminus#private#focus_gained() abort
+ let l:cmdline=getcmdline()
+ let l:cmdpos=getcmdpos()
+
+ " Our checktime autocmd will produce:
+ " E523: Not allowed here: checktime
+ silent! doautocmd FocusGained %
+
+ call setcmdpos(l:cmdpos)
+ return l:cmdline
+endfunction
+
+function! terminus#private#paste(ret) abort
+ set paste
+ return a:ret
+endfunction
@@ -0,0 +1 @@
+tags
@@ -0,0 +1,213 @@
+*terminus.txt* Terminus plug-in for Vim *terminus*
+
+CONTENTS *terminus-contents*
+
+1. Intro |terminus-intro|
+2. Installation |terminus-installation|
+3. Options |terminus-options|
+4. Overrides |terminus-overrides|
+5. Website |terminus-website|
+6. License |terminus-license|
+7. Authors |terminus-authors|
+8. History |terminus-history|
+
+
+INTRO *terminus-intro*
+
+ "terminus (noun, pl. termini or terminuses)
+ the end of a railroad or other transportation route, or a station at such
+ a point; a terminal."
+
+ *terminus-features*
+Terminus enhances Vim's integration with the terminal in four ways,
+particularly when using tmux (https://tmux.github.io/) and iTerm
+(https://www.iterm2.com/), closing the gap between terminal and GUI Vim:
+
+1. Cursor shape change in insert mode ~
+
+In insert mode, the cursor shape changes to a thin vertical bar. On leaving
+inset mode, it reverts to the standard "block" shape.
+
+2. Improved mouse support ~
+
+Activates 'mouse' support in all modes and additionally tries to activate
+|sgr-mouse| support, which allows the mouse to work "even in columns beyond
+223".
+
+3. Focus reporting ~
+
+Allows Vim to receive |FocusGained| and |FocusLost| events, even in the
+terminal and inside tmux. This is in turn used to fire the |:checktime|
+command, which, in conjunction with the 'autoread', allows Vim to
+automatically pick up changes made by other processes when switching to and
+from Vim.
+
+4. "Bracketed Paste" mode ~
+
+Sets up "Bracketed Paste" mode, which means you can forget about manually
+setting the 'paste' option and simply go ahead and paste in any mode.
+
+
+INSTALLATION *terminus-installation*
+
+To install Terminus, use your plug-in management system of choice.
+
+If you don't have a "plug-in management system of choice", I recommend
+Pathogen (https://github.com/tpope/vim-pathogen) due to its simplicity and
+robustness. Assuming that you have Pathogen installed and configured, and that
+you want to install Terminus into `~/.vim/bundle`, you can do so with: >
+
+ git clone https://github.com/wincent/terminus.git ~/.vim/bundle/terminus
+
+Alternatively, if you use a Git submodule for each Vim plug-in, you could do
+the following after `cd`-ing into the top-level of your Git superproject: >
+
+ git submodule add https://github.com/wincent/terminus.git ~/vim/bundle/terminus
+ git submodule init
+
+To generate help tags under Pathogen, you can do so from inside Vim with: >
+
+ :call pathogen#helptags()
+
+
+OPTIONS *terminus-options*
+
+ *g:TerminusCursorShape*
+ |g:TerminusCursorShape| boolean (default: 1)
+
+ Controls whether cursor shape changes are made when entering or leaving
+ insert mode. To disable, set to 0: >
+
+ let g:TerminusCursorShape=0
+<
+ *g:TerminusMouse*
+ |g:TerminusMouse| boolean (default: 1)
+
+ Controls whether Terminus attempts to improve mouse function by setting the
+ 'mouse' and 'typemouse' settings. To disable this action, set to 0: >
+
+ let g:TerminusMouse=0
+<
+ *g:TerminusFocusReporting*
+ |g:TerminusFocusReporting| boolean (default: 1)
+
+ Controls whether Terminus attempts to enable focus reporting and therefore
+ |FocusGained| and |FocusLost| events, which then trigger the |:checktime|
+ command and allow changed files to be refreshed automatically via
+ 'autoread'. To disable this feature, set to 0: >
+
+ let g:TerminusFocusReporting=0
+<
+ *g:TerminusBracketedPaste*
+ |g:TerminusBracketedPaste| boolean (default: 1)
+
+ Controls whether Terminus attempts to set-up Bracketed Paste mode. To
+ disable, set to 0: >
+
+ let g:TerminusBracketedPaste=0
+<
+ *terminus-assume-iterm*
+ *g:TerminusAssumeITerm*
+ |g:TerminusAssumeITerm| any (no default)
+
+ Terminus will try to autodetect when Vim is running inside of iTerm,
+ but it is possible that when running on a remote host via SSH the necessary
+ environment variables (`$ITERM_PROFILE` or `$ITERM_SESSION_ID`) may not be
+ present.
+
+ In this case, it is possible to signal to Terminus that iTerm is operative by
+ doing either of the following:
+
+ - Touching (ie. creating) a file at `~/.vim/.assume-iterm`.
+ - Setting |g:TerminusAssumeITerm| to any value
+
+ *g:TerminusLoaded*
+ |g:TerminusLoaded| any (no default)
+
+ To prevent Terminus from being loaded, set |g:TerminusLoaded| to any value
+ in your |.vimrc|. For example: >
+
+ let g:TerminusLoaded=1
+<
+
+OVERRIDES *terminus-overrides*
+
+Terminus sets some Vim settings to reasonable defaults in order to provide a
+good "out of the box" experience:
+
+ *terminus-autoread*
+ 'autoread'
+
+ Turned on (if a file change made outside of Vim is detected as the result of
+ running the |:checktime| command, reloads the file).
+
+ *terminus-ttimeoutlen*
+ 'ttimeoutlen'
+
+ Reduced to 50 (milliseconds) to speed of the response of some mappings (for
+ example, |O|) in the terminal. If the effective 'ttimeoulen' is already 50
+ or lower, Terminus leaves this setting untouched.
+
+To override any of these choices, you can place overrides in an
+|after-directory| (ie. `~/.vim/after/plugin/terminus.vim`). For example: >
+
+ " Override Terminus' 'autoread' setting.
+ set noautoread
+
+
+WEBSITE *terminus-website*
+
+The official Terminus source code repo is at:
+
+ http://git.wincent.com/terminus.git
+
+A mirror exists at:
+
+ https://github.com/wincent/terminus
+
+Official releases are listed at:
+
+ http://www.vim.org/scripts/script.php?script_id=5216
+
+
+LICENSE *terminus-license*
+
+Copyright 2015-present Greg Hurrell. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+
+AUTHORS *terminus-authors*
+
+Terminus is written and maintained by Greg Hurrell <greg@hurrell.net>.
+
+
+HISTORY *terminus-history*
+
+0.1 (6 July 2015)
+
+- initial release, extracted from my dotfiles
+ (https://github.com/wincent/wincent)
+
+
+-----------------------------------------------------------------------------
+vim:tw=78:ft=help:
@@ -0,0 +1,107 @@
+" Copyright 2015-present Greg Hurrell. All rights reserved.
+" Licensed under the terms of the BSD 2-clause license.
+
+" Provide users with means to prevent loading, as recommended in `:h
+" write-plugin`.
+if exists('g:TerminusLoaded') || &compatible || v:version < 700
+ finish
+endif
+let g:LoupeLoaded=1
+
+" Temporarily set 'cpoptions' to Vim default as per `:h use-cpo-save`.
+let s:cpoptions=&cpoptions
+set cpoptions&vim
+
+set autoread " if not changed in Vim, automatically pick up changes after "git checkout" etc
+if &ttimeoutlen == -1 && &timeoutlen > 50 || &ttimeoutlen > 50
+ set ttimeoutlen=50 " speed up O etc in the Terminal
+endif
+
+let s:iterm=exists('$ITERM_PROFILE') || exists('$ITERM_SESSION_ID') || exists('g:TerminusAssumeITerm') || filereadable(expand('~/.vim/.assume-iterm'))
+let s:screen=&term =~# 'screen'
+let s:tmux=exists('$TMUX')
+let s:xterm=&term =~# 'xterm'
+
+" Change shape of cursor in insert mode in iTerm 2.
+let s:shape=exists('g:TerminusCursorShape') ? g:TerminusCursorShape : 1
+if s:shape
+ if s:iterm
+ let s:start_insert="\<Esc>]50;CursorShape=1\x7"
+ let s:end_insert="\<Esc>]50;CursorShape=0\x7"
+
+ if s:tmux
+ let s:start_insert=terminus#private#wrap(s:start_insert)
+ let s:end_insert=terminus#private#wrap(s:end_insert)
+ endif
+
+ let &t_SI=s:start_insert
+ let &t_EI=s:end_insert
+ endif
+endif
+
+let s:mouse=exists('g:TerminusMouse') ? g:TerminusMouse : 1
+if s:mouse
+ if has('mouse')
+ set mouse=a
+ if s:screen || s:xterm
+ if has('mouse_sgr')
+ set ttymouse=sgr
+ else
+ set ttymouse=xterm2
+ endif
+ endif
+ endif
+endif
+
+let s:focus=exists('g:TerminusFocusReporting') ? g:TerminusFocusReporting : 1
+if s:focus
+ if has('autocmd')
+ augroup Terminus
+ autocmd!
+ autocmd FocusGained * checktime
+ augroup END
+ endif
+
+ " Enable focus reporting on entering Vim.
+ let &t_ti.="\e[?1004h"
+ " Disable focus reporting on leaving Vim.
+ let &t_te="\e[?1004l" . &t_te
+
+ execute "set <f20>=\<Esc>[O"
+ execute "set <f21>=\<Esc>[I"
+ cnoremap <silent> <f20> <c-\>eterminus#private#focus_lost()<cr>
+ cnoremap <silent> <f21> <c-\>eterminus#private#focus_gained()<cr>
+ inoremap <silent> <f20> <c-o>:silent doautocmd FocusLost %<cr>
+ inoremap <silent> <f21> <c-o>:silent doautocmd FocusGained %<cr>
+ nnoremap <silent> <f20> :doautocmd FocusLost %<cr>
+ nnoremap <silent> <f21> :doautocmd FocusGained %<cr>
+ onoremap <silent> <f20> <Esc>:silent doautocmd FocusLost %<cr>
+ onoremap <silent> <f21> <Esc>:silent doautocmd FocusGained %<cr>
+ vnoremap <silent> <f20> <Esc>:silent doautocmd FocusLost %<cr>gv
+ vnoremap <silent> <f21> <Esc>:silent doautocmd FocusGained %<cr>gv
+endif
+
+let s:paste=exists('g:TerminusBracketedPaste') ? g:TerminusBracketedPaste : 1
+if s:paste
+ " Make use of Xterm "bracketed paste mode". See:
+ " - http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode
+ " - http://stackoverflow.com/questions/5585129
+ if s:screen || s:xterm
+ " Enable bracketed paste mode on entering Vim.
+ let &t_ti.="\e[?2004h"
+
+ " Disable bracketed paste mode on leaving Vim.
+ let &t_te="\e[?2004l" . &t_te
+
+ set pastetoggle=<Esc>[201~
+ inoremap <expr> <Esc>[200~ terminus#private#paste('')
+ nnoremap <expr> <Esc>[200~ terminus#private#paste('i')
+ vnoremap <expr> <Esc>[200~ terminus#private#paste('c')
+ cnoremap <Esc>[200~ <nop>
+ cnoremap <Esc>[201~ <nop>
+ endif
+endif
+
+" Restore 'cpoptions' to its former value.
+let &cpoptions=s:cpoptions
+unlet s:cpoptions

0 comments on commit dea1df9

Please sign in to comment.