├── README.md ├── autoload ├── airline │ └── extensions │ │ └── anzu.vim ├── anzu.vim ├── anzu │ └── mode.vim └── unite │ └── sources │ └── anzu.vim ├── doc ├── anzu.jax └── anzu.txt └── plugin └── anzu.vim /README.md: -------------------------------------------------------------------------------- 1 | ## vim-anzu 2 | 3 | 現在の検索位置を画面に表示するためのプラグインです。 4 | 5 | ![test](https://f.cloud.github.com/assets/214488/999607/67346324-0a34-11e3-8264-158c8865d669.gif) 6 | ![anzu3](https://f.cloud.github.com/assets/214488/1506514/25dc147c-4930-11e3-9780-a81c8ae7e087.gif) 7 | 8 | 9 | #### Example 10 | 11 | ```vim 12 | " mapping 13 | nmap n (anzu-n-with-echo) 14 | nmap N (anzu-N-with-echo) 15 | nmap * (anzu-star-with-echo) 16 | nmap # (anzu-sharp-with-echo) 17 | 18 | " clear status 19 | nmap (anzu-clear-search-status) 20 | 21 | 22 | " statusline 23 | set statusline=%{anzu#search_status()} 24 | 25 | 26 | " if start anzu-mode key mapping 27 | " anzu-mode is anzu(12/51) in screen 28 | " nmap n (anzu-mode-n) 29 | " nmap N (anzu-mode-N) 30 | ``` 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /autoload/airline/extensions/anzu.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | 3 | 4 | function! airline#extensions#anzu#init(ext) 5 | let g:anzu_enable_CursorHold_AnzuUpdateSearchStatus 6 | \ = get(g:, 'anzu_enable_CursorHold_AnzuUpdateSearchStatus', 2) 7 | call airline#parts#define_function('anzu', 'anzu#search_status') 8 | call a:ext.add_statusline_func('airline#extensions#anzu#apply') 9 | endfunction 10 | 11 | function! airline#extensions#anzu#apply(...) 12 | call airline#extensions#append_to_section(get(g:, "anzu_airline_section", "y"), " %{anzu#search_status()}") 13 | endfunction 14 | -------------------------------------------------------------------------------- /autoload/anzu.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | let s:save_cpo = &cpo 3 | set cpo&vim 4 | 5 | let s:status_cache = "" 6 | 7 | function! anzu#search_status() 8 | return substitute(s:status_cache, '.\{-}<\/anzustatushighlight>', "", "g") 9 | endfunction 10 | 11 | function! anzu#clear_search_status() 12 | let s:status_cache = "" 13 | endfunction 14 | 15 | function! anzu#echohl_search_status() 16 | if empty(s:status_cache) 17 | return 18 | endif 19 | let text = s:status_cache 20 | try 21 | let len = 0 22 | let max_len = &columns * (&cmdheight -1) + &columns / 2 23 | for word in split(text . "None<\/anzustatushighlight>", '.\{-}<\/anzustatushighlight>\zs') 24 | let output = matchstr(word, '\zs.*\ze.*<\/anzustatushighlight>') 25 | if max_len > len + len(output) 26 | echon output 27 | let len += len(output) 28 | else 29 | echon output[ : max_len - len -1 ] 30 | return 31 | endif 32 | execute "echohl" matchstr(word, '.*\zs.*\ze<\/anzustatushighlight>') 33 | endfor 34 | finally 35 | echohl None 36 | endtry 37 | endfunction 38 | 39 | 40 | " a <= b 41 | function! s:pos_less_equal(a, b) 42 | return a:a[0] == a:b[0] ? a:a[1] <= a:b[1] : a:a[0] <= a:b[0] 43 | endfunction 44 | 45 | 46 | " function! s:search_less_pos(pos_list, pos) 47 | " let index = 0 48 | " for pos in a:pos_list 49 | " if s:pos_less_equal(a:pos, pos) 50 | " return index 51 | " endif 52 | " let index = index + 1 53 | " endfor 54 | " return -1 55 | " endfunction 56 | 57 | 58 | function! s:print_status(format, pattern, index, len, wrap) 59 | let result = a:format 60 | let result = substitute(result, '%#\(.\{-}\)#', '\1<\/anzustatushighlight>', "g") 61 | let result = substitute(result, '%i', a:index, "g") 62 | let result = substitute(result, '%l', a:len, "g") 63 | let result = substitute(result, '%w', a:wrap, "g") 64 | let result = substitute(result, '%p', a:pattern, "g") 65 | " Fix \ to view 66 | let result = substitute(result, '%/', substitute(histget("/", -1), '\\', '\\\\', "g"), "g") 67 | return result 68 | endfunction 69 | 70 | 71 | function! s:clamp_pos(pos, min, max) 72 | return s:pos_less_equal(a:min, a:pos) && s:pos_less_equal(a:pos, a:max) 73 | endfunction 74 | 75 | 76 | function! anzu#get_on_pattern_pos(pat) 77 | if a:pat == "" 78 | return getpos(".") 79 | endif 80 | let pos = getpos(".") 81 | let first = searchpos(a:pat, 'nWbc') 82 | let last = searchpos(a:pat, 'nWeb') 83 | if s:pos_less_equal(last, first) 84 | let last = searchpos(a:pat, 'nWec') 85 | endif 86 | if s:clamp_pos(pos[1:2], first, last) 87 | return [0, first[0], first[1], 0] 88 | endif 89 | return pos 90 | endfunction 91 | 92 | 93 | function! anzu#update(pattern, cursor_pos, ...) 94 | let pattern = a:pattern 95 | let cursor = a:cursor_pos 96 | if pattern == "" 97 | return 98 | endif 99 | 100 | let pos_all = s:searchpos(pattern) 101 | 102 | if empty(pos_all) 103 | let s:status_cache = s:print_status(g:anzu_no_match_word, pattern, "", "", "") 104 | return -1 105 | endif 106 | 107 | let index = index(pos_all, [cursor[1], cursor[2]]) 108 | if index == -1 109 | return -1 110 | endif 111 | 112 | let wrap_mes = get(a:, 1, "") 113 | 114 | let pattern = substitute(pattern, '\\', '\\\\', 'g') 115 | let s:status_cache = s:print_status(g:anzu_status_format, pattern, index+1, len(pos_all), wrap_mes) 116 | endfunction 117 | 118 | 119 | function! anzu#clear_search_cache(...) 120 | let bufnr = get(a:, 1, bufnr("%")) 121 | call setbufvar(bufnr, "anzu_searchpos_cache", {}) 122 | endfunction 123 | 124 | 125 | function! anzu#getpos(pattern, count) 126 | return get(s:searchpos(a:pattern), a:count, []) 127 | endfunction 128 | 129 | 130 | function! anzu#jump(pattern, count) 131 | let pos = anzu#getpos(a:pattern, a:count) 132 | if empty(pos) 133 | return 134 | endif 135 | call setpos(".", [0] + pos + [0]) 136 | endfunction 137 | 138 | 139 | function! anzu#jump_key(key, count) 140 | if a:count 141 | call anzu#jump(@/, a:count - 1) 142 | AnzuUpdateSearchStatus 143 | else 144 | if !empty(a:key) 145 | try 146 | execute "normal" a:key 147 | catch 148 | echohl ErrorMsg | echo matchstr(v:exception, 'Vim(normal):\zs.*\ze') | echohl None 149 | call anzu#clear_search_status() 150 | return -1 151 | endtry 152 | " execute "normal" a:key 153 | endif 154 | endif 155 | endfunction 156 | 157 | 158 | function! anzu#mapexpr_jump(...) 159 | let l:count = get(a:, 1, "") 160 | let key = get(a:, 2, "") 161 | return ":\if anzu#jump_key(\"" . key . "\", " . l:count . ") != -1 \ set hlsearch \ endif\" 162 | endfunction 163 | 164 | 165 | function! s:searchpos(pattern, ...) 166 | let bufnr = get(a:, 1, bufnr("%")) 167 | let uncache = get(a:, 2, 0) 168 | if uncache 169 | return s:searchpos_all(a:pattern) 170 | endif 171 | let cache = getbufvar(bufnr, "anzu_searchpos_cache") 172 | if type(cache) == type("") 173 | unlet cache 174 | let cache = {} 175 | endif 176 | 177 | if has_key(cache, a:pattern) 178 | return deepcopy(cache[a:pattern]) 179 | endif 180 | let searchpos = s:searchpos_all(a:pattern) 181 | let cache[a:pattern] = searchpos 182 | call setbufvar(bufnr, "anzu_searchpos_cache", cache) 183 | return searchpos 184 | endfunction 185 | 186 | 187 | 188 | function! s:searchpos_all(pattern) 189 | " winsave view correctly restores curswant 190 | let old_pos = winsaveview() 191 | let result = [] 192 | try 193 | call setpos(".", [0, line("$"), strlen(getline("$")), 0]) 194 | while 1 195 | silent! let pos = searchpos(a:pattern, "w") 196 | if pos == [0, 0] || index(result, pos) != -1 197 | break 198 | endif 199 | call add(result, pos) 200 | if len(result) >= g:anzu_search_limit 201 | break 202 | endif 203 | endwhile 204 | finally 205 | call winrestview(old_pos) 206 | endtry 207 | return result 208 | endfunction 209 | 210 | function! anzu#searchpos(...) 211 | return call("s:searchpos", a:000) 212 | endfunction 213 | 214 | 215 | function! anzu#clear_sign_matchline() 216 | call s:clear_sign_all() 217 | endfunction 218 | 219 | 220 | " 1はダミーに使用 221 | let s:sign_id_dummy = 1 222 | let s:sign_id_init = 2 223 | let s:sign_id_count = s:sign_id_init 224 | function! s:sign(line, bufnr) 225 | execute printf("sign place %d line=%d name=anzu_sign_matchline buffer=%d", s:sign_id_count, a:line, a:bufnr) 226 | let s:sign_id_count += 1 227 | endfunction 228 | 229 | function! s:clear_sign_id(id) 230 | execute printf("sign unplace %d", a:id) 231 | endfunction 232 | 233 | function! s:clear_sign_all() 234 | call map(range(s:sign_id_init, s:sign_id_count), "s:clear_sign_id(v:val)") 235 | let s:sign_id_count = s:sign_id_init 236 | endfunction 237 | 238 | function! s:is_signed() 239 | return s:sign_id_count != s:sign_id_init 240 | endfunction 241 | 242 | 243 | function! anzu#sign_matchline(pattern) 244 | highlight AnzuMatchline ctermbg=Yellow ctermfg=Yellow guibg=Yellow guifg=Yellow 245 | sign define anzu_sign_matchline text=>> texthl=AnzuMatchline 246 | 247 | highlight AnzuDummyhighlight ctermbg=NONE ctermfg=NONE guibg=NONE guifg=NONE 248 | sign define anzu_sign_dummy texthl=AnzuDummyhighlight 249 | 250 | call s:update_sign(a:pattern) 251 | endfunction 252 | 253 | 254 | let s:cache_top = 0 255 | let s:cache_bottom = 0 256 | function! anzu#smart_sign_matchline(pattern) 257 | let top = line("w0") 258 | let bottom = line("w$") 259 | if s:is_signed() && (top == s:cache_top && bottom == s:cache_bottom) 260 | return 261 | endif 262 | let s:cache_top = top 263 | let s:cache_bottom = bottom 264 | call anzu#sign_matchline(a:pattern) 265 | endfunction 266 | 267 | 268 | function! s:sign_lines(pattern) 269 | let top = line("w0") 270 | let bottom = line("w$") 271 | let height = bottom - top 272 | let rate = str2float(height) / line("$") 273 | let lines = map(deepcopy(s:searchpos(a:pattern)), "float2nr(v:val[0] * rate) + top") 274 | return lines 275 | endfunction 276 | 277 | 278 | function! s:update_sign(pattern) 279 | let lines = s:sign_lines(a:pattern) 280 | if empty(lines) 281 | return 282 | endif 283 | 284 | let lines = s:uniq_sort(lines) 285 | 286 | " チラツキ防止用 287 | execute printf("sign place %d line=1 name=anzu_sign_dummy buffer=%d", s:sign_id_dummy, bufnr("%")) 288 | try 289 | AnzuClearSignMatchLine 290 | let bufnr = bufnr("%") 291 | call map(lines, "s:sign(v:val, bufnr)") 292 | finally 293 | execute printf("sign unplace %d", s:sign_id_dummy) 294 | endtry 295 | endfunction 296 | 297 | function! s:uniq_sort(list) 298 | let result = [] 299 | for item in a:list 300 | if index(result, item) == -1 301 | call add(result, item) 302 | endif 303 | endfor 304 | return result 305 | endfunction 306 | 307 | 308 | let &cpo = s:save_cpo 309 | unlet s:save_cpo 310 | -------------------------------------------------------------------------------- /autoload/anzu/mode.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | let s:save_cpo = &cpo 3 | set cpo&vim 4 | 5 | function! s:pos_less_equal(a, b) 6 | return a:a[0] == a:b[0] ? a:a[1] <= a:b[1] : a:a[0] <= a:b[0] 7 | endfunction 8 | 9 | 10 | function! s:get_text_from_region(first, last, ...) 11 | let wise = get(a:, 1, "v") 12 | 13 | let old_selection = &selection 14 | let &selection = 'inclusive' 15 | 16 | let register = v:register == "" ? '"' : v:register 17 | let old_pos = getpos(".") 18 | let old_reg = getreg(register) 19 | let old_first = getpos("'[") 20 | let old_last = getpos("']") 21 | try 22 | call setpos("'[", a:first) 23 | call setpos("']", a:last) 24 | execute printf('silent normal! `[%s`]y', wise) 25 | return getreg(register) 26 | finally 27 | call setpos("'[", old_first) 28 | call setpos("']", old_last) 29 | call setreg(register, old_reg) 30 | call setpos(".", old_pos) 31 | let &selection = old_selection 32 | endtry 33 | endfunction 34 | 35 | 36 | function! s:get_text_from_pattern(pattern, ...) 37 | let wise = get(a:, 1, "v") 38 | let first = searchpos(a:pattern, "Wncb") 39 | if first == [0, 0] 40 | return "" 41 | endif 42 | let last = searchpos(a:pattern, "Wnce") 43 | if last == [0, 0] 44 | return "" 45 | endif 46 | return s:get_text_from_region([0] + first + [0], [0] + last + [0], wise) 47 | endfunction 48 | 49 | 50 | function! s:getchar() 51 | let char = getchar() 52 | return type(char) == type(0) ? nr2char(char) : char 53 | endfunction 54 | 55 | 56 | function! s:hl_cursor(hl, pos) 57 | if exists("s:hl_cursor_id") 58 | call matchdelete(s:hl_cursor_id) 59 | endif 60 | let s:hl_cursor_id = matchadd(a:hl, printf('\%%%dl\%%%dc', a:pos[0], a:pos[1])) 61 | endfunction 62 | 63 | 64 | function! s:jump(prefix, key, suffix) 65 | if !empty(a:prefix) | execute "normal!" a:prefix | endif 66 | while 1 67 | if !empty(a:key) | execute "normal!" a:key | endif 68 | let pattern = '(\d\+/\d\+)' 69 | let text = s:get_text_from_pattern(pattern) 70 | if text == "" || text !~ '^' . pattern . '$' 71 | break 72 | endif 73 | endwhile 74 | if !empty(a:suffix) | execute "normal!" a:suffix | endif 75 | endfunction 76 | 77 | 78 | function! anzu#mode#start(pattern, key, prefix, suffix, ...) 79 | if a:pattern == "" 80 | return 81 | endif 82 | let forward_key = get(a:, 1, "n") 83 | let back_key = get(a:, 2, "N") 84 | try 85 | call s:init(a:pattern) 86 | if a:key != "" 87 | call s:jump(a:prefix, a:key, a:suffix) 88 | endif 89 | call s:hl_cursor("Cursor", getpos(".")[1:]) 90 | catch /^Vim\%((\a\+)\)\=:E/ 91 | call s:finish() 92 | echohl ErrorMsg | echo matchstr(v:exception, '^Vim(\a\+):\zs.*\ze$') | echohl None 93 | return 94 | endtry 95 | redraw 96 | let char = s:getchar() 97 | while char ==# forward_key || char ==# back_key 98 | if char ==# forward_key 99 | call s:jump(a:prefix, "n", a:suffix) 100 | elseif char ==# back_key 101 | call s:jump(a:prefix, "N", a:suffix) 102 | else 103 | call s:jump(a:prefix, char, a:suffix) 104 | endif 105 | call s:hl_cursor("Cursor", getpos(".")[1:]) 106 | redraw 107 | let char = s:getchar() 108 | endwhile 109 | let cnt = index(anzu#searchpos(a:pattern, bufnr("%"), 1), getpos(".")[1:2]) 110 | call s:finish() 111 | if cnt >= 0 112 | let pos = anzu#getpos(a:pattern, cnt) 113 | if !empty(pos) 114 | call cursor(pos[0], pos[1]) 115 | endif 116 | endif 117 | call feedkeys(char) 118 | endfunction 119 | 120 | 121 | function! anzu#mode#counter() 122 | let s:count += 1 123 | return s:count 124 | endfunction 125 | 126 | 127 | 128 | function! s:substitute(range, pattern, string, flags) 129 | if a:range ==# "%" 130 | let first = 1 131 | let last = "$" 132 | elseif a:range =~ '\s*\d+\s*[,;]\s*\d+\s*' 133 | let [first, last] = matchlist(a:range, '\s*\(\d*\)\s*,\s*\(\d*\)\s*') 134 | elseif empty(a:range) 135 | let first = line('.') 136 | let last = line('.') 137 | else 138 | let first = 1 139 | let last = "$" 140 | endif 141 | return map(split(substitute(join(getline(first, last), "\n"), a:pattern, a:string, a:flags), "\n", 1), "setline(v:key + first, v:val)") 142 | endfunction 143 | 144 | 145 | function! s:silent_substitute(range, pattern, string, flags) 146 | try 147 | let old_search_pattern = @/ 148 | silent execute printf('%ss/%s/%s/%s', a:range, a:pattern, a:string, a:flags) 149 | return 1 150 | catch 151 | return 0 152 | finally 153 | call histdel("search", -1) 154 | let @/ = old_search_pattern 155 | endtry 156 | endfunction 157 | 158 | 159 | let s:anzu_mode = 0 160 | 161 | let s:options = {} 162 | function! s:reset_options(option, value) 163 | let bufnr = bufnr("%") 164 | let s:options[a:option] = getbufvar(bufnr, a:option) 165 | call setbufvar(bufnr, a:option, a:value) 166 | endfunction 167 | 168 | 169 | function! s:matchlines(pattern) 170 | return map(map(anzu#searchpos(a:pattern), "v:val[0]"), "[v:val, getline(v:val)]") 171 | endfunction 172 | 173 | 174 | function! s:init(pattern) 175 | if get(s:, "anzu_mode", 0) 176 | return 177 | endif 178 | let s:undo_flag = 0 179 | 180 | call s:reset_options("&modifiable", 1) 181 | call s:reset_options("&modified", 0) 182 | call s:reset_options("&readonly", 0) 183 | call s:reset_options("&spell", 0) 184 | 185 | let s:undo_file = tempname() 186 | execute "wundo!" s:undo_file 187 | 188 | let format = "%s(%d\\/%d)" 189 | let len = len(anzu#searchpos(a:pattern)) 190 | let s:count = 0 191 | let string = '\=printf("' . format . '", submatch(0), anzu#mode#counter(), ' . len . ')' 192 | let pos = getpos(".") 193 | let s:undo_flag = s:silent_substitute('%', '\(' . a:pattern . '\)', string, 'g') 194 | call setpos(".", pos) 195 | 196 | let &modified = 0 197 | 198 | let @/ = a:pattern 199 | let s:anzu_mode = 1 200 | unlet! s:hl_cursor_id 201 | 202 | let s:matchlist = [] 203 | call add(s:matchlist, matchadd("WarningMsg", (&ignorecase ? '\c' : "") . a:pattern . '\zs(\d\+/\d\+)', 3)) 204 | endfunction 205 | 206 | 207 | function! s:silent_undo() 208 | let pos = getpos(".") 209 | redir => _ 210 | silent undo 211 | redir END 212 | call setpos(".", pos) 213 | endfunction 214 | 215 | 216 | function! s:finish() 217 | if get(s:, "undo_flag", 0) 218 | call s:silent_undo() 219 | if exists("s:undo_file") 220 | \ && filereadable(s:undo_file) 221 | silent execute "rundo" s:undo_file 222 | call delete(s:undo_file) 223 | endif 224 | let &modified = 1 225 | endif 226 | 227 | for [option, value] in items(s:options) 228 | call setbufvar(bufnr("%"), option, value) 229 | endfor 230 | let s:options = {} 231 | 232 | let s:undo_flag = 0 233 | let s:anzu_mode = 0 234 | if exists("s:hl_cursor_id") && s:hl_cursor_id != -1 235 | call matchdelete(s:hl_cursor_id) 236 | unlet s:hl_cursor_id 237 | endif 238 | 239 | for id in s:matchlist 240 | if id != -1 241 | call matchdelete(id) 242 | endif 243 | endfor 244 | let s:matchlist = [] 245 | endfunction 246 | 247 | 248 | function! anzu#mode#mapexpr(key, prefix, suffix) 249 | return ":\call anzu#mode#start(@/, " . string(a:key) .", " . string(a:prefix) . ", " . string(a:suffix) . ")\" 250 | endfunction 251 | 252 | 253 | function! anzu#mode#start_from_incsearch_keymapping_expr(forward_key, back_key) 254 | silent! call anzu#mode#start(@/, "n", "", "", a:forward_key, a:back_key) 255 | return "" 256 | endfunction 257 | 258 | let &cpo = s:save_cpo 259 | unlet s:save_cpo 260 | -------------------------------------------------------------------------------- /autoload/unite/sources/anzu.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | let s:save_cpo = &cpo 3 | set cpo&vim 4 | 5 | function! unite#sources#anzu#define() 6 | return s:source 7 | endfunction 8 | 9 | 10 | let s:source = { 11 | \ "name" : "anzu", 12 | \ 'syntax' : 'uniteSource__anzu', 13 | \ "hooks" : {}, 14 | \ "default_kind" : "jump_list", 15 | \ "sorters" : "sorter_nothing" 16 | \} 17 | 18 | 19 | function! s:source.hooks.on_syntax(args, context) 20 | let pattern = get(a:args, 0, @/) 21 | execute 22 | \ 'syntax match uniteSource__anzuSearch' 23 | \ . ' /' . pattern . '/' 24 | \ . ' contained containedin=uniteSource__anzu' 25 | highlight default link uniteSource__anzuSearch Search 26 | endfunction 27 | 28 | 29 | function! s:source.gather_candidates(args, context) 30 | let pattern = get(a:args, 0, @/) 31 | let bufnr = unite#get_current_unite().prev_bufnr 32 | let list = {} 33 | for item in anzu#searchpos(pattern, bufnr) 34 | let list[item[0]] = getbufline(bufnr, item[0])[0] 35 | endfor 36 | return map(items(list), '{ 37 | \ "word" : v:val[1], 38 | \ "action__line": v:val[0], 39 | \ "action__pattern": pattern, 40 | \ "action__buffer_nr": bufnr, 41 | \ }') 42 | endfunction 43 | 44 | 45 | let &cpo = s:save_cpo 46 | unlet s:save_cpo 47 | -------------------------------------------------------------------------------- /doc/anzu.jax: -------------------------------------------------------------------------------- 1 | *anzu.txt* 検索時の位置情報を表示するプラグインです。 2 | 3 | ============================================================================== 4 | 目次 *anzu-contents* 5 | 6 | 概要 |anzu-introduction| 7 | 使い方 |anzu-usage| 8 | anzu-mode |anzu-mode| 9 | インターフェース |anzu-interface| 10 | コマンド |anzu-commands| 11 | 関数 |anzu-functions| 12 | キーマッピング |anzu-key-mappings| 13 | Autocommands |anzu-autocommands| 14 | 設定 |anzu-setting| 15 | 変数 |anzu-variables| 16 | unite-anzu |unite-anzu| 17 | 18 | 19 | ============================================================================== 20 | 概要 *anzu-introduction* 21 | 22 | *anzu* は検索時に検索位置を視覚的に分かりやすく補助するためのプラグインで 23 | す。 24 | (2/10) のような表示やブラウザなどのツールで検索時にサイドバーに検索位置 25 | が表示される機能を |:sign| を使用してエミュレートしています。 26 | 27 | 基本的に移動を行うキー(|n| や |N| など)にマッピングして使用します。 28 | 29 | -Requires 30 | Vim version 7.3.867 以上 31 | 32 | 33 | ============================================================================== 34 | 使い方 *anzu-usage* 35 | 36 | Example: > 37 | " n や N の代わりに使用します。 38 | nmap n (anzu-n) 39 | nmap N (anzu-N) 40 | nmap * (anzu-star) 41 | nmap # (anzu-sharp) 42 | 43 | " g* 時にステータス情報を出力する場合 44 | nmap g* g*(anzu-update-search-status-with-echo) 45 | 46 | " 最後に検索したワードの [count] の位置へ移動する 47 | " 10j であれば先頭から10番目のワードの位置へ移動する 48 | nmap j (anzu-jump) 49 | " ステータス情報をコマンドラインに出力する場合はこちら 50 | " nmap j (anzu-jump)(anzu-echo-search-status) 51 | 52 | " ステータス情報を statusline へと表示する 53 | set statusline=%{anzu#search_status()} 54 | 55 | " こちらを使用すると 56 | " 移動後にステータス情報をコマンドラインへと出力を行います。 57 | " nmap n (anzu-n-with-echo) 58 | " nmap N (anzu-N-with-echo) 59 | " nmap * (anzu-star-with-echo) 60 | " nmap # (anzu-sharp-with-echo) 61 | 62 | " sign も一緒に使用する場合 63 | " nmap n (anzu-n-with-echo)(anzu-sign-matchline) 64 | " nmap N (anzu-N-with-echo)(anzu-sign-matchline) 65 | 66 | 67 | ============================================================================== 68 | anzu-mode *anzu-mode* 69 | 70 | |anzu-mode| とは検索したワードの横に件数を表示するモードです。 71 | 例えば /anzu と検索した場合、 72 | > 73 | anzu(1/2)_homu 74 | anzu(2/2)_mami 75 | < 76 | というようにバッファ上の検索したワードの横に件数が表示されます。 77 | このモードを開始する場合、 78 | 79 | 次の関数、もしくはマッピングを呼び出す必要がありま 80 | す。 81 | > 82 | " anzu-mode を開始する 83 | " "anzu" で検索を行ってから n で移動を行い 84 | " anzu-mode になります 85 | call anzu#mode#start("anzu", "n", "", "") 86 | 87 | " n の後に anzu-mode を開始する 88 | nmap n (anzu-mode-n) 89 | " N の後に anzu-mode を開始する 90 | nmap N (anzu-mode-N) 91 | < 92 | |anzu-mode| では |n| か |N| キーのみ受け付けます。 93 | それ以外のキーが押された場合、|anzu-mode| は終了します。 94 | 95 | 96 | ============================================================================== 97 | インターフェース *anzu-interface* 98 | 99 | ------------------------------------------------------------------------------ 100 | コマンド *anzu-commands* 101 | 102 | :AnzuClearSearchStatus *:AnzuClearSearchStatus* 103 | ステータス情報をクリアします。 104 | 105 | :AnzuUpdateSearchStatus *:AnzuUpdateSearchStatus* 106 | 現在のカーソル位置でステータス情報を更新します。 107 | カーソル位置が検索位置とマッチした場合にのみ情報が更新されます。 108 | 109 | また、このコマンドだけではステータス情報を出力しないので 110 | |anzu#search_status()| と組み合わせて使用して下さい。 111 | 112 | Example: > 113 | " カーソルが移動するたびに更新する 114 | augroup anzu-update-search-status 115 | autocmd! 116 | autocmd CursorMoved * 117 | \ :AnzuUpdateSearchStatus|echo anzu#search_status() 118 | augroup END 119 | < 120 | 121 | :AnzuSignMatchLine[!] [{pattern}] *:AnzuSignMatchLine* 122 | バッファ内の {pattern} に一致する行を全体の相対的な位置で |:sign| しま 123 | す。 124 | (ブラウザなどのツールで検索時にサイドバーに検索位置が表示されるアレ) 125 | 126 | [!] が使用された場合は |anzu#sign_matchline| が呼ばれ、[!] がない場合 127 | は |anzu#smart_sign_matchline| が使用されます。 128 | 強制的に |:sign| を行いたい場合は [!] を使用して下さい。 129 | 130 | |anzu| 以外の |:sign| を使用していると上書きされる可能性があるので注意 131 | して下さい。 132 | {pattern} がない場合は |@/| の値を使用します。 133 | 134 | :AnzuClearSignMatchLine [{pattern}] *:AnzuClearSignMatchLine* 135 | |anzu| で設定された |:sign| を削除します。 136 | |anzu| 以外の |:sign| も削除される可能性があるので注意して下さい。 137 | また |:sign-unplace| を使用して |:sign| を削除した場 138 | 合、|:AnzuSignMatchLine| が正しく動作しない可能性があります。 139 | その場合は、このコマンドを呼び出してから |:AnzuSignMatchLine| を呼び出 140 | して下さい。 141 | 142 | :AnzuClearSearchCache *:AnzuClearSearchCache* 143 | カレントバッファの検索情報のキャッシュをクリアします。 144 | 145 | :AnzuUpdateSearchStatusOutput *AnzuUpdateSearchStatusOutput* 146 | |:AnzuUpdateSearchStatus| 後に |anzu#search_status()| を |:echo| で出 147 | 力します。 148 | 149 | 150 | ------------------------------------------------------------------------------ 151 | 関数 *anzu-functions* 152 | 153 | anzu#search_status() *anzu#search_status()* 154 | 現在のステータス情報を文字列で返します。 155 | 156 | anzu#clear_search_status() *anzu#clear_search_status()* 157 | ステータス情報をクリアします。 158 | 159 | anzu#echohl_search_status() *anzu#echohl_search_status()* 160 | ステータス情報を |:echohl| でハイライトして出力します。 161 | この時に使用されるハイライトグループは |g:anzu_status_format| で設定し 162 | たものが使用されます。 163 | 164 | anzu#sign_matchline({pattern}) *anzu#sign_matchline()* 165 | {pattern} の位置を |:sign| します。 166 | 167 | anzu#smart_sign_matchline({pattern}) *anzu#smart_sign_matchline()* 168 | {pattern} の位置を |:sign| します。 169 | 基本的には |anzu#sign_matchline| と同じ動作になりますが、なる 170 | べく無駄な |:sign| を行わないようになっています。 171 | (e.g.カーソルがウィンドウの外に出ていない場合は |:sign| しない) 172 | 173 | ただし、場合によっては正しく |:sign| が行われない事もあるので注意して 174 | 下さい。 175 | (e.g.|:sign| の削除に|AnzuClearSignMatchLine| ではなく |:sign-unplace| 176 | を使用した場合など) 177 | 178 | anzu#clear_sign_matchline() *anzu#clear_sign_matchline()* 179 | |:sign| を削除します。 180 | 181 | anzu#clear_search_cache([{bufnr}]) *anzu#clear_search_cache()* 182 | バッファ番号{bufnr} の検索データのキャッシュをクリアします。 183 | これは |TextChanged| |TextChangedI| で呼ばれます。 184 | 185 | *anzu#mode#start()* 186 | anzu#mode#start({pattern}, {key}, {prefix}, {suffix}) 187 | {pattern} で検索を行う |anzu-mode| を開始します。 188 | この時に最初に {key} のキーが呼ばれます。 189 | {prefix} と {suffix} にはそれぞれ |anzu-mode| で |n| や |N| が押された 190 | 場合に prefix と suffix として追加されます。 191 | Example: > 192 | " anzu で検索し、最初に n で移動し anzu-mode に入る 193 | " anzu-mode で n や N が押された場合、 194 | " nzzzv や Nzzzv として処理される 195 | call anzu#mode#start("anzu", "n", "", "zzzv") 196 | < 197 | 198 | anzu#mode#mapexpr({key}, {prefix}, {suffix}) *anzu#mode#mapexpr()* 199 | |:map-| で使用する以外は |anzu#mode#start()| と同じ挙動です。 200 | {pattern} には |@/| が使用されます。 201 | Example: > 202 | " anzu-mode で n を押した場合に nzzzv として処理する 203 | nnoremap n anzu#mode#mapexpr("n", "", "zzzv") 204 | " anzu-mode で N を押した場合に Nzzzv として処理する 205 | nnoremap N anzu#mode#mapexpr("N", "", "zzzv") 206 | 207 | 208 | ------------------------------------------------------------------------------ 209 | キーマッピング *anzu-key-mappings* 210 | 211 | (anzu-update-search-status) *(anzu-update-search-status)* 212 | ステータス情報を更新します。 213 | 基本的には |n| や |N| と併用して使用します。 214 | このマッピングは移動を行うマッピングよりも後で呼び出して下さい。 215 | 216 | Example: > 217 | " n や N の後で呼び出す。 218 | nmap n n(anzu-update-search-status) 219 | nmap N N(anzu-update-search-status) 220 | < 221 | 222 | (anzu-clear-search-status) *(anzu-clear-search-status)* 223 | ステータス情報をクリアします。 224 | 225 | (anzu-clear-search-cache) *(anzu-clear-search-cache)* 226 | カレントバッファの検索情報のキャッシュをクリアします。 227 | 228 | (anzu-echo-search-status) *(anzu-echo-search-status)* 229 | ステータス情報をコマンドラインへ出力します。 230 | このマッピングではステータス情報を更新しないので注意して下さい。 231 | ステータス情報も更新する場合は 232 | |(anzu-update-search-status-with-echo)| を使用して下さい。 233 | 234 | Example: > 235 | " 前回のステータス情報を再出力する 236 | nmap (anzu-update-search-status-with-echo) 237 | < 238 | 239 | (anzu-update-search-status-with-echo) *(anzu-update-search-status-with-echo)* 240 | ステータス情報を更新後にコマンドラインへと出力します。 241 | このマッピングは移動を行うマッピングよりも後で呼び出して下さい。 242 | 243 | Example: > 244 | " g* の後で呼び出す。 245 | nmap g* g*(anzu-update-search-status-with-echo) 246 | < 247 | 248 | (anzu-n) *(anzu-n)* 249 | |(anzu-search-status-update)| がフックされている以外は |n| と同様 250 | の挙動です。 251 | 252 | (anzu-n-with-echo) *(anzu-n-with-echo)* 253 | |(anzu-n)| 後にコマンドラインにステータス情報を出力します。 254 | 255 | (anzu-N) *(anzu-N)* 256 | |(anzu-search-status-update)| がフックされている以外は |N| と同様 257 | の挙動です。 258 | 259 | (anzu-N-with-echo) *(anzu-N-with-echo)* 260 | |(anzu-N)| 後にコマンドラインにステータス情報を出力します。 261 | 262 | (anzu-star) *(anzu-star)* 263 | |(anzu-search-status-update)| がフックされている以外は |star| と同 264 | 様の挙動です。 265 | 266 | (anzu-star-with-echo) *(anzu-star-with-echo)* 267 | |(anzu-star)| 後にコマンドラインにステータス情報を出力します。 268 | 269 | (anzu-sharp) *(anzu-sharp)* 270 | |(anzu-search-status-update)| がフックされている以外は |#| と同様 271 | の挙動です。 272 | 273 | (anzu-sharp-with-echo) *(anzu-sharp-with-echo)* 274 | |(anzu-sharp)| 後にコマンドラインにステータス情報を出力します。 275 | 276 | (anzu-sign-matchline) *(anzu-sign-matchline)* 277 | |:AnzuSignMatchLine| を [!] 付きで呼び出します。 278 | |:AnzuSignMatchLine| の引数には |@/| が使用されます。 279 | このマッピングは移動を行うマッピングよりも後で呼び出して下さい。 280 | 281 | Example: > 282 | " n や N の後で呼び出す。 283 | nmap n n(anzu-sign-matchline) 284 | nmap N N(anzu-sign-matchline) 285 | < 286 | 287 | (anzu-clear-sign-matchline) *(anzu-clear-sign-matchline)* 288 | |:AnzuClearSignMatchLine| を呼び出します。 289 | |:AnzuSignMatchLine| を [!] ありで呼び出します。 290 | 291 | (anzu-smart-sign-matchline) *(anzu-smart-sign-matchline)* 292 | 基本的には |(anzu-sign-matchline)| と同じです。 293 | |:AnzuSignMatchLine| を [!] なしで呼び出します。 294 | 295 | (anzu-jump) *(anzu-jump)* 296 | 最後に検索したワードの [count] の位置へ移動します。 297 | [count] がない、もしくは範囲外であれば移動はしません。 298 | Example: > 299 | " 最後に検索したワードの [count] の位置へ移動する 300 | " 10j であれば先頭から10番目のワードの位置へ移動する 301 | nmap j (anzu-jump) 302 | " ステータス情報をコマンドラインに出力する場合はこちら 303 | " nmap j (anzu-jump)(anzu-echo-search-status) 304 | < 305 | 306 | (anzu-jump-n) *(anzu-jump-n)* 307 | 最後に検索したワードの [count] の位置へ移動します。 308 | 10(anzu-jump-n) であればバッファの先頭から10番目のワードの位置へ 309 | 移動します。 310 | [count] がなければ |(anzu-n)| を使用します。 311 | [count] が範囲外であれば移動はしません。 312 | Example: > 313 | nmap n (anzu-jump-n) 314 | 315 | " 位置をコマンドラインに出力したい場合 316 | nmap n (anzu-jump-n)(anzu-echo-search-status) 317 | < 318 | (anzu-jump-N) *(anzu-jump-N)* 319 | 最後に検索したワードの [count] の位置へ移動します。 320 | [count] がない場合に |(anzu-N)| が使用される以外は 321 | |(anzu-jump-n)| と同じです。 322 | 323 | (anzu-jump-star) *(anzu-jump-star)* 324 | カーソルに最も近い単語の [count] の位置へ移動します。 325 | [count] がない場合に |(anzu-star)| が使用される以外は 326 | |(anzu-jump-n)| と同じです。 327 | 328 | (anzu-jump-sharp) *(anzu-jump-sharp)* 329 | [count] がない場合に |(anzu-sharp)| が使用される以外は 330 | |(anzu-jump-sharp)| と同じです。 331 | 332 | (anzu-mode-n) *(anzu-mode-n)* 333 | |anzu-mode| を開始し、直後 |n| で移動します。 334 | 335 | (anzu-mode-N) *(anzu-mode-N)* 336 | |anzu-mode| を開始し、直後 |N| で移動します。 337 | 338 | (anzu-mode) *(anzu-mode)* 339 | |anzu-mode| を開始しますが、カーソルの移動は行ないません。 340 | 341 | 342 | ------------------------------------------------------------------------------ 343 | Autocommands *anzu-autocommands* 344 | 345 | AnzuWrap *AnzuWrap* 346 | An |User| autocommand, triggered when search has reached the end, and 347 | moving to the other side. 348 | 349 | Example: > 350 | augroup Anzu 351 | autocmd! 352 | autocmd User AnzuWrap call sound_playevent('bell') 353 | augroup END 354 | < 355 | 356 | ============================================================================== 357 | 設定 *anzu-setting* 358 | 359 | ------------------------------------------------------------------------------ 360 | 変数 *anzu-variables* 361 | 362 | g:anzu_status_format *g:anzu_status_format* 363 | ステータス情報のフォーマットを設定します。 364 | 365 | シンボル 展開値~ 366 | -------- ------~ 367 | %p 検索パターン 368 | %/ %p と同等だが offset も付属される(histget("search", 369 | -1) の値) 370 | %i 現在の位置 371 | %l 一致した個数 372 | %# 強調グループ(see: 'statusline') 373 | %w 末尾から先頭、または先頭から末尾に移動した際に表示され 374 | るメッセージ 375 | 376 | Default: > 377 | let g:anzu_status_format = "%p(%i/%l)" 378 | 379 | " highlight "WarningMsg" 380 | let g:anzu_status_format = "%#WarningMsg#%p(%i/%l)" 381 | < 382 | 383 | g:anzu_search_limit *g:anzu_search_limit* 384 | 検索するワードの個数の最大値を設定します。 385 | この変数に設定されている値よりも多くヒットした場合、その場で検索を終了 386 | します。 387 | ヒットするワードが多すぎて動作が遅くなってしまう場合はこの変数に低い値 388 | を設定して下さい。 389 | 390 | Default: > 391 | let g:anzu_search_limit = 1000 392 | < 393 | 394 | 395 | g:anzu_no_match_word *g:anzu_no_match_word* 396 | 検索時にマッチしなかった場合に |anzu#search_status()| 397 | |(anzu-echo-search-status)| で出力する文字列です。 398 | |g:anzu_status_format| と同様のシンボルを設定する事ができます。 399 | 400 | Default: > 401 | let g:anzu_no_match_word = "" 402 | < 403 | 404 | *g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus* 405 | g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus 406 | 1 が設定されていれば |CursorMoved| 時にチェックを行い、カーソル位置と 407 | 検索したワードの位置が同じであれば検索結果を出力します。 408 | |n| 等を再マップしたくない場合などカーソル移動するたびに検索結果を出力 409 | したい場合に使用して下さい。 410 | 411 | Default: > 412 | let g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus = 0 413 | < 414 | 415 | g:airline#extensions#anzu#enabled *g:airline#extensions#anzu#enabled* 416 | |airline| にステータス情報を表示するかどうかの設定を行います。 417 | 0 が設定されていれば |airline| には表示されません。 418 | 419 | g:anzu_bottomtop_word *g:anzu_bottomtop_word* 420 | |(anzu-n-with-echo)| 等で末尾から先頭に移動した際に表示する文字 421 | 列です。 422 | |g:anzu_status_format| の %w に置き換えられます。 423 | Default: > 424 | let g:anzu_bottomtop_word = "search hit BOTTOM, continuing at TOP" 425 | < 426 | 427 | g:anzu_topbottom_word *g:anzu_topbottom_word* 428 | |(anzu-N-with-echo)| 等で先頭から末尾に移動した際に表示する文字 429 | 列です。 430 | |g:anzu_status_format| の %w に置き換えられます。 431 | Default: > 432 | let g:anzu_topbottom_word = "search hit TOP, continuing at BOTTOM" 433 | < 434 | 435 | ============================================================================== 436 | unite-anzu *unite-anzu* 437 | 438 | > 439 | " {pattern} にマッチした行を unite.vim で出力 440 | :Unite anzu:{pattern} 441 | < 442 | 443 | 444 | ============================================================================== 445 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 446 | -------------------------------------------------------------------------------- /doc/anzu.txt: -------------------------------------------------------------------------------- 1 | *anzu.txt* A plug-in that displays the position information of search. 2 | 3 | ============================================================================== 4 | CONTENTS *anzu-contents* 5 | 6 | Introduction |anzu-introduction| 7 | Usage |anzu-usage| 8 | anzu-mode |anzu-mode| 9 | Interface |anzu-interface| 10 | Commands |anzu-commands| 11 | Functions |anzu-functions| 12 | Key mappings |anzu-key-mappings| 13 | Autocommands |anzu-autocommands| 14 | Settings |anzu-setting| 15 | Variables |anzu-variables| 16 | unite-anzu |unite-anzu| 17 | 18 | 19 | ============================================================================== 20 | Introduction *anzu-introduction* 21 | 22 | *anzu* is a plug-in for assisting the search position visually and easily. 23 | Using |:sign| when searching t can display search position like (2/10) or 24 | display the position in the sidebar like a search in a browser. 25 | 26 | It basically remaps search command keys (|n|, |N|, etc.). 27 | 28 | -Requires 29 | Vim version 7.3.867+ 30 | 31 | 32 | ============================================================================== 33 | Usage *anzu-usage* 34 | 35 | Example: > 36 | " Use it instead of n or N. 37 | nmap n (anzu-n) 38 | nmap N (anzu-N) 39 | nmap * (anzu-star) 40 | nmap # (anzu-sharp) 41 | 42 | " If you want to output search status information with g* 43 | nmap g* g*(anzu-update-search-status-with-echo) 44 | 45 | " Move to the [count] occurrence of the last searched word. 46 | " 10j move to the position of the tenth occurrence from 47 | " the beginning 48 | nmap j (anzu-jump) 49 | " Output search status information to the command line 50 | " nmap j (anzu-jump)(anzu-echo-search-status) 51 | 52 | " Display search status information to statusline 53 | set statusline=%{anzu#search_status()} 54 | 55 | " After the move, the search status information is output to 56 | " the command line. 57 | " nmap n (anzu-n-with-echo) 58 | " nmap N (anzu-N-with-echo) 59 | " nmap * (anzu-star-with-echo) 60 | " nmap # (anzu-sharp-with-echo) 61 | 62 | " Using together with sign 63 | " nmap n (anzu-n-with-echo)(anzu-sign-matchline) 64 | " nmap N (anzu-N-with-echo)(anzu-sign-matchline) 65 | 66 | 67 | ============================================================================== 68 | anzu-mode *anzu-mode* 69 | 70 | |anzu-mode| is the mode to display the number of occurrences next to the word 71 | you searched for. 72 | For example, if you search with /anzu, 73 | > 74 | anzu(1/2)_homu 75 | anzu(2/2)_mami 76 | < 77 | The number of occurrences is displayed next to the word searched in the 78 | buffer. 79 | 80 | To start this mode, you need to call the following function or mapping. 81 | > 82 | " To start anzu-mode: 83 | " after searching with "anzu", move with n 84 | " it will be anzu-mode 85 | call anzu#mode#start("anzu", "n", "", "") 86 | 87 | " Start anzu-mode after n 88 | nmap n (anzu-mode-n) 89 | " Start anzu-mode after N 90 | nmap N (anzu-mode-N) 91 | < 92 | |anzu-mode| accepts only the |n| or |N| keys. 93 | If any other key is pressed, |anzu-mode| will exit. 94 | 95 | 96 | ============================================================================== 97 | Interface *anzu-interface* 98 | 99 | ------------------------------------------------------------------------------ 100 | Commands *anzu-commands* 101 | 102 | :AnzuClearSearchStatus *:AnzuClearSearchStatus* 103 | Clear the search status information. 104 | 105 | :AnzuUpdateSearchStatus *:AnzuUpdateSearchStatus* 106 | Update the search status information at the current cursor position. 107 | The information is updated only when the cursor position matches 108 | the search position. 109 | 110 | Also, since this command does not output search status information 111 | use it in combination with |anzu#search_status()|. 112 | 113 | Example: > 114 | " Update each time the cursor moves 115 | augroup anzu-update-search-status 116 | autocmd! 117 | autocmd CursorMoved * 118 | \ :AnzuUpdateSearchStatus|echo anzu#search_status() 119 | augroup END 120 | < 121 | 122 | :AnzuSignMatchLine[!] [{pattern}] *:AnzuSignMatchLine* 123 | The line that matches the {pattern} in the buffer is |:sign| relative 124 | to the position in the buffer. 125 | (The search position is displayed in the sidebar like when searching 126 | with tools such as browsers) 127 | 128 | If [!] is used, |anzu#sign_matchline| is called, otherwise 129 | |anzu#smart_sign_matchline| is used. 130 | If you want to force |:sign| use [!]. 131 | 132 | Be aware that using |:sign| not by |anzu| may overwrite existing signs. 133 | If there is no {pattern}, the value of |@/| is used. 134 | 135 | :AnzuClearSignMatchLine [{pattern}] *:AnzuClearSignMatchLine* 136 | Delete |:sign| was set by |anzu|. 137 | Be aware that |:sign| which was set by something other than |anzu| may 138 | also be deleted. 139 | Also, if you use |:sign-unplace| to delete |:sign|, 140 | |:AnzuSignMatchLine| may not work properly. 141 | In that case, call this command and also |:AnzuSignMatchLine|. 142 | 143 | :AnzuClearSearchCache *:AnzuClearSearchCache* 144 | Clear the cache of the search information of the current buffer. 145 | 146 | :AnzuUpdateSearchStatusOutput *AnzuUpdateSearchStatusOutput* 147 | After |:AnzuUpdateSearchStatus| an |anzu#search_status()| will output 148 | with |:echo|. 149 | 150 | 151 | ------------------------------------------------------------------------------ 152 | Functions *anzu-functions* 153 | 154 | anzu#search_status() *anzu#search_status()* 155 | Returns the current search status information as a string. 156 | 157 | anzu#clear_search_status() *anzu#clear_search_status()* 158 | Clear the search status information. 159 | 160 | anzu#echohl_search_status() *anzu#echohl_search_status()* 161 | Highlight the status information with |:echohl| and output it. 162 | The highlight group is set via |g:anzu_status_format|. 163 | 164 | anzu#sign_matchline({pattern}) *anzu#sign_matchline()* 165 | |:sign| the position of {pattern}. 166 | 167 | anzu#smart_sign_matchline({pattern}) *anzu#smart_sign_matchline()* 168 | |:sign| the position of {pattern}. 169 | Basically it works the same as |anzu#sign_matchline|, but it is designed 170 | not to waste |:sign| as much as possible. 171 | (e.g. not |:sign| when the cursor does not go outside the window) 172 | 173 | However, beware that |:sign| may not be set properly in some cases. 174 | (e.g. when using |:sign-unplace| instead of |AnzuClearSignMatchLine| 175 | to delete |:sign|) 176 | 177 | anzu#clear_sign_matchline() *anzu#clear_sign_matchline()* 178 | |:sign| delete. 179 | 180 | anzu#clear_search_cache([{bufnr}]) *anzu#clear_search_cache()* 181 | Clear cache of search data of buffer number {bufnr} 182 | This is called by |TextChanged| and |TextChangedI|. 183 | 184 | *anzu#mode#start()* 185 | anzu#mode#start({pattern}, {key}, {prefix}, {suffix}) 186 | Start search with {pattern} in |anzu-mode|. 187 | The key {key} is called first. 188 | {prefix} and {suffix} are added as prefix and suffix respectively 189 | when |n| and |N|are pressed with |anzu-mode|. 190 | Example: > 191 | " Search anzu, move with n and enter anzu-mode 192 | " when n or N is pressed in anzu-mode 193 | " it is processed as nzzzv or Nzzzv 194 | call anzu#mode#start("anzu", "n", "", "zzzv") 195 | < 196 | 197 | anzu#mode#mapexpr({key}, {prefix}, {suffix}) *anzu#mode#mapexpr()* 198 | The behavior is the same as |anzu#mode#start()|, except using 199 | |:map-|. |@/| is used for {pattern}. 200 | Example: > 201 | " Processing as nzzzv when n is pressed in anzu-mode 202 | nnoremap n anzu#mode#mapexpr("n", "", "zzzv") 203 | " Processing as Nzzzv when N is pressed in anzu-mode 204 | nnoremap N anzu#mode#mapexpr("N", "", "zzzv") 205 | 206 | 207 | ------------------------------------------------------------------------------ 208 | Key mappings *anzu-key-mappings* 209 | 210 | (anzu-update-search-status) *(anzu-update-search-status)* 211 | Update the search status information. 212 | Basically it is used in combination with |n| and |N|. 213 | This mapping should be called after the move's mapping. 214 | 215 | Example: > 216 | " Call after n or N. 217 | nmap n n(anzu-update-search-status) 218 | nmap N N(anzu-update-search-status) 219 | < 220 | 221 | (anzu-clear-search-status) *(anzu-clear-search-status)* 222 | Clear the search status information. 223 | 224 | (anzu-clear-search-cache) *(anzu-clear-search-cache)* 225 | Clear the cache of the search information of the current buffer. 226 | 227 | (anzu-echo-search-status) *(anzu-echo-search-status)* 228 | Search status information is output to the command line. 229 | Note that search status information is not updated in this mapping. 230 | Use |(anzu-update-search-status-with-echo)| 231 | when updating the search status information. 232 | 233 | Example: > 234 | " Re-output the previous search status information 235 | nmap (anzu-update-search-status-with-echo) 236 | < 237 | 238 | (anzu-update-search-status-with-echo) *(anzu-update-search-status-with-echo)* 239 | After updating the search status information, also output it to 240 | the command line. 241 | This mapping should be called after the move's mapping. 242 | 243 | Example: > 244 | " Call after g*. 245 | nmap g* g*(anzu-update-search-status-with-echo) 246 | < 247 | 248 | (anzu-n) *(anzu-n)* 249 | Behavior similar to |n| except that |(anzu-search-status-update)| 250 | is hooked. 251 | 252 | (anzu-n-with-echo) *(anzu-n-with-echo)* 253 | Like |(anzu-n)|, but also the search status information 254 | will be output to the command line. 255 | 256 | (anzu-N) *(anzu-N)* 257 | Behavior similar to |N| except that |(anzu-search-status-update)| 258 | is hooked. 259 | 260 | (anzu-N-with-echo) *(anzu-N-with-echo)* 261 | Like |(anzu-N)|, but also the search status information 262 | will be output to the command line. 263 | 264 | (anzu-star) *(anzu-star)* 265 | Behavior similar to |star| except that 266 | |(anzu-search-status-update)| is hooked. 267 | 268 | (anzu-star-with-echo) *(anzu-star-with-echo)* 269 | Like |(anzu-star)|, but also the search status information 270 | will be output to the command line. 271 | 272 | (anzu-sharp) *(anzu-sharp)* 273 | Behavior similar to |#| except that |(anzu-search-status-update)| 274 | is hooked. 275 | 276 | (anzu-sharp-with-echo) *(anzu-sharp-with-echo)* 277 | Like |(anzu-sharp)|, but also the search status information 278 | will be output to the command line. 279 | 280 | (anzu-sign-matchline) *(anzu-sign-matchline)* 281 | |:AnzuSignMatchLine| with [!] is called. 282 | |@/| is used as the argument of |:AnzuSignMatchLine|. 283 | This mapping should be called after the move's mapping. 284 | 285 | Example: > 286 | " Call after n or N. 287 | nmap n n(anzu-sign-matchline) 288 | nmap N N(anzu-sign-matchline) 289 | < 290 | 291 | (anzu-clear-sign-matchline) *(anzu-clear-sign-matchline)* 292 | |:AnzuClearSignMatchLine| is called. 293 | Call |:AnzuSignMatchLine| with [!]. 294 | 295 | (anzu-smart-sign-matchline) *(anzu-smart-sign-matchline)* 296 | Basically it is the same as |(anzu-sign-matchline)|. 297 | Call |:AnzuSignMatchLine| without [!]. 298 | 299 | (anzu-jump) *(anzu-jump)* 300 | Move to the [count] position of the last searched word. 301 | If [count] does not exist or is out of range, it will not move. 302 | Example: > 303 | " Move to the position of [count] occurrence of the last searched word 304 | " 10j means move to the position of the tenth word from 305 | " the beginning 306 | nmap j (anzu-jump) 307 | " To output search status information to the command line 308 | " nmap j (anzu-jump)(anzu-echo-search-status) 309 | < 310 | 311 | (anzu-jump-n) *(anzu-jump-n)* 312 | Move to the [count] position of the last searched word. 313 | 10(anzu-jump-n) means move to the position of the tenth word 314 | from the beginning of the buffer. 315 | If there is no [count], use |(anzu-n)| instead. 316 | If [count] is out of range, it will not move. 317 | Example: > 318 | nmap n (anzu-jump-n) 319 | 320 | " When you want to output the position to the command line 321 | nmap n (anzu-jump-n)(anzu-echo-search-status) 322 | < 323 | (anzu-jump-N) *(anzu-jump-N)* 324 | It is the same as |(anzu-jump-n)| except that |(anzu-N)| 325 | is used when there is no [count]. 326 | 327 | (anzu-jump-star) *(anzu-jump-star)* 328 | Move to the [count] position of the word closest to the cursor. 329 | It is the same as |(anzu-jump-n)| except that |(anzu-star)| 330 | is used when there is no [count]. 331 | 332 | (anzu-jump-sharp) *(anzu-jump-sharp)* 333 | It is the same as |(anzu-jump-sharp)| except that 334 | |(anzu-sharp)| is used when there is no [count]. 335 | 336 | (anzu-mode-n) *(anzu-mode-n)* 337 | Start |anzu-mode| and move right after |n|. 338 | 339 | (anzu-mode-N) *(anzu-mode-N)* 340 | Start |anzu-mode| and move right after |N|. 341 | 342 | (anzu-mode) *(anzu-mode)* 343 | |anzu-mode| is started but the cursor is not moved. 344 | 345 | 346 | ------------------------------------------------------------------------------ 347 | Autocommands *anzu-autocommands* 348 | 349 | AnzuWrap *AnzuWrap* 350 | An |User| autocommand, triggered when search has reached the end, and 351 | moving to the other side. 352 | 353 | Example: > 354 | augroup Anzu 355 | autocmd! 356 | autocmd User AnzuWrap call sound_playevent('bell') 357 | augroup END 358 | < 359 | 360 | ============================================================================== 361 | Settings *anzu-setting* 362 | 363 | ------------------------------------------------------------------------------ 364 | Variables *anzu-variables* 365 | 366 | g:anzu_status_format *g:anzu_status_format* 367 | Set the format of status information. 368 | 369 | Item Meaning~ 370 | -------- ------~ 371 | %p Search pattern 372 | %/ %p equivalent but offset is also included 373 | (value of histget("search", -1)) 374 | %i Current position 375 | %l Match quantity 376 | %# Highlight group (see: 'statusline') 377 | %w Message displayed when moving from the end to 378 | the beginning or vice versa 379 | 380 | Default: > 381 | let g:anzu_status_format = "%p(%i/%l)" 382 | 383 | " highlight as "WarningMsg" 384 | let g:anzu_status_format = "%#WarningMsg#%p(%i/%l)" 385 | < 386 | 387 | g:anzu_search_limit *g:anzu_search_limit* 388 | Sets the maximum number of words to search. 389 | If more hits are made than the value set in this variable, 390 | the search is terminated on the spot. 391 | If the number of hits is too high and the operation slows down 392 | set a lower value for this variable. 393 | 394 | Default: > 395 | let g:anzu_search_limit = 1000 396 | < 397 | 398 | 399 | g:anzu_no_match_word *g:anzu_no_match_word* 400 | If there is no matches on search it will output this character string 401 | via |anzu#search_status()| and |(anzu-echo-search-status)|. 402 | You can set symbols similar to |g:anzu_status_format|. 403 | 404 | Default: > 405 | let g:anzu_no_match_word = "" 406 | < 407 | 408 | *g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus* 409 | g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus 410 | If set to 1, |CursorMoved| is checked at times, and if the position 411 | of the cursor and the position of the searched word are the same, 412 | the search result is output. 413 | If set to 2, only the cache will be updated but it won't output 414 | anything. 415 | Use this when you want to output search results each time you move 416 | the cursor, for example when you do not want to remap |n| etc. 417 | 418 | Default: > 419 | let g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus = 0 420 | < 421 | *g:anzu_enable_CursorHold_AnzuUpdateSearchStatus* 422 | g:anzu_enable_CursorHold_AnzuUpdateSearchStatus 423 | If set to 1, |CursorHold| is checked at times, and if the position 424 | of the cursor and the position of the searched word are the same, 425 | the search result is output. 426 | If set to 2, only the cache will be updated but it won't output 427 | anything. 428 | Use this when you want to output search results each time you move 429 | the cursor, for example when you do not want to remap |n| etc. 430 | 431 | Default: > 432 | let g:anzu_enable_CursorHold_AnzuUpdateSearchStatus = 0 433 | < 434 | 435 | g:airline#extensions#anzu#enabled *g:airline#extensions#anzu#enabled* 436 | Set whether to display search status information on |airline|. 437 | Otherwise set to 0. 438 | 439 | g:anzu_airline_section *g:anzu_airline_section* 440 | Set the airline section to be used to display search status 441 | information. 442 | Default: > 443 | let g:anzu_airline_section = "y" 444 | < 445 | 446 | g:anzu_bottomtop_word *g:anzu_bottomtop_word* 447 | This is a character string to be displayed when moving from the end 448 | to the beginning with |(anzu-n-with-echo)|. 449 | It will replace %w in |g:anzu_status_format|. 450 | Default: > 451 | let g:anzu_bottomtop_word = "search hit BOTTOM, continuing at TOP" 452 | < 453 | 454 | g:anzu_topbottom_word *g:anzu_topbottom_word* 455 | This is a character string to be displayed when moving from the 456 | beginning to the end with |(anzu-N-with-echo)|. 457 | It will replace %w in |g:anzu_status_format|. 458 | Default: > 459 | let g:anzu_topbottom_word = "search hit TOP, continuing at BOTTOM" 460 | < 461 | 462 | ============================================================================== 463 | unite-anzu *unite-anzu* 464 | 465 | > 466 | " Output a line matching {pattern} in unite.vim 467 | :Unite anzu:{pattern} 468 | < 469 | 470 | 471 | ============================================================================== 472 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 473 | -------------------------------------------------------------------------------- /plugin/anzu.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | if exists('g:loaded_anzu') 3 | finish 4 | endif 5 | let g:loaded_anzu = 1 6 | 7 | let s:save_cpo = &cpo 8 | set cpo&vim 9 | 10 | 11 | function! s:push_pos(is_back) 12 | let s:start_pos = getpos(".") 13 | let s:is_back = a:is_back 14 | endfunction 15 | 16 | 17 | " a < b 18 | function! s:pos_less(a, b) 19 | return a:a[1] == a:b[1] ? a:a[2] < a:b[2] : a:a[1] < a:b[1] 20 | endfunction 21 | 22 | function! s:update_search_status() 23 | if mode() !=# 'n' 24 | return 25 | endif 26 | 27 | let curs_hold = get(g:, 'anzu_enable_CursorHold_AnzuUpdateSearchStatus', 0) 28 | let curs_mov = get(g:, 'anzu_enable_CursorMoved_AnzuUpdateSearchStatus', 0) 29 | 30 | let anzu_echo_output = (curs_hold == 1 || curs_mov == 1) 31 | 32 | try 33 | if curs_hold || curs_mov 34 | if anzu#update(@/, anzu#get_on_pattern_pos(@/), s:wrapscan_mes()) != -1 35 | \ && anzu_echo_output 36 | call feedkeys("\(anzu-echohl_search_status)") 37 | endif 38 | endif 39 | catch /^Vim\%((\a\+)\)\=:E/ 40 | echohl ErrorMsg | echo matchstr(v:exception, '^Vim(\a\+):\zs.*\ze$') | echohl None 41 | return 42 | endtry 43 | endfunction 44 | 45 | function! s:wrapscan_mes() 46 | if !exists("s:start_pos") || !exists("s:is_back") 47 | return "" 48 | endif 49 | let prev_pos = s:start_pos 50 | let pos = getpos(".") 51 | let result = "" 52 | if !empty(prev_pos) && s:pos_less(pos, prev_pos) && !s:is_back 53 | let result = g:anzu_bottomtop_word 54 | elseif !empty(prev_pos) && s:pos_less(prev_pos, pos) && s:is_back 55 | let result = g:anzu_topbottom_word 56 | endif 57 | unlet s:start_pos 58 | unlet s:is_back 59 | 60 | if !empty(result) && exists('#User#AnzuWrap') 61 | doautocmd User AnzuWrap 62 | endif 63 | 64 | return result 65 | endfunction 66 | 67 | 68 | let g:anzu_status_format = get(g:, "anzu_status_format", '%p(%i/%l)') 69 | let g:anzu_search_limit = get(g:, "anzu_search_limit", 1000) 70 | let g:anzu_no_match_word = get(g:, "anzu_no_match_word", "") 71 | 72 | let g:anzu_airline_format = get(g:, "anzu_airline_format", "(%i/%l)") 73 | 74 | let g:anzu_bottomtop_word = get(g:, "anzu_bottomtop_word", "search hit BOTTOM, continuing at TOP") 75 | let g:anzu_topbottom_word = get(g:, "anzu_topbottom_word", "search hit TOP, continuing at BOTTOM") 76 | 77 | 78 | 79 | command! -bar AnzuClearSearchStatus call anzu#clear_search_status() 80 | command! -bar AnzuClearSearchCache call anzu#clear_search_cache() 81 | 82 | command! -bar AnzuUpdateSearchStatus 83 | \ call anzu#update(@/, anzu#get_on_pattern_pos(@/), s:wrapscan_mes()) 84 | command! -bar AnzuUpdateSearchStatusOutput 85 | \ call anzu#update(@/, anzu#get_on_pattern_pos(@/), s:wrapscan_mes()) 86 | \| call anzu#echohl_search_status() 87 | 88 | 89 | nnoremap (anzu-echo-search-status) :call anzu#echohl_search_status() 90 | 91 | 92 | nnoremap (anzu-update-search-status) :AnzuUpdateSearchStatus 93 | nmap (anzu-update-search-status-with-echo) 94 | \ (anzu-update-search-status)(anzu-echo-search-status) 95 | 96 | nnoremap (anzu-clear-search-status) :AnzuClearSearchStatus 97 | nnoremap (anzu-clear-search-cache) :AnzuClearSearchCache 98 | 99 | 100 | nnoremap (anzu-star) 101 | \ ":\call \push_pos(0)\:normal! " . v:count1 . "*\:\AnzuUpdateSearchStatus\" 102 | 103 | nmap (anzu-star-with-echo) 104 | \ (anzu-star)(anzu-echo-search-status) 105 | 106 | nnoremap (anzu-sharp) 107 | \ ":\call \push_pos(1)\:normal! " . v:count1 . "#\:\AnzuUpdateSearchStatus" 108 | 109 | nmap (anzu-sharp-with-echo) 110 | \ (anzu-sharp)(anzu-echo-search-status) 111 | 112 | nnoremap (anzu-n) 113 | \ ":\call \push_pos(0)\:normal! " . v:count1 . "n\:\AnzuUpdateSearchStatus\" 114 | 115 | nmap (anzu-n-with-echo) 116 | \ (anzu-n)(anzu-echo-search-status) 117 | 118 | nnoremap (anzu-N) 119 | \ ":\call \push_pos(1)\:normal! " . v:count1 . "N\:\AnzuUpdateSearchStatus\" 120 | 121 | 122 | nmap (anzu-N-with-echo) 123 | \ (anzu-N)(anzu-echo-search-status) 124 | 125 | 126 | nnoremap (anzu-jump) 127 | \ anzu#mapexpr_jump(v:count, '') 128 | 129 | nnoremap (anzu-jump-n) 130 | \ anzu#mapexpr_jump(v:count, '\(anzu-n)') 131 | 132 | nnoremap (anzu-jump-N) 133 | \ anzu#mapexpr_jump(v:count, '\(anzu-N)') 134 | 135 | nnoremap (anzu-jump-star) 136 | \ ":normal! *N\" . anzu#mapexpr_jump(v:count, '\(anzu-star)') 137 | 138 | nnoremap (anzu-jump-sharp) 139 | \ ":normal! *N\" . anzu#mapexpr_jump(v:count, '\(anzu-sharp)') 140 | 141 | 142 | command! -bar -nargs=* -bang 143 | \ AnzuSignMatchLine 144 | \ if 0 145 | \| call anzu#sign_matchline(empty() ? @/ : ) 146 | \| else 147 | \| call anzu#smart_sign_matchline(empty() ? @/ : ) 148 | \| endif 149 | 150 | command! -bar -nargs=* 151 | \ AnzuClearSignMatchLine 152 | \ call anzu#clear_sign_matchline() 153 | 154 | 155 | nnoremap (anzu-sign-matchline) :AnzuSignMatchLine! 156 | nnoremap (anzu-clear-sign-matchline) :AnzuClearSignMatchLine 157 | 158 | nnoremap (anzu-smart-sign-matchline) :AnzuSignMatchLine 159 | 160 | noremap (anzu-echohl_search_status) 161 | \ (mode() =~ '[iR]' ? "\" : "") . ":call anzu#echohl_search_status()\" 162 | 163 | 164 | augroup anzu 165 | autocmd! 166 | autocmd CursorMoved * call update_search_status() 167 | 168 | if exists("##TextChanged") 169 | autocmd TextChanged * call anzu#clear_search_cache() 170 | autocmd TextChangedI * call anzu#clear_search_cache() 171 | else 172 | if exists("##InsertCharPre") 173 | autocmd InsertCharPre * call anzu#clear_search_cache() 174 | endif 175 | autocmd BufWritePost * call anzu#clear_search_cache() 176 | endif 177 | augroup END 178 | 179 | 180 | nnoremap (anzu-mode-n) :call anzu#mode#start(@/, "n", "", "") 181 | nnoremap (anzu-mode-N) :call anzu#mode#start(@/, "N", "", "") 182 | nnoremap (anzu-mode) :call anzu#mode#start(@/, "", "", "") 183 | 184 | 185 | let &cpo = s:save_cpo 186 | unlet s:save_cpo 187 | --------------------------------------------------------------------------------