-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimprovedft.vmb
842 lines (749 loc) · 26.2 KB
/
improvedft.vmb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
" Vimball Archiver by Charles E. Campbell
UseVimball
finish
plugin/ft_improved.vim [[[1
148
" ft_improved.vim - Better f/t command for Vim
" -------------------------------------------------------------
" Version: 0.9
" Maintainer: Christian Brabandt <cb@256bit.org>
" Last Change: Thu, 15 Jan 2015 21:40:10 +0100
"
" Script:
" Copyright: (c) 2009, 2010, 2011, 2012 by Christian Brabandt
" The VIM LICENSE applies to histwin.vim
" (see |copyright|) except use "ft_improved.vim"
" instead of "Vim".
" No warranty, express or implied.
" *** *** Use At-Your-Own-Risk! *** ***
" GetLatestVimScripts: 3877 9 :AutoInstall: ft_improved.vim
"
" Init: {{{1
let s:cpo= &cpo
if exists("g:loaded_ft_improved") || &cp
finish
endif
set cpo&vim
let g:loaded_ft_improved = 1
fun! <sid>DoNotRemap(key) "{{{1
if a:key ==? ','
return get(g:, 'ft_improved_nomap_comma', 0)
elseif a:key ==? ';'
return get(g:, 'ft_improved_nomap_semicolon', 0)
else
return get(g:, 'ft_improved_nomap_'.a:key, 0)
endif
endfu
fun! <sid>Map(lhs, rhs) "{{{1
if !hasmapto(a:rhs, 'nxo') && !<sid>DoNotRemap(a:lhs)
for mode in split('nxo', '\zs')
exe mode. "noremap <silent> <expr> <unique>" a:lhs
\ substitute(a:rhs, 'X', '"'.mode.'"', '')
endfor
endif
endfun
fun! <sid>Unmap(lhs) "{{{1
if !empty(maparg(a:lhs, 'nov'))
exe "nunmap" a:lhs
exe "xunmap" a:lhs
exe "ounmap" a:lhs
endif
endfun
fun! <sid>Activate(enable) "{{{1
if a:enable
" Disable the remapping of those keys by the yankring plugin
" and reload the Yankring plugin
" github issue #1
let g:yr_mapped = [0, 0]
if exists("g:loaded_yankring") &&
\ g:loaded_yankring > 1
" should make sure, the user didn't set this variable to simply
" deactivate the plugin. If so, he probably only set it to 1...
if exists(":YRToggle") == 2
" turn off and on again yankring
" first turn off with the original values of the variables,
" so everything is disabled correctly
sil YRToggle 0
" now adjust the Yankring options
if g:yankring_zap_keys =~# "[ft]"
let g:yankring_zap_keys =
\ substitute(g:yankring_zap_keys,
\ '\c[ft] ', "", "g")
let g:yr_mapped[0] = 1
endif
if g:yankring_o_keys =~ "[,;]"
let g:yankring_o_keys =
\ substitute(g:yankring_o_keys, '[,;] ',
\ "", "g")
let g:yr_mapped[1] = 1
endif
" enable the plugin again
sil YRToggle 1
endif
else
" YankRing wasn't loaded yet, so init those variables
let g:yankring_zap_keys = "/ ?"
let g:yankring_o_keys = 'b B w W e E d h j k l H M L y G ^ 0 $'
let g:yankring_o_keys .= ' g_ g^ gm g$ gk gj gg ge gE - + _ '
let g:yankring_o_keys .= ' iw iW aw aW as is ap ip a] a[ i] i['
let g:yankring_o_keys .= ' a) a( ab i) i( ib a> a< i> i< at it'
let g:yankring_o_keys .= ' a} a{ aB i} i{ iB a" a'' a` i" i'' i`'
endif
" f,F,t,T should be unmaped now, so we can map it.
call <sid>Map('f', 'ftimproved#FTCommand(1,1,X)')
call <sid>Map('F', 'ftimproved#FTCommand(1,0,X)')
call <sid>Map('t', 'ftimproved#FTCommand(0,1,X)')
call <sid>Map('T', 'ftimproved#FTCommand(0,0,X)')
call <sid>Map(';', 'ftimproved#ColonCommand(1,X)')
call <sid>Map(',', 'ftimproved#ColonCommand(0,X)')
else
call <sid>Unmap('f')
call <sid>Unmap('F')
call <sid>Unmap('t')
call <sid>Unmap('T')
call <sid>Unmap(',')
call <sid>Unmap(';')
if exists("g:loaded_yankring") &&
\ g:loaded_yankring > 1
" should make sure, the user didn't set this variable to simply
" deactivate the plugin. If so, he probably only set it to 1...
if exists(":YRToggle") == 2
" turn off and on again yankring
sil YRToggle 0
" reset the yankring options
if g:yr_mapped[0]
let g:yankring_zap_keys .= 'f F t T '
else
unlet! g:yankring_zap_keys
endif
if g:yr_mapped[1]
let g:yankring_o_keys .= ', ; '
else
unlet! g:yankring_o_keys
endif
" enable Yankring, and reload the YankRing
sil YRToggle 1
endif
endif
endif
endfun
" ----------------------------------------------------------------------------
" Define the Mapping: "{{{2
"noremap <script> <Plug>F_Cmd_forward <sid>F_Cmd_fw
"noremap <script> <Plug>F_Cmd_backward <sid>F_Cmd_bw
"noremap <script> <Plug>T_Cmd_forward <sid>T_Cmd_fw
"noremap <script> <Plug>T_Cmd_backward <sid>T_Cmd_bw
"
"noremap <sid>F_Cmd_fw ft_improved#FTCommand(1,1)
"noremap <sid>F_Cmd_bw ft_improved#FTCommand(1,0)
"noremap <sid>T_Cmd_fw ft_improved#FTCommand(0,1)
"noremap <sid>T_Cmd_bw ft_improved#FTCommand(0,0)
com! DisableImprovedFT :call <sid>Activate(0)
com! EnableImprovedFT :call <sid>Activate(1)
call <sid>Activate(1)
" Restore: "{{{1
let &cpo=s:cpo
unlet s:cpo
" vim: ts=4 sts=4 fdm=marker com+=l\:\"
autoload/ftimproved.vim [[[1
453
" ftimproved.vim - Better f/t command for Vim
" -------------------------------------------------------------
" Version: 0.9
" Maintainer: Christian Brabandt <cb@256bit.org>
" Last Change: Thu, 15 Jan 2015 21:40:10 +0100
" Script: http://www.vim.org/scripts/script.php?script_id=3877
" Copyright: (c) 2009 - 2013 by Christian Brabandt
" The VIM LICENSE applies to ft_improved.vim
" (see |copyright|) except use "ft_improved.vim"
" instead of "Vim".
" No warranty, express or implied.
" *** *** Use At-Your-Own-Risk! *** ***
" GetLatestVimScripts: 3877 9 :AutoInstall: ft_improved.vim
"
" Functions:
let s:cpo= &cpo
set cpo&vim
" Debug Mode:
let s:debug = 0
let s:escape = "\e"
fun! <sid>ReturnOperatorOffset(f_mot, fwd, mode) "{{{1
" Return list with 2 items
" item 0: operator, item 1: offset
if a:f_mot
" f-command
if a:mode =~ 'o'
" operator pending mode
" :h o_v
return ['v', '']
endif
else
" t-command
if a:mode =~? 'v\|'
return ['', a:fwd ? 's-' : 'e']
elseif a:mode !~ 'o'
return ['', a:fwd ? 'e-' : 'e+']
endif
endif
return ['', '']
endfun
fun! <sid>DebugOutput(string) "{{{1
if s:debug
echom strtrans(a:string)
endif
return a:string
endfun
fun! <sid>Opposite(char) "{{{1
if a:char == '/' || a:char =~ '[ft]'
return '?'
else
return '/'
endif
endfun
fun! <sid>SearchForChar(char) "{{{1
if a:char =~# '[ft]'
return '/'
else
return '?'
endif
endfun
fun! <sid>EscapePat(pat, vmagic) "{{{1
let pat = escape(a:pat, '\')
if pat ==# ''
let pat = '\r'
elseif pat ==# ' '
let pat = '\t'
" elseif pat ==# '' " Will be skipped anyhow
" let pat = '\e'
"
" TODO: Other characters to take care of?
endif
return (a:vmagic ? '\V' : '').pat
endfun
fun! <sid>ColonPattern(cmd, pat, off, f, fwd) "{{{1
if !exists("s:colon")
let s:colon = {}
endif
let cmd = a:cmd
let pat = a:pat
let opp = <sid>Opposite(a:cmd[-1:])
let opp_off = <sid>Opposite(a:off[0])
if a:cmd ==# 'f' || a:cmd ==# 't'
let cmd = '/'
elseif a:cmd == 'F' || a:cmd ==# 'T'
let cmd = '?'
endif
let s:colon[';'] = cmd[-1:]. pat.
\ (empty(a:off) ? cmd[-1:] : a:off)
let s:colon[','] = cmd[:-2]. opp. pat.
\ (empty(a:off) ? opp : opp_off . a:off[1])
let s:colon['cmd'] = a:f
endfun
fun! <sid>HighlightMatch(char, dir) "{{{1
if get(g:, 'ft_improved_nohighlight', 0)
return
endif
if exists("s:matchid")
sil! call matchdelete(s:matchid)
endif
let output=''
"if !empty(a:char) && a:char !~# '\%(\\c\)\?\%(\V\)\?$'
if !empty(matchstr(a:char, '^\%(\\c\)\?\\V\zs.*$'))
let output = matchstr(a:char, '^\%(\\c\)\?\\V\zs.*')
" remove escaping for display
let output = substitute(output, '\\\\', '\\', 'g')
let pos = [line('.'), col('.')]
if a:dir
" If a count has been given, first move to the count'th match and
" then highlight all matches after that (the count works only for
" the first entered char
while s:count > 1
" skip that many matches
let pos = searchpos(a:char, 'eW')
let s:count -= 1
endw
let pat = '\%(\%>'. pos[1]. 'c\&\%'. pos[0]. 'l'
let pat .= '\|\%>'. pos[0]. 'l\)'. a:char
" Make sure, it only matches within the current viewport
let pat = '\%('. pat. '\m\)\ze\&\%<'.(line('w$')+1).'l'.a:char
else
while s:count > 1
let pos = searchpos(a:char, 'bW')
let s:count -= 1
endw
let pat = '\%(\%<'. pos[1]. 'c\&\%'. pos[0]. 'l'
let pat .= '\|\%<'. pos[0]. 'l\)'. a:char
" Make sure, it only matches within the current viewport
let pat = '\%('. pat. '\m\)\ze\&\%>'.(line('w0')-1).'l'.a:char
endif
let s:matchid = matchadd('IncSearch', pat)
redraw!
" Output input string after(!) redraw.
if !empty(output)
echohl Title
exe ':echon '. string(output)
echohl Normal
endif
else
redraw! "clear screen"
endif
endfu
fun! <sid>CheckSearchWrap(pat, fwd, cnt) "{{{1
" Check, if search would warp around
let counter = 1
let oldpos = getpos('.')
while a:cnt >= counter
let line = search(a:pat, (a:fwd ? '' : 'b') .'W')
if !line
" don't return anything, if the search would wrap around
call setpos('.', oldpos)
return 1
endif
let counter+=1
endw
call setpos('.', oldpos)
return 0
endfun
fun! <sid>CountMatchesWin(pat, forward) "{{{1
" Return number of matches of pattern window start and cursor (backwards)
" or cursorline and window end line (forward search)
" TODO: filter folded lines?
if a:forward
let first = line('.') + 1
let last = line('w$')
let cursorline = getline('.')[col('.')-1:]
else
let first = line('w0')
let last = line('.')-1
let cursorline = matchstr(getline('.'), '^.*\%'.col('.').'c')
endif
" Skip folded lines (they are not visible and won't be available for
" jumping to.
let buf = ''
let line = first
while line <= last
if foldclosed(line) != -1
let line = foldclosedend(line) + 1
continue
endif
let buf .= getline(line) . "\n"
let line+=1
endw
let buf .= "\n". cursorline
return len(split(buf, a:pat.'\zs', 1)) - 1
endfu
fun! ftimproved#ColonCommand(f, mode) "{{{1
" a:f f/F command, a:mode: map mode
if !exists("s:searchforward")
let s:searchforward = 1
endif
let fcmd = (a:f ? ';' : ',')
if !exists("s:colon")
let s:colon={}
let s:colon[';']=''
let s:colon[',']=''
let s:colon['cmd'] = ''
endif
let res = ''
let res = (empty(s:colon[fcmd]) ? fcmd : s:colon[fcmd])
if get(g:, 'ft_improved_consistent_comma', 0)
if a:f
let res = '/'.res[1:-2]. '/'
else
let res = '?'.res[1:-2]. '?'
endif
endif
let oldsearchpat = @/
if a:mode =~ 'o' &&
\ s:colon['cmd'] " last search was 'f' command
" operator pending. For f cmd, make sure the motion is inclusive
let res = 'v'.res
endif
if res != fcmd
try
let pat = matchlist(res, '^v\?\([/?]\)\(.*\)\1\([bse].\)\?')
" ?-search, means, we need to escape '?' in the pattern
let spat = pat[2]
if pat[1] =~ '[?/]'
let pat[2] = escape(pat[2], pat[1])
if !s:colon['cmd'] && pat[1] == '?'
" T command
let res = pat[1]. '\('. pat[2]. '\m\)\@<=.' . pat[1]
elseif !s:colon['cmd']
" t command and forward search
let res = pat[1]. '.\@>\(' . pat[2]. '\)'. pat[1]
else
let res = pat[1] . pat[2] . pat[1]
endif
endif
if !search(spat, (pat[1]=='?' ? 'b' : '').'nW') ||
\ <sid>CheckSearchWrap(spat, pat[1]!='?', v:count1)
" noop
let res = ''
endif
if pat[1]=='?'
let tline = search(spat, 'bnW')
if tline < line('.') && getline(tline) =~ spat.'\$'
" Match is in the last column of a previous line
let res = substitute(res, '[/?]\zs[se][+-]$', '', '')
endif
endif
catch
" Most likely, the matchlist did not succeed.
let res = ''
endtry
endif
" Ctrl-C should be a noop
let res = (empty(res) ? s:escape : res."\n")
if a:mode != 'o' && v:operator != 'c'
let res .= ":\<C-U>call histdel('/', -1)\<cr>".
\ ":\<C-U>let @/='". oldsearchpat. "'\<cr>"
endif
return <sid>DebugOutput(res)
endfun
fun! ftimproved#FTCommand(f, fwd, mode) "{{{1
" f: its an f-command
" fwd: forward motion
" mode: mapping mode
try
let s:searchforward = a:fwd
let char = nr2char(getchar())
if char == s:escape
" abort when Escape has been hit
return <sid>DebugOutput(char)
elseif empty(char) || char ==? "\x80\xFD\x60" "CursorHoldEvent"
return <sid>DebugOutput(s:escape)
endif
" Use a script local var, so that you can use 3fi (and afterwards
" further redefine the search term, without skipping the next 2
" matching patterns!
let s:count = v:count1
let orig_char = char
let char = <sid>EscapePat(char, 1)
" ignore case of pattern? Does only work with search, not with original
" f/F/t/T commands
if get(g:, "ft_improved_ignorecase", 0)
let char = '\c'.char
endif
if get(g:, "ft_improved_multichars", 0) &&
\ <sid>CountMatchesWin(char, a:fwd) > 1
call <sid>HighlightMatch(char, a:fwd)
let next = getchar()
" break on Enter, Esc or Backspace
while !empty(next) && ((next !=? "\x80\xFD\x60" &&
\ next != 13 &&
\ next != 10 &&
\ next != 27) || next == "\<BS>")
if next == "\<BS>"
" Remove one char
let char = substitute(char, '\%(\\\\\|.\)$', '', '')
else
let char .= <sid>EscapePat(nr2char(next),0)
endif
" Get matches of pattern within the windows viewport
let matches = <sid>CountMatchesWin(char, a:fwd)
if matches == 0
" no match within the windows viewport, abort
return <sid>DebugOutput(s:escape)
elseif matches == 1
break
endif
if char =~# '^\%(\\c\)\?\\V$'
" don't highlight empty pattern
call <sid>HighlightMatch('', a:fwd)
else
call <sid>HighlightMatch(char, a:fwd)
endif
if !search(char, (a:fwd ? '' : 'b'). 'Wn')
" Pattern not found, abort
return <sid>DebugOutput(s:escape)
endif
" Get next character
let next = getchar()
endw
if nr2char(next) == s:escape
" abort when Escape has been hit
return <sid>DebugOutput(s:escape)
elseif empty(next) || next ==? "\x80\xFD\x60" "CursorHold Event"
return <sid>DebugOutput(s:escape)
endif
endif
let oldsearchpat = @/
let no_offset = 0
let cmd = (a:fwd ? '/' : '?')
let pat = char
if !get(g:, "ft_improved_multichars", 0)
" Check if normal f/t commands would work:
if search(matchstr(pat.'\C', '^\%(\\c\)\?\zs.*'), 'nW') == line('.')
\ && a:fwd
let cmd = (a:f ? 'f' : 't')
call <sid>ColonPattern(<sid>SearchForChar(cmd),
\ pat, '', a:f, a:fwd)
return <sid>DebugOutput(cmd.orig_char)
elseif search(matchstr(pat.'\C', '^\%(\\c\)\?\zs.*'), 'bnW') == line('.')
\ && !a:fwd
let cmd = (a:f ? 'F' : 'T')
call <sid>ColonPattern(<sid>SearchForChar(cmd),
\ pat, '', a:f, a:fwd)
return <sid>DebugOutput(cmd.orig_char)
endif
endif
" Check if search would wrap
if (search(pat, 'nW') == 0 && a:fwd) ||
\ (search(pat, 'bnW') == 0 && !a:fwd)
" return ESC
call <sid>ColonPattern(<sid>SearchForChar(cmd),
\ pat, '', a:f, a:fwd)
return <sid>DebugOutput(s:escape)
endif
let cnt = v:count1
let off = cmd
let res = ''
let op_off = <sid>ReturnOperatorOffset(a:f, a:fwd, a:mode)
if a:f
" Searching using 'f' command
"if a:mode == 'o'
" There is a strange vi behaviour
" Cite from Vim source code:
"
" * Imitate the strange Vi behaviour: If the delete spans more
" * than one line and motion_type == MCHAR and the result is a
" * blank line, make the delete linewise.
" * Don't do this for the change command or Visual mode.
"if a:mode !~# 'v\|'
" Not working correctly in Vim. This looks like a bug:
" Message-ID: 20120104185216.GB9668@256bit.org
" should be fixed with 7.3.396
"let cmd = cnt . 'v' . cmd
"endif
"endif
let cmd = op_off[0].cmd
let off .= op_off[1]
let pat1 = (a:fwd ? escape(pat, '/') : escape(pat, '?'))
let res = cmd.pat1.off."\<cr>"
else
" Searching using 't' command
let cmd = op_off[0].cmd
" if match is on previous line the last char, don't add offset
if !a:fwd
let pos=searchpos(pat, 'bnW')
if ((pos[0] < line('.') &&
\ pos[1] != strlen(substitute(getline(pos[0]), '.', 'X', 'g'))) ||
\ pos[0] == line('.'))
let off .= op_off[1]
else
let no_offset = 1
endif
else
let off .= op_off[1]
endif
let pat1 = (a:fwd ? escape(pat, '/') : escape(pat, '?'))
let res = cmd.pat1.off."\<cr>"
endif
if <sid>CheckSearchWrap(pat, a:fwd, cnt)
let res = s:escape
endif
" handle 'cedit' key gracefully
let res = substitute(res, &cedit, ''.&cedit, '')
" save pattern for ';' and ','
call <sid>ColonPattern(cmd, pat,
\ off. (no_offset ? op_off[1] : ''), a:f, a:fwd)
let pat = pat1
let post_cmd = ''
" If operator is c, don't switch to normal mode after the
" command, else we would lose the repeatability using '.'
" (e.g. cf,foobar<esc> is not repeatable anymore)
if a:mode != 'o' || (a:mode == 'o' && v:operator != 'c')
let post_cmd = ":\<C-U>call histdel('/', -1)\<cr>".
\ ":\<C-U>let @/='". oldsearchpat. "'\<cr>"
endif
" For visual mode, the :Ex commands exit the visual selection, so need
" to reselect it
return <sid>DebugOutput(res.post_cmd. ((a:mode ==? 'x') ? 'gv' : ''))
finally
call <sid>HighlightMatch('', a:fwd)
endtry
endfun
" Restore: "{{{1
let &cpo=s:cpo
unlet s:cpo
" Modeline {{{1
" vim: ts=4 sts=4 fdm=marker com+=l\:\" fdl=0
doc/ft_improved.txt [[[1
231
*ft_improved.txt* - Better f/t command for Vim
Author: Christian Brabandt <cb@256bit.org>
Version: 0.9 Thu, 15 Jan 2015 21:40:10 +0100
Copyright: (c) 2009-2013 by Christian Brabandt
The VIM LICENSE applies to improved_ft.vim and improved_ft.txt
(see |copyright|) except use improved_ft instead of "Vim".
NO WARRANTY, EXPRESS OR IMPLIED. USE AT-YOUR-OWN-RISK.
==============================================================================
1. Contents *improvedft-ft*
1. Contents...................................: |improvedft-ft|
2. Manual.....................................: |improvedft-manual|
2.1 Enable...................................: |improvedft-Enable|
2.2 Disable..................................: |improvedft-Disable|
2.3 Tips.....................................: |improvedft-Tips|
2.3.1 Using the YankRing.......................: |improvedft-YankRing|
2.3.2 Ignoring case............................: |improvedft-ignorecase|
2.3.3 Searching for more chars.................: |improvedft-multichars|
2.3.4 Consistent ,/; keys......................: |improvedft-consistent_comma|
2.4 Mapping..................................: |improvedft-Mapping|
2.5 Bugs.....................................: |improvedft-Bugs|
3. Feedback...................................: |improvedft-feedback|
4. History....................................: |improvedft-history|
==============================================================================
2. Improved ft command Manual *improvedft-manual*
Functionality
This plugin tries to improve the existing behaviour of the |f|, |F|, |t| and
|T| command by letting them move the cursor not only inside the current line,
but move to whatever line, where the character is found. Also the |,| and |;|
command should consistently by default, but can be enabled to work as usual
(see |improvedft-consistent_comma|).
It does consider counts given and should work simply as a user would be
expecting.
It basically does that, by remapping the f,F,t and T command to issue a search
for the character that is entered and moving the cursor there.
2.1 Enable *improvedft-Enable*
----------
By default the new f,F,t,T commands should simply work. If you have disabled
the plugin (see |improvedft-Disable|), use the command >
:EnableImprovedFT
<
2.2 Disable *improvedft-Disable*
-----------
If for any reason, you want to disable the plugin, use >
:DisableImprovedFT
<
2.3 Tips *improvedft-Tips*
--------
*improvedft-YankRing*
2.3.1 YankRing and the improved ft plugin
------------------------------------------
Both plugins map the ',', ';', 'f', 'F', 't' and 'T' key, so they don't work
together very well. The improved ft plugin tries to work around that by
setting a YankRing option that prevents mapping those keys and reloading the
YankRing plugin.
The following YankRing variables are set by the improved ft plugin: >
let g:yankring_zap_keys = "/ ?"
let g:yankring_o_keys = 'b B w W e E d h j k l H M L y G ^ 0 $'
let g:yankring_o_keys .= ' g_ g^ gm g$ gk gj gg ge gE - + _ '
let g:yankring_o_keys .= ' iw iW aw aW as is ap ip a] a[ i] i['
let g:yankring_o_keys .= ' a) a( ab i) i( ib a> a< i> i< at it'
let g:yankring_o_keys .= ' a} a{ aB i} i{ iB a" a'' a` i" i'' i`'
<
If those variables have been customized in your .vimrc, the plugin detects it
and removes the ',', ';', 'f', 'F', 't' and 'T' from them.
The drawback of doing this is, that the YankRing possibly doesn't immediately
catch up in the YankRing itself and possibly will not be caught at all.
*improvedft-ignorecase*
2.3.2 Ignoring case when searching
----------------------------------
ft_improved tries to mimic the existing behaviour of the |f| |F| |t| |T| |,| |;|
commands as closely as possible. However, you might wish to search for the
character while ignoring case, so that fT will also jump to either the next
't' or 'T' character, whichever appears first.
To enable this, simply set this variable in your |.vimrc| >
:let g:ft_improved_ignorecase = 1
<
To disable either |unlet| that variable, or set it to zero.
*improvedft-multichars*
2.3.3 Searching for more characters
-----------------------------------
ft_improved tries to mimic the existing behaviour of the |f| |F| |t| |T| |,| |;|
commands as closely as possible. However, you might wish to search for more
character to better find your position and not only allow one single char with
it.
To enable this, simply set this variable in your |.vimrc| >
:let g:ft_improved_multichars = 1
<
As you type, the matching positions will be highlighted.
(Set g:ft_improved_nohighlight = 1 if you don't want the highlighting).
To disable either |unlet| that variable, or set it to zero.
If you have enabled it this way, you need to press enter, after having entered
the characters to search for, so that the plugin knows, when not to wait for more
characters and to start searching. Alternatively, if the entered characters
precisely only match one position in the current screen (excluding folds), it
will simply drop you there.
Note: This is highly experimental and basically turns your |f| |F| |t| |T| |,|
|;| keys to use a literal search function.
*improvedft-consistent_comma*
2.3.4 Consistent ,/; keys
-------------------------
By default, the |,| will always search into the opposite direction of your
last |f|/|F|/|t|/|T| command, while the ';' will always search in the same
direciton.
If you rather like to have that the |;| will always search forward and the |,|
always backwards you can set the variable g:ft_improved_consistent_comma
variable like this in your |.vimrc| >
:let g:ft_improved_consistent_comma = 1
2.4 Mapping *improvedft-Mapping*
-----------
By default the keys |f| |F| |t| |T| |;| and |,| are mapped to a function that
performs the work. If for one reason, you do not want any of those keys to be
remapped, simply set the variable g:ft_improved_nomap_<key> to one where <key>
corresponds to any of the above keys (but use "comma" for "," and semicolon
for ";"). Say you do not want to have the ',' remapped, you would in your
|.vimrc| set: >
:let g:ft_improved_nomap_comma = 1
2.5 Bugs *improvedft-Bugs*
--------
- When using T as operator and the match is the last character of a previous
line, the motion will become inclusive and you will incorrectly also change
that character. (also when ',' or ';' are searching backwards) That seems to
be a bug within Vim. See also |exclusive|
==============================================================================
3. Feedback *improvedft-feedback*
Feedback is always welcome. If you like the plugin, please rate it at the
vim-page:
http://www.vim.org/scripts/script.php?script_id=3877
You can also follow the development of the plugin at github:
http://github.com/chrisbra/improvedft
Please don't hesitate to report any bugs to the maintainer, mentioned in the
third line of this document.
==============================================================================
4. History *improvedft-history*
0.10: (unreleased) "{{{
- Make |,| and |;| work as documented (reported by JonnyRa in
https://github.com/chrisbra/improvedft/issues/5, thanks!)
0.9: Jan 15, 2015 "{{{
- do not mess up highlighting for |;| and |,| commands
- make count work correctly with multi-highlight match, so that only the
count'th occurence gets highlighted.
- allow to disable mappings selectively |improvedft-Mapping|
(issue https://github.com/chrisbra/improvedft/issues/4 reported by Maiko
Cezar, thanks!)
- make the plugin not unneccessarily source the autoload script
- document |improvedft-consistent_comma|
0.8: Mar 27, 2014 "{{{1
- handle keys like <Enter>, <Tab> literally
- escape '/' correctly for |t| commands.
0.7: Aug 14, 2013 "{{{1
- small bugfixes
- correctly handle ignorecase setting |improvedft-ignorecase|
- escape '
- make ; work correctly when using backwards motion.
0.6: Mar 16, 2013 "{{{1
- |improvedft-multichars|
- save and restore search-history in all modes correctly
0.5: Feb 16, 2013 "{{{1
- ignorecase when searching, when g:ft_improved_ignorecase is set
0.4: Sep 09, 2012 "{{{1
- special handling of pattern / and ?
0.3: Aug 20, 2012 "{{{1
- fix issue https://github.com/chrisbra/improvedft/issues/1
by disallowing the Yankring to map the keys f F t and T
- Better mapping of ';' key (patch by Marcin Szamotulski, thanks!)
0.2: Jan 13, 2012 {{{1
- disable debug mode
- enable |GLVS|
0.1: Jan 12, 2012 {{{1
- Initial upload
- development versions are available at the github repository
- put plugin on a public repository (http://github.com/chrisbra/improvedft)
}}}
==============================================================================
Modeline:
vim:tw=78:ts=8:ft=help:et:fdm=marker:fdl=0:norl