├── doc └── visualstar.txt └── plugin └── visualstar.vim /doc/visualstar.txt: -------------------------------------------------------------------------------- 1 | *visualstar.txt* |star| for |Visual-mode|. 2 | 3 | Version: 0.5.0 4 | Author : thinca 5 | License: zlib License 6 | 7 | ============================================================================== 8 | CONTENTS *visualstar-contents* 9 | 10 | INTRODUCTION |visualstar-introduction| 11 | INTERFACE |visualstar-interface| 12 | KEY MAPPINGS |visualstar-key-mappings| 13 | SETTINGS |visualstar-settings| 14 | EXAMPLES |visualstar-examples| 15 | CHANGELOG |visualstar-changelog| 16 | 17 | 18 | 19 | ============================================================================== 20 | INTRODUCTION *visualstar-introduction* 21 | 22 | *visualstar* is a Vim plugin to provide a |star| feature for |Visual-mode|. 23 | In other words, you can search your selection text in |Visual-mode|. 24 | 25 | Requirements: 26 | - Vim 7.2 or later 27 | 28 | Latest version: 29 | https://github.com/thinca/vim-visualstar 30 | 31 | 32 | 33 | ============================================================================== 34 | INTERFACE *visualstar-interface* 35 | 36 | ------------------------------------------------------------------------------ 37 | KEY MAPPINGS *visualstar-key-mappings* 38 | 39 | (visualstar-*) *(visualstar-star)* *v_star* 40 | Search forward for the [count]'th occurrence of 41 | selection text in |Visual-mode| nearest to the cursor. 42 | If the character of head of selection text is 43 | 'iskeyword' character, and outside of selection area 44 | is not 'iskeyword' character, "\<" is appended to the 45 | head of search word like same as |star|. 46 | The tail is also similar. 47 | 48 | (visualstar-#) *(visualstar-#)* *v_#* 49 | Same as |(visualstar-star)|, but search 50 | backward. 51 | 52 | (visualstar-g*) *(visualstar-gstar)* *v_gstar* 53 | Like |(visualstar-star)|, but don't put "\<" and 54 | "\>" around the word. 55 | 56 | (visualstar-g#) *(visualstar-g#)* *v_g#* 57 | Like |(visualstar-#)|, but don't put "\<" and 58 | "\>" around the word. 59 | 60 | In |Normal-mode| and |Operator-pending-mode|, the following key mappings will 61 | be also defined for convenience. 62 | 63 | {lhs} {rhs} 64 | ------------------------ ------ 65 | (visualstar-*) * 66 | (visualstar-#) # 67 | (visualstar-g*) g* 68 | (visualstar-g#) g# 69 | 70 | 71 | *g:visualstar_no_default_key_mappings* 72 | The following key mappings will be also available in |Visual-mode| unless 73 | |g:visualstar_no_default_key_mappings| is defined: 74 | 75 | {lhs} {rhs} 76 | -------- --------------------- 77 | * (visualstar-*) 78 | (visualstar-*) 79 | (visualstar-*) 80 | # (visualstar-#) 81 | g* (visualstar-g*) 82 | g (visualstar-g*) 83 | g (visualstar-g*) 84 | g# (visualstar-g#) 85 | 86 | 87 | 88 | ============================================================================== 89 | SETTINGS *visualstar-settings* 90 | 91 | 92 | g:visualstar_extra_commands *g:visualstar_extra_commands* 93 | In case you want to run extra commands when searching, you can set 94 | this variable to a key sequence. 95 | For example, to center the search in the window and open enough folds, 96 | you can set the following variable. 97 | > 98 | let g:visualstar_extra_commands = 'zzzv' 99 | < 100 | 101 | 102 | ============================================================================== 103 | EXAMPLES *visualstar-examples* 104 | 105 | Search the text, but cursor don't move to next match. > 106 | map * (visualstar-*)N 107 | map # (visualstar-#)N 108 | 109 | If you map N to something, you must create and use a secondary key mapping. > 110 | noremap N N 111 | map * (visualstar-*)N 112 | map # (visualstar-#)N 113 | 114 | 115 | 116 | ============================================================================== 117 | CHANGELOG *visualstar-changelog* 118 | 119 | 0.5.0 2014-05-09 120 | - [count] didn't work. 121 | - Removed default key mappings from |Select-mode|, again. 122 | - Some key mappings remained. 123 | 124 | 0.4.0 2012-06-28 125 | - Removed default key mappings from |Select-mode|. 126 | - Added key mappings from . 127 | 128 | 0.3.0 2012-05-12 129 | - Added key mappings from . 130 | 131 | 0.2.1 2010-04-23 132 | - Don't append \< and \> if the edge of string is multibyte character. 133 | - Append \< and \> if it is differed inside or outside of the boundary 134 | that is multibyte character or not. 135 | 136 | 0.2.0 2010-01-25 137 | - Changed the key mapping name. 138 | - (visualstar) -> (visualstar-*) 139 | - Added |(visualstar-gstar)| and |(visualstar-g#)|. 140 | - These are same as (visualstar) and (visualstar-#) of 141 | version before. 142 | - Changed the behavior of (visualstar-*) and 143 | (visualstar-#). 144 | - [count] is now available. 145 | 146 | 0.1.0 2009-11-16 147 | - Initial version. 148 | 149 | 150 | ============================================================================== 151 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 152 | -------------------------------------------------------------------------------- /plugin/visualstar.vim: -------------------------------------------------------------------------------- 1 | " |star| for |Visual-mode|. 2 | " Version: 0.5.0 3 | " Author : thinca 4 | " License: zlib License 5 | 6 | if exists('g:loaded_visualstar') 7 | finish 8 | endif 9 | let g:loaded_visualstar = 1 10 | 11 | let s:save_cpo = &cpo 12 | set cpo&vim 13 | 14 | 15 | function! s:search(type, g) 16 | let s:count = v:count1 . a:type 17 | let reg = '"' 18 | let [save_reg, save_type] = [getreg(reg), getregtype(reg)] 19 | normal! gv""y 20 | let text = @" 21 | call setreg(reg, save_reg, save_type) 22 | 23 | let [pre, post] = ['', ''] 24 | if !a:g 25 | let head = matchstr(text, '^.') 26 | let is_head_multibyte = 1 < len(head) 27 | let [l, col] = getpos("'<")[1 : 2] 28 | let line = getline(l) 29 | let before = line[: col - 2] 30 | let outer = matchstr(before, '.$') 31 | if text =~# '^\k' && ((!empty(outer) && len(outer) != len(head)) || 32 | \ (!is_head_multibyte && (col == 1 || before !~# '\k$'))) 33 | let pre = '\<' 34 | endif 35 | 36 | let tail = matchstr(text, '.$') 37 | let is_tail_multibyte = 1 < len(tail) 38 | let [l, col] = getpos("'>")[1 : 2] 39 | let col += len(tail) - 1 40 | let line = getline(l) 41 | let after = line[col :] 42 | let outer = matchstr(after, '^.') 43 | if text =~# '\k$' && ((!empty(outer) && len(outer) != len(tail)) || 44 | \ (!is_tail_multibyte && (col == len(line) || after !~# '^\k'))) 45 | let post = '\>' 46 | endif 47 | endif 48 | 49 | let text = substitute(escape(text, '\' . a:type), "\n", '\\n', 'g') 50 | 51 | let @/ = '\V' . pre . text . post 52 | call histadd('/', @/) 53 | endfunction 54 | 55 | function! s:count() 56 | return s:count . "\" 57 | endfunction 58 | 59 | function! s:extra_commands() 60 | if exists('g:visualstar_extra_commands') 61 | return g:visualstar_extra_commands 62 | else 63 | return '' 64 | endif 65 | endfunction 66 | 67 | 68 | noremap (visualstar-*) * 69 | noremap (visualstar-#) # 70 | noremap (visualstar-g*) g* 71 | noremap (visualstar-g#) g# 72 | 73 | vnoremap