1
- *if_tcl.txt* For Vim version 9.1. Last change: 2022 Jan 08
1
+ *if_tcl.txt* For Vim version 9.1. Last change: 2024 Oct 05
2
2
3
3
4
4
VIM REFERENCE MANUAL by Ingo Wilken
@@ -461,14 +461,14 @@ Input from stdin is currently not supported.
461
461
Here are a few small (and maybe useful) Tcl scripts.
462
462
463
463
This script sorts the lines of the entire buffer (assume it contains a list
464
- of names or something similar):
464
+ of names or something similar): >
465
465
set buf $::vim::current(buffer)
466
466
set lines [$buf get top bottom]
467
467
set lines [lsort -dictionary $lines]
468
468
$buf set top bottom $lines
469
469
470
470
This script reverses the lines in the buffer. Note the use of "::vim::lbase"
471
- and "$buf last" to work with any line number setting.
471
+ and "$buf last" to work with any line number setting: >
472
472
set buf $::vim::current(buffer)
473
473
set t $::vim::lbase
474
474
set b [$buf last]
@@ -481,7 +481,7 @@ and "$buf last" to work with any line number setting.
481
481
incr b -1
482
482
}
483
483
484
- This script adds a consecutive number to each line in the current range:
484
+ This script adds a consecutive number to each line in the current range: >
485
485
set buf $::vim::current(buffer)
486
486
set i $::vim::range(start)
487
487
set n 1
@@ -491,25 +491,25 @@ This script adds a consecutive number to each line in the current range:
491
491
incr i ; incr n
492
492
}
493
493
494
- The same can also be done quickly with two Ex commands, using ":tcldo":
494
+ The same can also be done quickly with two Ex commands, using ":tcldo": >
495
495
:tcl set n 1
496
496
:[range]tcldo set line "$n\t$line" ; incr n
497
497
498
- This procedure runs an Ex command on each buffer (idea stolen from Ron Aaron):
498
+ This procedure runs an Ex command on each buffer (idea stolen from Ron Aaron): >
499
499
proc eachbuf { cmd } {
500
500
foreach b [::vim::buffer list] {
501
501
$b command $cmd
502
502
}
503
503
}
504
- Use it like this:
504
+ Use it like this: >
505
505
:tcl eachbuf %s/foo/bar/g
506
506
Be careful with Tcl's string and backslash substitution, tough. If in doubt,
507
507
surround the Ex command with curly braces.
508
508
509
509
510
510
If you want to add some Tcl procedures permanently to vim, just place them in
511
511
a file (e.g. "~/.vimrc.tcl" on Unix machines), and add these lines to your
512
- startup file (usually "~/.vimrc" on Unix):
512
+ startup file (usually "~/.vimrc" on Unix): >
513
513
if has("tcl")
514
514
tclfile ~/.vimrc.tcl
515
515
endif
0 commit comments