├── .gitignore ├── README.md ├── autoload └── jplus.vim ├── doc ├── jplus.jax └── jplus.txt └── plugin └── jplus.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | doc/tags-ja 3 | test_jplus 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jplus.vim 2 | 3 | 結合時に区切り文字を入力したり、行継続のキーワード(\ 等)などを削除して行結合を行うプラグインです。 4 | 5 | ## Screencapture 6 | 7 | #### 任意の文字を挿入して結合する 8 | 9 | ![jplus1](https://cloud.githubusercontent.com/assets/214488/3864410/0e52b254-1f5c-11e4-9f89-3c624dc72936.gif) 10 | 11 | #### 先頭の \ を取り除いて結合する 12 | 13 | ![jplus2](https://cloud.githubusercontent.com/assets/214488/3864436/f747a67c-1f5c-11e4-8918-45bfa0a2aced.gif) 14 | 15 | ## Example 16 | 17 | ```vim 18 | " J の挙動を jplus.vim で行う 19 | nmap J (jplus) 20 | vmap J (jplus) 21 | 22 | " getchar() を使用して挿入文字を入力します 23 | nmap J (jplus-getchar) 24 | vmap J (jplus-getchar) 25 | 26 | " input() を使用したい場合はこちらを使用して下さい 27 | " nmap J (jplus-input) 28 | " vmap J (jplus-input) 29 | 30 | " (jplus-getchar) 時に左右に空白文字を入れたい場合 31 | " %d は入力した結合文字に置き換えられる 32 | let g:jplus#config = { 33 | \ "_" : { 34 | \ "delimiter_format" : ' %d ' 35 | \ } 36 | \} 37 | ``` 38 | 39 | 40 | -------------------------------------------------------------------------------- /autoload/jplus.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | let s:save_cpo = &cpo 3 | set cpo&vim 4 | 5 | 6 | " Workaround issues #12 7 | function! s:escape_substitute_sub(str) 8 | return substitute(a:str, '&', '\\&', "g") 9 | endfunction 10 | 11 | 12 | function! s:extend_list(list) 13 | return empty(a:list) ? {} 14 | \ : len(a:list) == 1 ? a:list[0] 15 | \ : extend(deepcopy(a:list[0]), s:extend_list(a:list[1:])) 16 | endfunction 17 | 18 | 19 | 20 | function! jplus#getchar() 21 | let c = nr2char(getchar()) 22 | return c =~ '[[:print:]]' ? c : "" 23 | endfunction 24 | 25 | 26 | function! s:join_list(list, c, ignore, left_match, right_match) 27 | let list = filter(a:list, 'len(v:val) && !(a:ignore != "" && (v:val =~ a:ignore))') 28 | 29 | if empty(list) 30 | return [] 31 | endif 32 | 33 | let result = list[0] 34 | for i in list[1:] 35 | let result = matchstr(result, a:left_match) . a:c . matchstr(i, a:right_match) 36 | endfor 37 | return result 38 | endfunction 39 | 40 | 41 | 42 | function! s:add_comment_leader_pattern(current_pattern) 43 | if &formatoptions !~ 'j' 44 | return a:current_pattern 45 | endif 46 | 47 | let flags = '\(^:\|m\)' 48 | let to_consider = filter(split(&comments, ','), 'v:val =~ flags') 49 | call map(to_consider, 'split(v:val, ":")[-1]') 50 | 51 | if len(to_consider) == 0 52 | return a:current_pattern 53 | endif 54 | 55 | " Escape special characters 56 | let to_escape = '\([*.]\)' 57 | let replace_with = '\\\1' 58 | call map(to_consider, 'substitute(v:val, to_escape, replace_with, "g")') 59 | 60 | " Construct patterns 61 | let before = '^\s*' 62 | let after = '\s*\zs.*' 63 | call map(to_consider, 'before . v:val . after') 64 | 65 | " Note: a:current_pattern MUST come at the end since it might contain '.*' 66 | " in the pattern, which will match even to comment leaders 67 | return '\%(' . join(to_consider, '\|') . '\|' . a:current_pattern . '\)' 68 | endfunction 69 | 70 | 71 | 72 | function! s:join(config) 73 | let ignore = a:config.ignore_pattern 74 | let left_matchstr = a:config.left_matchstr_pattern 75 | let right_matchstr = s:add_comment_leader_pattern(a:config.right_matchstr_pattern) 76 | let delimiter = s:escape_substitute_sub(a:config.delimiter) 77 | let c = substitute(a:config.delimiter_format, '%d', delimiter, "g") 78 | let start = a:config.firstline 79 | let lastline = a:config.firstline + a:config.line_num 80 | let end = lastline + (start == lastline) 81 | 82 | if end > line("$") 83 | return 84 | endif 85 | 86 | let line = s:join_list(getline(start, end), c, ignore, left_matchstr, right_matchstr) 87 | 88 | let view = winsaveview() 89 | let new_col = len(line) - len(matchstr(getline(end), right_matchstr)) 90 | let view['col'] = new_col - 1 91 | call setline(start, line) 92 | 93 | if start+1 <= end 94 | silent execute start+1 . ',' . end 'delete _' 95 | endif 96 | 97 | if end <= line("$") 98 | normal! -1 99 | endif 100 | call winrestview(view) 101 | endfunction 102 | 103 | 104 | 105 | let g:jplus#default_config = { 106 | \ "_" : { 107 | \ "left_matchstr_pattern" : '.\{-}\ze\s*$', 108 | \ "right_matchstr_pattern" : '\s*\zs.*', 109 | \ "ignore_pattern" : '', 110 | \ "delimiter" : " ", 111 | \ "delimiter_format" : "%d", 112 | \ }, 113 | \ "bash" : { 114 | \ "left_matchstr_pattern" : '^.\{-}\%(\ze\s*\\$\|$\)', 115 | \ }, 116 | \ "c" : { 117 | \ "left_matchstr_pattern" : '^.\{-}\%(\ze\s*\\$\|$\)', 118 | \ }, 119 | \ "cpp" : { 120 | \ "left_matchstr_pattern" : '^.\{-}\%(\ze\s*\\$\|$\)', 121 | \ }, 122 | \ "ruby" : { 123 | \ "left_matchstr_pattern" : '^.\{-}\%(\ze\s*\\$\|$\)', 124 | \ }, 125 | \ "python" : { 126 | \ "left_matchstr_pattern" : '^.\{-}\%(\ze\s*\\$\|$\)', 127 | \ }, 128 | \ "vim" : { 129 | \ "right_matchstr_pattern" : '^\s*\\\s*\zs.*\|\s*\zs.*', 130 | \ }, 131 | \ "zsh" : { 132 | \ "left_matchstr_pattern" : '^.\{-}\%(\ze\s*\\$\|$\)', 133 | \ }, 134 | \} 135 | 136 | 137 | let g:jplus#config = get(g:, "jplus#config", {}) 138 | 139 | function! jplus#get_config(filetype, ...) 140 | return s:extend_list([ 141 | \ get(g:jplus#default_config, "_", {}), 142 | \ get(g:jplus#config, "_", {}), 143 | \ get(g:jplus#default_config, a:filetype, {}), 144 | \ get(g:jplus#config, a:filetype, {}), 145 | \ get(a:, 1, {}) 146 | \ ]) 147 | endfunction 148 | 149 | 150 | let g:jplus#input_config = get(g:, "jplus#input_config", {}) 151 | 152 | function! jplus#get_input_config(input, filetype, ...) 153 | let empty_keyword = a:input ==# "" ? "__EMPTY__" : a:input 154 | return s:extend_list([ 155 | \ get(g:jplus#default_config, "_", {}), 156 | \ get(g:jplus#config, "_", {}), 157 | \ get(g:jplus#input_config, "__DEFAULT__", {}), 158 | \ get(g:jplus#default_config, a:filetype, {}), 159 | \ get(g:jplus#config, a:filetype, {}), 160 | \ { "delimiter" : a:input }, 161 | \ get(g:jplus#input_config, empty_keyword, {}), 162 | \ get(a:, 1, {}) 163 | \ ]) 164 | endfunction 165 | 166 | 167 | function! jplus#join(config) range 168 | if &modifiable == 0 169 | return 170 | endif 171 | let config = extend({ 172 | \ "firstline" : a:firstline, 173 | \ "line_num" : a:lastline - a:firstline, 174 | \ }, a:config) 175 | let s:latest_config = a:config 176 | let s:latest_config.line_num = config.line_num 177 | let &operatorfunc = "jplus#operatorfunc_latest_repeat" 178 | call feedkeys("g@g@", "n") 179 | " execute "normal!" (mode() =~# "[vV\]") ? "g@" : "g@g@" 180 | endfunction 181 | 182 | 183 | function! jplus#join_latest_repeat() 184 | if exists("s:latest_config") 185 | let config = extend({ 186 | \ "firstline" : a:firstline, 187 | \ "line_num" : a:lastline - a:firstline, 188 | \ }, s:latest_config) 189 | call s:join(config) 190 | endif 191 | endfunction 192 | 193 | 194 | function! jplus#mapexpr_join(...) 195 | let g:jplus_tmp_config = get(a:, 1, {}) 196 | return ":call jplus#join(g:jplus_tmp_c, g:jplus_tmp_config)\" 197 | endfunction 198 | 199 | 200 | function! s:operatorfunc(wise, ...) 201 | let base = get(a:, 1, {}) 202 | let first = getpos("'[")[1] 203 | let last = getpos("']")[1] 204 | let config = base 205 | call jplus#join(extend({ 206 | \ "firstline" : first, 207 | \ "lastline" : last, 208 | \ }, config)) 209 | endfunction 210 | 211 | 212 | function! jplus#operatorfunc(wise) 213 | return s:operatorfunc(a:wise, jplus#get_config(&filetype)) 214 | endfunction 215 | 216 | 217 | function! jplus#operatorfunc_input(wise) 218 | return s:operatorfunc(a:wise, jplus#get_input_config(input("Input joint delimiter : "), &filetype)) 219 | endfunction 220 | 221 | 222 | function! jplus#operatorfunc_getchar(wise) 223 | return s:operatorfunc(a:wise, jplus#get_input_config(jplus#getchar(), &filetype)) 224 | endfunction 225 | 226 | 227 | function! jplus#operatorfunc_latest_repeat(...) 228 | return jplus#join_latest_repeat() 229 | endfunction 230 | 231 | 232 | let &cpo = s:save_cpo 233 | unlet s:save_cpo 234 | -------------------------------------------------------------------------------- /doc/jplus.jax: -------------------------------------------------------------------------------- 1 | *jplus.txt* 特定の文字を挿入して行の結合を行います。 2 | 3 | ============================================================================== 4 | 目次 *jplus-contents* 5 | 6 | 概要 |jplus-introduction| 7 | 使い方 |jplus-usage| 8 | インターフェース |jplus-interface| 9 | マッピング |jplus-mapping| 10 | 設定 |jplus-setting| 11 | 変数 |jplus-variables| 12 | FAQ |jplus-FAQ| 13 | 14 | 15 | ============================================================================== 16 | 概要 *jplus-introduction* 17 | 18 | *jplus* は行を結合する際に挿入する文字を入力して行の結合を行う。 19 | 20 | before: > 21 | aaa 22 | bbb 23 | ccc 24 | < 25 | 26 | ↓↓↓ (jplus-getchar)+ ↓↓↓ 27 | 28 | after: > 29 | aaa+bbb+ccc 30 | < 31 | 32 | また、行継続のワード(\ など)を削除して行結合を行います。 33 | 34 | before: > 35 | " filetype=vim 36 | let = aaa 37 | \ + bbb 38 | \ + ccc 39 | < 40 | 41 | ↓↓↓ (jplus) ↓↓↓ 42 | 43 | after: > 44 | let = aaa + bbb + ccc 45 | < 46 | 47 | 48 | ============================================================================== 49 | 使い方 *jplus-usage* 50 | 51 | 任意のキーにマッピングして使用します。 52 | 53 | > 54 | " J の挙動を jplus.vim で行う 55 | nmap J (jplus) 56 | vmap J (jplus) 57 | 58 | " getchar() を使用して挿入文字を入力します 59 | nmap J (jplus-getchar) 60 | vmap J (jplus-getchar) 61 | 62 | " (jplus-getchar) 時に左右に空白文字を入れたい場合 63 | " %d は入力した結合文字に置き換えられる 64 | let g:jplus#config = { 65 | \ "_" : { 66 | \ "delimiter_format" : ' %d ' 67 | \ } 68 | \} 69 | 70 | " input() を使用したい場合はこちらを使用して下さい 71 | " nmap J (jplus-input) 72 | " vmap J (jplus-input) 73 | < 74 | 75 | 76 | ============================================================================== 77 | インターフェース *jplus-interface* 78 | 79 | ------------------------------------------------------------------------------ 80 | マッピング *jplus-mapping* 81 | 82 | (jplus) *(jplus)* 83 | |J| と同様に行の結合を行います。 84 | また、行継続が行われている場合はそのキーワード(行末の \ 文字など)を 85 | 自動的に削除して結合します。 86 | この削除機能は下記の 'filetype' が対応しています。 87 | 88 | "bash" 89 | "c" 90 | "cpp" 91 | "ruby" 92 | "python" 93 | "vim" 94 | "zsh" 95 | 96 | この時に |g:jplus#config| などに設定された |jplus-config| を参照します。 97 | 詳しくは |jplus-config-priority| を参照してください。 98 | 99 | (jplus-getchar) *(jplus-getchar)* 100 | |(jplus)| と同等の設定ですが、呼び出し時に挿入文字を入力して行の 101 | 結合を行います。 102 | 挿入文字の入力には |getchar()| が使用されます。 103 | また、この時に |g:jplus#input_config| などの設定を参照します。 104 | 詳しくは ||jplus-config-priority|| を参照してください。 105 | 106 | (jplus-getchar-with-space) *(jplus-getchar-with-space)* 107 | |(jplus-getchar)| と同様の動作ですが、挿入文字の左右にスペー 108 | スを挿入します。 109 | これは ||g:jplus#input_config|| の設定よりも優先します。 110 | 111 | (jplus-input) *(jplus-input)* 112 | |(jplus-getchar)| と同等の動作ですが、|input()| 113 | を使用して入力を行います. 114 | 115 | (jplus-input-with-space) *(jplus-input-with-space)* 116 | |(jplus-input)| と同様の動作ですが、挿入文字の左右にスペー 117 | スを挿入します。 118 | これは ||g:jplus#input_config|| の設定よりも優先します。 119 | 120 | 121 | ============================================================================== 122 | 設定 *jplus-setting* 123 | 124 | ------------------------------------------------------------------------------ 125 | 変数 *jplus-variables* 126 | 127 | g:jplus#config *g:jplus#config* 128 | 'filetype' をキーとした設定を記述します。 129 | "_" をキーとした場合はデフォルトの設定として使用します。 130 | この設定は |(jplus)| などのキーマッピングを使用した場合に参照さ 131 | れます。 132 | 各 'filetype' ごとに設定するフォーマットは |jplus-config| を参照して 133 | ください。 134 | 135 | NOTE: |(jplus-getchar)| などで入力した区切り文字は |g:jplus#config| 136 | で設定した |jplus-config-delimiter| よりも優先されます。 137 | 138 | |g:jplus#default_config| *g:jplus#default_config* 139 | |g:jplus#config| と同等の設定です。 140 | この変数はプラグイン内のデフォルト値として使用され、通常はユーザが 141 | 書き換えることはありません。 142 | 143 | g:jplus#input_config *g:jplus#input_config* 144 | |(jplus-getchar)| や |(jplus-input)| で参照される 145 | |jplus-config| の設定です。 146 | 入力された区切り文字をキーとした辞書を設定します. 147 | 入力された区切り文字によって設定を変えたい場合に使用します。 148 | また、キーにはいくつか特別な意味を持つ単語を設定する事ができます。 149 | 150 | "__DEFAULT__" : デフォルトの設定として使用 151 | "__EMPTY__" : 区切り文字の入力がなかった場合に使用 152 | 153 | Example: > 154 | " デフォルトでは結合文字の左右に " " をつける 155 | " 入力がなかった場合はスペースを挿入しないで結合する 156 | " , で結合する場合は ", " で結合する 157 | let g:jplus#input_config = { 158 | \ "__DEFAULT__" : { 159 | \ "delimiter_format" : " %d " 160 | \ }, 161 | \ "__EMPTY__" : { 162 | \ "delimiter_format" : "%d" 163 | \ }, 164 | \ "," : { 165 | \ "delimiter_format" : "%d " 166 | \ } 167 | \ } 168 | < 169 | 170 | 171 | ============================================================================== 172 | jplus-config *jplus-config* 173 | 174 | 行結合時に使用される設定のフォーマットです。 175 | 設定名をキーとして辞書形式で設定を行います。 176 | |g:jplus#config| などに設定して使用します。 177 | 178 | Example: > 179 | " filetype=vim でコメント行は結合しない(削除される) 180 | let g:jplus#config = { 181 | \ "vim" : { 182 | \ "ignore_pattern" : '^\s*"' 183 | \ } 184 | \} 185 | < 186 | 187 | - "delimiter" *jplus-config-delimiter* 188 | 結合時に使用する区切り文字です。 189 | 190 | Default: " " 191 | 192 | - "delimiter_format" *jplus-config-delimiter_format* 193 | 区切り文字のフォーマットです。 194 | 文字列内の "%d" が "delimiter" 文字に置き換えられます。 195 | 196 | Default: "%d" 197 | 198 | 199 | - "ignore_pattern" *jplus-config-ignore_pattern* 200 | 結合を行わない行のパターンです。 201 | このパターンにマッチした行は結合される削除されます。 202 | また、空の文字列が設定されている場合はすべての行にマッチします。 203 | 204 | Default: "" 205 | 206 | - "left_matchstr_pattern" *jplus-config-left_matchstr_pattern* 207 | 行結合する際に左辺に適用される |matchstr()| の {pat} の値です。 208 | 任意の文字列のみを結合する場合に使用します。 209 | また、複数行を結合する場合は、1行結合する毎に |matchstr()| が 210 | 適用されます。 211 | 212 | Default: '.*' 213 | 214 | - "right_matchstr_pattern" *jplus-config-right_matchstr_pattern* 215 | |jplus-config-left_matchstr_pattern| と同等の機能ですが、行結合時の 216 | 右辺に適用されるパターンになります。 217 | デフォルトでは "行頭のスペースを削除する" パターンが設定されていま 218 | す。 219 | 220 | Default: '\s*\zs.*' 221 | 222 | 223 | 224 | ------------------------------------------------------------------------------ 225 | 設定の優先順位 *jplus-config-priority* 226 | 227 | |(jplus)| 時に使用される |jplus-config| の優先順位は以下になります。 228 | 229 | 1. |g:jplus#default_config| の '_' 230 | 2. |g:jplus#config| の '_' 231 | 3. |g:jplus#default_config| の現在の 'filetype' 232 | 4. |g:jplus#config| の現在の 'filetype' 233 | 234 | 1. の優先順位が一番低く、4. に優先順位の高い設定を行います。 235 | 236 | 237 | |(jplus-getchar)| と |(jplus-input)| 時に使用される |jplus-config| 238 | の優先順位は以下になります。 239 | 240 | 1. |g:jplus#default_config| の '_' 241 | 2. |g:jplus#config| の '_' 242 | 3. |g:jplus#input_config| の '__DEFAULT__' 243 | 4. |g:jplus#default_config| の現在の 'filetype' 244 | 5. |g:jplus#config| の現在の 'filetype' 245 | 6. { "delimiter" : {入力された区切り文字} } 246 | 7. |g:jplus#input_config| の入力された区切り文字 247 | 248 | 1. の優先順位が一番低くなります。 249 | 入力された区切り文字を設定で変更した場合は 250 | g:jplus#input_config[{入力された文字列}].delimiter 251 | に対して設定します。 252 | 253 | 254 | ============================================================================== 255 | FAQ *jplus-FAQ* 256 | 257 | Q. 行結合時に先頭のスペースを削除したくない 258 | 259 | A. |g:jplus#config| に |jplus-config-right_matchstr_pattern| を設定します。 260 | > 261 | " right_matchstr_pattern にすべての文字列を適用するようなパターンを設定する 262 | " "_" はすべての filetype で使用される設定 263 | let g:jplus#config = { 264 | \ "_" : { 265 | \ "matchstr_pattern" : '\s*\\\s*\zs.*\|\s*\zs.*' 266 | \ } 267 | \} 268 | < 269 | 270 | Q. コメントアウトされている行を結合しない 271 | 272 | A. |g:jplus#config| に |jplus-config-ignore_pattern| を設定します。 273 | > 274 | " filetype=vim 時の設定 275 | let g:jplus#config = { 276 | \ "vim" : { 277 | \ "ignore_pattern" : '^\s*"' 278 | \ } 279 | \} 280 | 281 | 282 | Q. |(jplus-getchar)| 等で "," を入力した場合に ", " で結合したい。 283 | 284 | A. |g:jplus#input_config| に "," 時の設定を追加します。 285 | > 286 | let g:jplus#input_config = { 287 | \ "," : { 288 | \ "delimiter_format" : " %d " 289 | \ } 290 | \} 291 | < 292 | 293 | 294 | ============================================================================== 295 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 296 | -------------------------------------------------------------------------------- /doc/jplus.txt: -------------------------------------------------------------------------------- 1 | *jplus.txt* Join lines inserting characters in between 2 | 3 | ============================================================================== 4 | CONTENTS *jplus-contents* 5 | 6 | Introduction |jplus-introduction| 7 | Usage |jplus-usage| 8 | Interface |jplus-interface| 9 | Mappings |jplus-mapping| 10 | Settings |jplus-setting| 11 | Variables |jplus-variables| 12 | FAQ |jplus-FAQ| 13 | 14 | 15 | ============================================================================== 16 | INTRODUCTION *jplus-introduction* 17 | 18 | This plugin lets you input characters to insert between lines when joining 19 | lines. 20 | 21 | before: > 22 | aaa 23 | bbb 24 | ccc 25 | < 26 | 27 | ↓↓↓ (jplus-getchar)+ ↓↓↓ 28 | 29 | after: > 30 | aaa+bbb+ccc 31 | < 32 | 33 | Additionally, it deletes the line continuation character (such as \) when 34 | joining. 35 | 36 | before: > 37 | " filetype=vim 38 | let = aaa 39 | \ + bbb 40 | \ + ccc 41 | < 42 | 43 | ↓↓↓ (jplus) ↓↓↓ 44 | 45 | after: > 46 | let = aaa + bbb + ccc 47 | < 48 | 49 | 50 | ============================================================================== 51 | USAGE *jplus-usage* 52 | 53 | You can map it to the key of your preference to use it. 54 | 55 | > 56 | " Let jplus.vim handle default behaviour of J 57 | nmap J (jplus) 58 | vmap J (jplus) 59 | 60 | " Input one character getchar() to insert between lines 61 | nmap J (jplus-getchar) 62 | vmap J (jplus-getchar) 63 | 64 | " When you want to add surrounding spaces with (jplus-getchar) 65 | " %d is replaced with the input character 66 | let g:jplus#config = { 67 | \ "_" : { 68 | \ "delimiter_format" : ' %d ' 69 | \ } 70 | \} 71 | 72 | " When you want to use input() (for more than one character) 73 | " nmap J (jplus-input) 74 | " vmap J (jplus-input) 75 | < 76 | 77 | 78 | ============================================================================== 79 | INTERFACE *jplus-interface* 80 | 81 | ------------------------------------------------------------------------------ 82 | MAPPINGS *jplus-mapping* 83 | 84 | (jplus) *(jplus)* 85 | Does line concatenation similar to |J|. 86 | This will automatically remove the line continuation character (such 87 | as a trailing \) when joining lines. 88 | Automatic removal is done in the following 'filetype'. 89 | 90 | "bash" 91 | "c" 92 | "cpp" 93 | "ruby" 94 | "python" 95 | "vim" 96 | "zsh" 97 | 98 | The plugin will check the |jplus-config| set in |g:jplus#config|. 99 | See |jplus-config-priority| for more details. 100 | 101 | (jplus-getchar) *(jplus-getchar)* 102 | Similar to |(jplus)| but prompts for a character that is used as 103 | a delimiter for the lines. Character input is done using |getchar()|. 104 | The plugin will look settings in |g:jplus#input_config|. 105 | See |jplus-config-priority| for more details. 106 | 107 | (jplus-getchar-with-space) *(jplus-getchar-with-space)* 108 | Similar to |(jplus-getchar)|, but inserts surrounding spaces 109 | around the delimiter character. 110 | This has higher priority than the configurations in 111 | |g:jplus#input_config|. 112 | 113 | (jplus-input) *(jplus-input)* 114 | Similar to |(jplus-getchar)| but uses |input()| for prompting. 115 | 116 | (jplus-input-with-space) *(jplus-input-with-space)* 117 | Similar to |(jplus-input)| but inserts surrounding spaces around 118 | the delimiter character. 119 | This has higher priority than the configurations in 120 | |g:jplus#input_config|. 121 | 122 | 123 | ============================================================================== 124 | SETTINGS *jplus-setting* 125 | 126 | ------------------------------------------------------------------------------ 127 | VARIABLES *jplus-variables* 128 | 129 | g:jplus#config *g:jplus#config* 130 | States the configurations with 'filetype' being the keys. 131 | When "_" is used as the key, it is used as the default configurations. 132 | These configurations are used when key mappings such as 133 | |(jplus)| are used. 134 | See |jplus-config| for the format of the configurations per 135 | 'filetype'. 136 | 137 | NOTE: The delimiter characters entered using |(jplus-getchar)| 138 | have higher priority than the |jplus-config-delimiter| set in 139 | |g:jplus#config|. 140 | 141 | |g:jplus#default_config| *g:jplus#default_config* 142 | Same configurations as |g:jplus#config|. 143 | This variable is used as the default value, and is normally not 144 | modified by the user. 145 | 146 | g:jplus#input_config *g:jplus#input_config* 147 | |jplus-config| configurations that are used by |(jplus-getchar)| 148 | and |(jplus-input)|. 149 | Dictionary whose keys are the entered delimiter character. 150 | This is used when you want to change the format depending on the 151 | character entered. 152 | "__DEFAULT__" key is used as the default configurations. 153 | Example: > 154 | > 155 | " Surround the delimiter character with spaces by default 156 | " Only add a space to the left when joining with a comma 157 | let g:jplus#input_config = { 158 | \ "__DEFAULT__" : { 159 | \ "delimiter_format" : " %d " 160 | \ }, 161 | \ "," : { 162 | \ "delimiter_format" : "%d " 163 | \ } 164 | \} 165 | < 166 | 167 | 168 | ============================================================================== 169 | jplus-config *jplus-config* 170 | 171 | Defines the configurations that are used when joining lines. 172 | This is a dictionary with the key being the name of the configuration. 173 | Use this format for configurations such as |g:jplus#config|. 174 | 175 | Example: > 176 | " Don't join comment lines and delete them when filetype=vim 177 | let g:jplus#config = { 178 | \ "vim" : { 179 | \ "ignore_pattern" : '^\s*"' 180 | \ } 181 | \} 182 | < 183 | 184 | - "delimiter" *jplus-config-delimiter* 185 | Delimiter used when joining. 186 | 187 | Default: " " 188 | 189 | - "delimiter_format" *jplus-config-delimiter_format* 190 | The format of the delimiter. 191 | "%d" is replaced with the "delimiter". 192 | 193 | Default: "%d" 194 | 195 | 196 | - "ignore_pattern" *jplus-config-ignore_pattern* 197 | Ignore lines that match this pattern. Ignored lines are deleted. 198 | No lines are ignored when an empty string is set. 199 | 200 | Default: "" 201 | 202 | - "left_matchstr_pattern" *jplus-config-left_matchstr_pattern* 203 | The {pat} value used for |matchstr()| when applying the pattern to the 204 | left hand side when joining lines. 205 | Used when joining only certain strings. 206 | When joining multiple lines, this pattern is used on each line. 207 | 208 | Default: '.*' 209 | 210 | - "right_matchstr_pattern" *jplus-config-right_matchstr_pattern* 211 | Similar to |jplus-config-left_matchstr_pattern| but is applied to the 212 | right hand side. 213 | The default pattern "removes the leading whitespaces." 214 | 215 | Default: '\s*\zs.*' 216 | 217 | 218 | 219 | ------------------------------------------------------------------------------ 220 | PRIORITIES *jplus-config-priority* 221 | 222 | The following list shows the priorities of the |jplus-config| configurations 223 | used on |(jplus)|. 224 | 225 | 1. '_' key of |g:jplus#default_config| 226 | 2. '_' key of |g:jplus#config| 227 | 3. Current 'filetype' key of |g:jplus#default_config| 228 | 4. Current 'filetype' key of |g:jplus#config| 229 | 230 | where 1 is the lowest, and 4 is the highest priority. 231 | 232 | 233 | The priorities of the |jplus-config| used on |(jplus-getchar)| and 234 | |(jplus-input)| are the following. 235 | 236 | 1. '_' key of |g:jplus#default_config| 237 | 2. '_' key of |g:jplus#config| 238 | 3. '__DEFAULT__' key of |g:jplus#input_config| 239 | 4. Current 'filetype' key of |g:jplus#default_config| 240 | 5. Current 'filetype' key of |g:jplus#config| 241 | 6. { "delimiter" : {Entered delimiter} } 242 | 7. Entered delimiter in |g:jplus#input_config| 243 | 244 | where 1 is the lowest priority. 245 | If you want to change the configurations for the entered delimiter, change 246 | g:jplus#input_config[{Entered delimiter}].delimiter 247 | 248 | 249 | ============================================================================== 250 | FAQ *jplus-FAQ* 251 | 252 | Q. Don't remove the leading spaces when joining 253 | 254 | A. Set |jplus-config-right_matchstr_pattern| in |g:jplus#config|. 255 | > 256 | " Apply this right_matchstr_pattern to all strings 257 | " "_" is the default configuration for all filetypes 258 | let g:jplus#config = { 259 | \ "_" : { 260 | \ "matchstr_pattern" : '\s*\\\s*\zs.*\|\s*\zs.*' 261 | \ } 262 | \} 263 | < 264 | 265 | Q. Don't join lines that are commented out 266 | 267 | A. Set |jplus-config-ignore_pattern| in |g:jplus#config| 268 | > 269 | " When filetype=vim 270 | let g:jplus#config = { 271 | \ "vim" : { 272 | \ "ignore_pattern" : '^\s*"' 273 | \ } 274 | \} 275 | 276 | 277 | Q. When joining with "," using |(jplus-getchar)|, I want the delimiter 278 | to be ", " 279 | 280 | A. Add the settings for "," in |g:jplus#input_config| 281 | > 282 | let g:jplus#input_config = { 283 | \ "," : { 284 | \ "delimiter_format" : " %d " 285 | \ } 286 | \} 287 | < 288 | 289 | 290 | ============================================================================== 291 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 292 | -------------------------------------------------------------------------------- /plugin/jplus.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | if exists('g:loaded_jplus') 3 | finish 4 | endif 5 | let g:loaded_jplus = 1 6 | 7 | let s:save_cpo = &cpo 8 | set cpo&vim 9 | 10 | 11 | function! s:config(base) 12 | return jplus#get_config(&filetype, a:base) 13 | endfunction 14 | 15 | 16 | function! s:input_config(input, base) 17 | return jplus#get_input_config(a:input, &filetype, a:base) 18 | endfunction 19 | 20 | 21 | noremap (jplus-getchar) 22 | \ :call jplus#join(input_config(jplus#getchar(), {})) 23 | 24 | noremap (jplus-getchar-with-space) 25 | \ :call jplus#join(input_config(jplus#getchar(), { "delimiter_format" : " %d " })) 26 | 27 | noremap (jplus-input) 28 | \ :call jplus#join(input_config(input("Input joint delimiter : "), {})) 29 | 30 | noremap (jplus-input-with-space) 31 | \ :call jplus#join(input_config(input("Input joint delimiter :"), { "delimiter_format" : " %d " })) 32 | 33 | 34 | noremap (jplus) 35 | \ :call jplus#join(config({})) 36 | 37 | nnoremap (operator-jplus) 38 | \ :set operatorfunc=jplus#operatorfuncg@ 39 | 40 | nnoremap (operator-jplus-getchar) 41 | \ :set operatorfunc=jplus#operatorfunc_getcharg@ 42 | 43 | nnoremap (operator-jplus-input) 44 | \ :set operatorfunc=jplus#operatorfunc_inputg@ 45 | 46 | 47 | let &cpo = s:save_cpo 48 | unlet s:save_cpo 49 | --------------------------------------------------------------------------------