├── autoload └── portal.vim ├── doc └── portal.txt └── plugin └── portal.vim /autoload/portal.vim: -------------------------------------------------------------------------------- 1 | " Make portals. 2 | " Version: 1.0 3 | " Author : thinca 4 | " License: zlib License 5 | 6 | let s:save_cpo = &cpo 7 | set cpo&vim 8 | 9 | " Points for portals 10 | let s:points = {} 11 | 12 | let s:jump_tagets = { 13 | \ 'blue': 'orange', 14 | \ 'orange': 'blue', 15 | \ } 16 | let s:jump_colors = { 17 | \ 'blue': { 18 | \ 'guibg': 'Blue', 19 | \ 'guifg': 'Blue', 20 | \ 'ctermbg': 'Blue', 21 | \ 'ctermfg': 'Blue', 22 | \ }, 23 | \ 'orange': { 24 | \ 'guibg': 'Orange', 25 | \ 'guifg': 'Orange', 26 | \ 'ctermbg': 'Red', 27 | \ 'ctermfg': 'Red', 28 | \ }, 29 | \ } 30 | 31 | function! portal#shoot(color, ...) 32 | let s:points[a:color] = get(a:, 1, s:getpos()) 33 | call portal#show_all() 34 | endfunction 35 | 36 | function! portal#reset() 37 | let s:points = {} 38 | call portal#show_all() 39 | endfunction 40 | 41 | function! portal#_complete(lead, line, pos) 42 | return filter(keys(s:jump_tagets), 'v:val =~# "^" . a:lead') 43 | endfunction 44 | 45 | function! portal#jump() 46 | let cur_pos = s:getpos() 47 | for [color, pos] in items(s:points) 48 | if cur_pos == pos 49 | let target = get(s:jump_tagets, color, '') 50 | if has_key(s:points, target) 51 | let target_pos = get(s:points, target) 52 | if cur_pos[0] != target_pos[0] 53 | execute target_pos[0] 'buffer' 54 | endif 55 | call cursor(target_pos[1 :]) 56 | endif 57 | break 58 | end 59 | endfor 60 | endfunction 61 | 62 | function! portal#show_all() 63 | let winnr = winnr() 64 | noautocmd keepjumps windo call portal#show() 65 | noautocmd keepjumps execute winnr 'wincmd w' 66 | endfunction 67 | 68 | function! portal#show() 69 | for m in filter(getmatches(), 'v:val.group =~# "^portal_"') 70 | silent! call matchdelete(m.id) 71 | endfor 72 | 73 | let buf = bufnr('%') 74 | for [color, pos] in items(s:points) 75 | if pos[0] == buf 76 | let pat = printf('\%%%dl\%%%dc', pos[1], pos[2]) 77 | let id = matchadd('portal_' . color, pat) 78 | endif 79 | endfor 80 | endfunction 81 | 82 | function! portal#highlight() 83 | for [name, colors] in items(s:jump_colors) 84 | let args = join(map(items(colors), 'v:val[0] . "=" . v:val[1]'), ' ') 85 | execute printf('highlight portal_%s %s', name, args) 86 | endfor 87 | endfunction 88 | 89 | function! s:getpos() 90 | let pos = getpos('.') 91 | let pos[0] = bufnr('%') 92 | return pos 93 | endfunction 94 | 95 | call portal#highlight() 96 | 97 | let &cpo = s:save_cpo 98 | unlet s:save_cpo 99 | -------------------------------------------------------------------------------- /doc/portal.txt: -------------------------------------------------------------------------------- 1 | *portal.txt* Hello and, again, this is the Portal Gun for Vim. 2 | 3 | Version: 1.0 4 | Author : thinca 5 | License: zlib License 6 | 7 | ============================================================================== 8 | CONTENTS *portal-contents* 9 | 10 | INTRODUCTION |portal-introduction| 11 | INTERFACE |portal-interface| 12 | COMMANDS |portal-commands| 13 | FUNCTIONS |portal-functions| 14 | KEY MAPPINGS |portal-key-mappings| 15 | CHANGELOG |portal-changelog| 16 | 17 | 18 | 19 | ============================================================================== 20 | INTRODUCTION *portal-introduction* 21 | 22 | *portal.vim* is a Vim plugin to provide the Portal Gun for Vim. 23 | You can open blue portal and orange portal, and you can jump the cursor 24 | between two portals. 25 | 26 | Reference: 27 | Portal Website 28 | - http://www.thinkwithportals.com/ 29 | Screen Cast 30 | - https://vimeo.com/71125575 31 | 32 | Requirements: 33 | - Vim 7.3 or later 34 | 35 | Latest version: 36 | https://github.com/thinca/vim-portal 37 | 38 | 39 | 40 | ============================================================================== 41 | INTERFACE *portal-interface* 42 | 43 | ------------------------------------------------------------------------------ 44 | COMMANDS *portal-commands* 45 | 46 | :PortalShoot {color} *:PortalShoot* 47 | Make a {color} portal at the current position. 48 | You can use "blue" or "orange" for {color}. 49 | 50 | :PortalReset *:PortalReset* 51 | Remove the all portals. 52 | 53 | 54 | ------------------------------------------------------------------------------ 55 | FUNCTIONS *portal-functions* 56 | 57 | portal#shoot({color}, [{position}]) *portal#shoot()* 58 | A function version of |:PortalShoot|. 59 | If a {position} is given, make a {color} portal at the position. 60 | {position} is a |List| with three numbers: 61 | [bufnum, lnum, col] 62 | "bufnum" is buffer number. 63 | "lnum" and "col" are the position in the buffer. 64 | 65 | 66 | portal#reset() *portal#reset()* 67 | A function version of |:PortalReset|. 68 | 69 | 70 | ------------------------------------------------------------------------------ 71 | KEY MAPPINGS *portal-key-mappings* 72 | 73 | (portal-gun-blue) *(portal-gun-blue)* 74 | Make a blue portal at the current position. 75 | 76 | (portal-gun-orange) *(portal-gun-orange)* 77 | Make a orange portal at the current position. 78 | 79 | *g:portal_no_default_key_mappings* 80 | Following key mappings will NOT be defined if it's already mapped, 81 | or |g:portal_no_default_key_mappings| has been set to 1. 82 | 83 | {lhs} {rhs} 84 | -------- ----------------------------- 85 | pb (portal-gun-blue) 86 | po (portal-gun-orange) 87 | 88 | 89 | 90 | ============================================================================== 91 | CHANGELOG *portal-changelog* 92 | 93 | 1.0 2013-07-27 94 | - Initial version. 95 | 96 | 97 | ============================================================================== 98 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 99 | -------------------------------------------------------------------------------- /plugin/portal.vim: -------------------------------------------------------------------------------- 1 | " Make portals. 2 | " Version: 1.0 3 | " Author : thinca 4 | " License: zlib License 5 | 6 | if exists('g:loaded_portal') 7 | finish 8 | endif 9 | let g:loaded_portal = 1 10 | 11 | let s:save_cpo = &cpo 12 | set cpo&vim 13 | 14 | command! -nargs=1 -bar -complete=customlist,portal#_complete 15 | \ PortalShoot call portal#shoot() 16 | command! -bar PortalReset call portal#reset() 17 | 18 | nnoremap (portal-gun-blue) :PortalShoot blue 19 | nnoremap (portal-gun-orange) :PortalShoot orange 20 | 21 | function! s:make_mapping(mode, lhs, rhs) 22 | if (exists('g:portal_no_default_key_mappings') && 23 | \ g:portal_no_default_key_mappings) || 24 | \ hasmapto(a:rhs, a:mode) 25 | return 26 | endif 27 | silent! execute a:mode . 'map ' a:lhs a:rhs 28 | endfunction 29 | call s:make_mapping('n', 'pb', '(portal-gun-blue)') 30 | call s:make_mapping('n', 'po', '(portal-gun-orange)') 31 | 32 | augroup plugin-portal 33 | autocmd! 34 | autocmd CursorMoved * nested call portal#jump() 35 | autocmd TabEnter * call portal#show_all() 36 | autocmd WinEnter,BufEnter * call portal#show() 37 | autocmd ColorScheme * call portal#highlight() 38 | augroup END 39 | 40 | let &cpo = s:save_cpo 41 | unlet s:save_cpo 42 | --------------------------------------------------------------------------------