├── .gitignore ├── README.mkd ├── README_JA.mkd ├── autoload └── minimap.vim ├── image ├── animation.gif └── screenshot.png └── plugin └── minimap_loader.vim /.gitignore: -------------------------------------------------------------------------------- 1 | VIM_AUTO_RTP 2 | tmp/ 3 | -------------------------------------------------------------------------------- /README.mkd: -------------------------------------------------------------------------------- 1 | # Minimap plugin for Vim 2 | 3 | For Japanese please read [README\_JA.mkd](README_JA.mkd). 4 | 5 | Minimap is a file overview sidebar plugin for Vim like the Sublime's 6 | Minimap. It only works with Gvim or MacVim. 7 | 8 | ## How it works 9 | 10 | Minimap utilizes a new buffer and sets the fonts size to 3 points. It 11 | then synchronizes the Minimap buffer with the main editing buffer. 12 | 13 | ![Minimap Animation](image/animation.gif "MiniMap in MacVim") 14 | 15 | ![Screenshot](image/screenshot.png) 16 | 17 | ## Installation 18 | 19 | ### Regular installation 20 | 21 | - Download zip archive from GitHub 22 | - Unzip the archive 23 | 24 | ``` 25 | cd unzipped-dir 26 | cp -r plugin ~/.vim/ 27 | cp -r autoload ~/.vim/ 28 | ``` 29 | 30 | - Restart Gvim or MacVim 31 | 32 | ### Install with Janus 33 | 34 | ``` 35 | cd ~/.janus 36 | git clone https://github.com/koron/minimap-vim.git minimap 37 | ``` 38 | 39 | ## How to use 40 | 41 | Open Gvim or MacVim 42 | 43 | ``` 44 | :e /some/long/file.code 45 | :MinimapSync 46 | ``` 47 | 48 | ## Warning 49 | 50 | This plugin is very experimental. Not suitable for production. 51 | -------------------------------------------------------------------------------- /README_JA.mkd: -------------------------------------------------------------------------------- 1 | # Minimap plugin for Vim 2 | 3 | For English please read [README.mkd](README.mkd). 4 | 5 | Minimap はファイルの概要を別ウィンドウに表示するプラグインです。Sublimeにある同名の機能と同等です。GvimもしくはMacVimで動作します。 6 | 7 | ## まずはご覧あれ 8 | 9 | ![Minimap Animation](image/animation.gif "MiniMap in MacVim") 10 | 11 | ![Screenshot](image/screenshot.png) 12 | 13 | ## 使い方 14 | 15 | 1. runtimepath にこのディレクトリを加えるなどしてインストール 16 | 2. gvimを起動する (香り屋版推奨というかそれしかテストしてない) 17 | 2. 適当なファイルを開く `:e $VIM/README.txt` 18 | 3. `:MinimapSync` を実行する 19 | 20 | ワオ! 21 | 22 | ## 注意事項 23 | 24 | まだ実験段階なので、環境によっては動かないかも。許せ。 25 | -------------------------------------------------------------------------------- /autoload/minimap.vim: -------------------------------------------------------------------------------- 1 | " vim:set ts=8 sts=2 sw=2 tw=0 et nowrap: 2 | " 3 | " minimap.vim - Autoload of minimap plugin for Vim. 4 | " 5 | " License: THE VIM LICENSE 6 | " 7 | " Copyright: 8 | " - (C) 2012 MURAOKA Taro (koron.kaoriya@gmail.com) 9 | 10 | scriptencoding utf-8 11 | 12 | let s:minimap_id = 'MINIMAP' 13 | let s:minimap_mode = get(s:, 'minimap_mode', 0) 14 | 15 | function! minimap#_is_open(id) 16 | let servers = split(serverlist(), '\n', 0) 17 | return len(filter(servers, 'v:val ==? a:id')) > 0 ? 1 : 0 18 | endfunction 19 | 20 | function! minimap#_open(id, ack) 21 | if has('gui_macvim') 22 | call minimap#_open_macvim(a:id, a:ack) 23 | elseif has('win32') || has('win64') 24 | call minimap#_open_win(a:id, a:ack) 25 | else 26 | call minimap#_open_others(a:id, a:ack) 27 | endif 28 | endfunction 29 | 30 | function! minimap#_open_macvim(id, ack) 31 | let macvim_dir = $VIM . '/../../../..' 32 | let cmd_args = [ 33 | \ macvim_dir . '/MacVim.app/Contents/MacOS/Vim', 34 | \ '-g', 35 | \ '--servername', a:id, 36 | \ '-c', printf("\"let g:minimap_ack=\'%s\'\"", a:ack), 37 | \ ] 38 | silent execute '!'.join(cmd_args, ' ') 39 | endfunction 40 | 41 | function! minimap#_open_win(id, ack) 42 | let args = [ 43 | \ 'gvim', 44 | \ '--servername', a:id, 45 | \ '-c', printf("\"let g:minimap_ack=\'%s\'\"", a:ack), 46 | \ ] 47 | silent execute '!start '.join(args, ' ') 48 | endfunction 49 | 50 | function! minimap#_open_others(id, ack) 51 | let args = [ 52 | \ 'gvim', 53 | \ '--servername', a:id, 54 | \ '-c', printf("\"let g:minimap_ack=\'%s\'\"", a:ack), 55 | \ '&', 56 | \ ] 57 | silent execute '!'.join(args, ' ') 58 | endfunction 59 | 60 | function! minimap#_capture() 61 | return { 62 | \ 'sender': v:servername, 63 | \ 'path': minimap#_get_current_path(), 64 | \ 'line': line('.'), 65 | \ 'col': col('.'), 66 | \ 'start': line('w0'), 67 | \ 'end': line('w$'), 68 | \ } 69 | endfunction 70 | 71 | function! minimap#_send(id) 72 | let data = minimap#_capture() 73 | let expr = printf('minimap#_on_recv("%s")', string(data)) 74 | call remote_expr(a:id, expr) 75 | endfunction 76 | 77 | function! minimap#_on_open() 78 | " setup view parameters. 79 | call minimap#_set_small_font() 80 | set guioptions= laststatus=0 cmdheight=1 nowrap 81 | set columns=80 foldcolumn=0 82 | set scrolloff=0 83 | set cursorline 84 | hi clear CursorLine 85 | hi link CursorLine Cursor 86 | winpos 0 0 87 | set lines=999 88 | 89 | " send ACK for open. 90 | if exists('g:minimap_ack') 91 | let expr = printf(':call minimap#_ack_open("%s")', v:servername) 92 | call remote_send(g:minimap_ack, expr) 93 | if !has('gui_macvim') 94 | call remote_foreground(g:minimap_ack) 95 | endif 96 | unlet g:minimap_ack 97 | endif 98 | endfunction 99 | 100 | function! minimap#_set_small_font() 101 | if has('gui_macvim') 102 | set noantialias 103 | set guifont=Osaka-Mono:h3 104 | elseif has('gui_win32') 105 | set guifont=MS_Gothic:h3:cSHIFTJIS 106 | elseif has('gui_gtk2') 107 | set guifont=Monospace\ 3 108 | else 109 | " TODO: for other platforms. 110 | endif 111 | endfunction 112 | 113 | function! minimap#_get_current_path() 114 | return substitute(expand('%:p'), '\\', '/', 'g') 115 | endfunction 116 | 117 | let s:cached_sync_data = '' 118 | 119 | function! minimap#_sync_data() 120 | return s:cached_sync_data 121 | endfunction 122 | 123 | function! minimap#_remote_pull_sync(id) 124 | let s:cached_sync_data = string(minimap#_capture()) 125 | let keys = printf(':call minimap#_pull_sync("%s")', v:servername) 126 | call remote_send(a:id, keys) 127 | endfunction 128 | 129 | function! minimap#_pull_sync(id) 130 | "echo printf('minimap: update required by %s', a:id) 131 | let data = eval(remote_expr(a:id, 'minimap#_sync_data()')) 132 | if len(data) 133 | call minimap#_apply(data) 134 | endif 135 | endfunction 136 | 137 | function! minimap#_on_recv(data) 138 | call minimap#_apply(eval(a:data)) 139 | endfunction 140 | 141 | function! minimap#_apply(data) 142 | let path = a:data['path'] 143 | if len(path) == 0 144 | return 145 | endif 146 | if path !=# minimap#_get_current_path() 147 | execute 'view! ' . path 148 | endif 149 | if path ==# minimap#_get_current_path() 150 | call minimap#_set_view_range(a:data['line'], a:data['col'], 151 | \ a:data['start'], a:data['end']) 152 | endif 153 | endfunction 154 | 155 | function! minimap#_set_view_range(line, col, start, end) 156 | " ensure to show view range. 157 | if a:start < line('w0') 158 | silent execute printf('normal! %dGzt', a:start) 159 | endif 160 | if a:end > line('w$') 161 | silent execute printf('normal! %dGzb', a:end) 162 | endif 163 | " mark view range. 164 | let p1 = printf('\%%>%dl\%%<%dl', a:start - 1, a:line) 165 | let p2 = printf('\%%>%dl\%%<%dl', a:line, a:end + 1) 166 | silent execute printf('match Search /\(%s\|%s\).*/', p1, p2) 167 | " move cursor 168 | call cursor(a:line, a:col) 169 | "redraw 170 | endfunction 171 | 172 | function! minimap#_set_autosync() 173 | let s:minimap_mode = 1 174 | augroup minimap_auto 175 | autocmd! 176 | autocmd CursorMoved * call minimap#_lazysync() 177 | autocmd CursorMovedI * call minimap#_lazysync() 178 | augroup END 179 | endfunction 180 | 181 | function! minimap#_unset_autosync() 182 | let s:minimap_mode = 0 183 | augroup minimap_auto 184 | autocmd! 185 | augroup END 186 | endfunction 187 | 188 | function! minimap#_send_and_enter_minimap_mode(id) 189 | "call minimap#_send(a:id) 190 | call minimap#_remote_pull_sync(a:id) 191 | if s:minimap_mode == 0 192 | call minimap#_enter_minimap_mode() 193 | endif 194 | endfunction 195 | 196 | function! minimap#_sync() 197 | let id = s:minimap_id 198 | if minimap#_is_open(id) == 0 199 | call minimap#_open(id, v:servername) 200 | else 201 | call minimap#_send_and_enter_minimap_mode(id) 202 | endif 203 | endfunction 204 | 205 | let s:lazysync_count = get(s:, 'lazysync_count', 0) 206 | 207 | function! minimap#_lazysync() 208 | let s:lazysync_count += 1 209 | call feedkeys("\(lazysync-do)", 'm') 210 | endfunction 211 | 212 | function! minimap#_lazysync_do() 213 | if s:lazysync_count > 0 214 | let s:lazysync_count -= 1 215 | if s:lazysync_count == 0 216 | call minimap#_sync() 217 | endif 218 | endif 219 | return '' 220 | endfunction 221 | 222 | function! minimap#_ack_open(id) 223 | if has('gui_macvim') 224 | call foreground() 225 | endif 226 | call minimap#_send_and_enter_minimap_mode(a:id) 227 | endfunction 228 | 229 | function! minimap#_delete_command(cmd) 230 | if exists(':' . a:cmd) 231 | execute 'delcommand ' . a:cmd 232 | endif 233 | endfunction 234 | 235 | function! minimap#_enter_minimap_mode() 236 | call minimap#_set_autosync() 237 | call minimap#_delete_command('MinimapSync') 238 | command! MinimapStop call minimap#_leave_minimap_mode() 239 | endfunction 240 | 241 | function! minimap#_leave_minimap_mode() 242 | call minimap#_unset_autosync() 243 | call minimap#_delete_command('MinimapStop') 244 | command! MinimapSync call minimap#_sync() 245 | endfunction 246 | 247 | function! minimap#init() 248 | if v:servername =~? s:minimap_id 249 | call minimap#_on_open() 250 | else 251 | command! MinimapSync call minimap#_sync() 252 | nnoremap (lazysync-do) :call minimap#_lazysync_do() 253 | inoremap (lazysync-do) =minimap#_lazysync_do() 254 | endif 255 | endfunction 256 | -------------------------------------------------------------------------------- /image/animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koron/minimap-vim/5cdf7069fcb071debc7a33bfd0865e0c533fc3f8/image/animation.gif -------------------------------------------------------------------------------- /image/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koron/minimap-vim/5cdf7069fcb071debc7a33bfd0865e0c533fc3f8/image/screenshot.png -------------------------------------------------------------------------------- /plugin/minimap_loader.vim: -------------------------------------------------------------------------------- 1 | " vim:set ts=8 sts=2 sw=2 tw=0 et nowrap: 2 | " 3 | " minimap_loader.vim - Loader of minimap plugin for Vim. 4 | " 5 | " License: THE VIM LICENSE 6 | " 7 | " Copyright: 8 | " - (C) 2012 MURAOKA Taro (koron.kaoriya@gmail.com) 9 | 10 | scriptencoding utf-8 11 | 12 | augroup minimap_loader 13 | autocmd! 14 | autocmd VimEnter * call minimap#init() 15 | augroup END 16 | --------------------------------------------------------------------------------