aboutsummaryrefslogtreecommitdiffstats
path: root/vim-mode/README.pod
blob: dd3b61a692b3743b93db9216e22f978946c1e7bc (plain) (blame)
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
=pod

=head1 NAME

vim_mode.pl

=head1 DESCRIPTION

An Irssi script to emulate some of the vi(m) features for the Irssi inputline.

=head1 INSTALLATION

Copy into your F<~/.irssi/scripts/> directory and load with
C</SCRIPT LOAD vim_mode.pl>. You may wish to have it autoload in one of the
L<usual ways|https://github.com/shabble/irssi-docs/wiki/Guide#Autorunning_Scripts>.

=head2 DEPENDENCIES

For proper :ex mode support, vim-mode requires the installation of F<uberprompt.pl>
Uberprompt can be downloaded from:

L<https://github.com/shabble/irssi-scripts/raw/master/prompt_info/uberprompt.pl>

and follow the instructions at the top of that file for installation.

If you don't need Ex-mode, you can run vim_mode.pl without the
uberprompt.pl script, but it is strongly recommended that you use it.

=head3 Irssi requirements

0.8.12 and above should work fine. However the following features are
disabled in irssi < 0.8.13:

=over 4

=item * C<j> C<k> (only with count, they work fine without count in older versions)

=item * C<gg>, C<G>

=back

It is intended to work with at Irssi  0.8.12 and later versions. However some
features are disabled in older versions (see below for details).

Perl >= 5.8.1 is recommended for UTF-8 support (which can be disabled if
necessary).  Please report bugs in older versions as well, we'll try to fix
them.  Later versions of Perl are also faster, which is probably beneficial
to a script of this size and complexity.

=head2 SETUP

Vim Mode provides certain feedback to the user, such as the currently active
mode (command, insert, ex), and if switching buffers, which buffer(s) currently
match the search terms.

There are two ways to go about displaying this information, as described in
the following sections:

=head3 Statusbar Items

Run the following command to add a statusbar item that shows which mode
you're in.

C</statusbar window add vim_mode>

And the following to let C<:b [str]> display a list of channels matching your
search string.

C</statusbar window add vim_windows>

B<Note:> Remember to C</save> after adding these statusbar items to make them
permanent.

B<Note:> If you would rather have these statusbar items on your prompt
line rather than thte window statusbar, please follow these steps.

For technical reasons, I<uberprompt> must occasionally call C</statusbar prompt
reset>, which will remove or deactivate any manually added items on the prompt
statusbar.  To get around this, uberprompt provides two command hooks,
C<uberprompt_load_hook> and C<uberprompt_unload_hook>.  Both of these settings
can contain one (or more, using C</EVAL> commands to be executed when the prompt
is enabled and disabled, respectively.

For I<right-aligned> items (that is, after the input field:

=over 4

=item 1 C</alias vm_add /^statusbar prompt add -after input -alignment right vim_mode>

=item 2 C</alias vm_del /^statusbar prompt remove vim_mode>

=item 3 C</set uberprompt_load_hook /^vm_add>

=item 4 C</set uberprompt_unload_hook /^vm_del>

=back

For I<left-aligned> items (before the prompt):


=over 4

=item 1 C</alias vm_add /^statusbar prompt add -before prompt -alignment left vim_mode>

=item 2 C</alias vm_del /^statusbar prompt remove vim_mode>

=item 3 C</set uberprompt_load_hook /^vm_add>

=item 4 C</set uberprompt_unload_hook /^vm_del>

=back

If you wish to add both C<vim_mode> and C<vim_windows> items, replace steps 1 and 2
with the following:

=over 4

=item 1 C</alias vm_add /^eval /^statusbar prompt add -after input -alightment right vim_mode ; /^statusbar prompt add -after input -alignment right vim_windows>

=item 2 C</alias vm_del /^eval /^statusbar prompt remove vim_mode ; /^statusbar prompt remove vim_windows>

=back

and then complete stages 3 and 4 as above.  Replace the C<-after> and C<-alignment>
to suit your location preferences.

B<Note:> It is also possible to place the items between the prompt and input field,
by specifying C<-after prompt> or C<-before input> as appropriate.

=head3 Expando Variables

Vim mode augments the existing Irssi expando (automatic variables) with two
additional ones: C<$vim_cmd_mode> and C<$vim_wins>.

C<$vim_cmd_mode> is the equivalent of the C<vim_mode> statusbar item, and
C<$vim_wins> is the counterpart of C<vim_windows>.

They can be added to your theme, or inserted into your uberprompt using
the

"C</set uberprompt_format [$vim_cmd_mode] $*$uber] >" command.


=head3 FILE-BASED CONFIGURATION

Additionally to the irssi settings described in L<settings|/SETTINGS>, vim_mode
can be configured through an external configuration file named "vim_moderc"
located in F<~/.irssi/vim_moderc>. If available it's loaded on startup and every
supported ex-command is run. Its syntax is similar to "vimrc". To (re)load it
while vim_mode is running use C<:so[urce]>.

Currently Supported ex-commands:

=over 4

=item * C<:map>

=back

=head1 USAGE

The following section is divided into the different modes as supported by Vim itself:

=head2 COMMAND MODE

It supports most commonly used command mode features:

=over 2

=item * Insert/Command mode.

C<Esc> and C<Ctrl-C> enter command mode.  C</set vim_mode_cmd_seq j> allows
to use C<jj> as Escape (any other character can be used as well).

=item * Cursor motion:

C<h l 0 ^ $ E<lt>SpaceE<gt> E<lt>BSE<gt> f t F T>

=item * History motion:

C<j k gg G> C<gg> moves to the oldest (first) history line.  C<G> without a
count moves to the current input line, with a count it goes to the I<count-th>
history line (1 is the oldest).

=item * Cursor word motion:

C<w b ge e W gE B E>

=item * Word objects (only the following work yet):

C<aw aW>

=item * Yank and paste:

 C<y p P>

=item * Change and delete:

C<c d>

=item * Delete at cursor:

C<x X>

=item * Replace at cursor:

C<r>

=item * Insert mode:

C<i a I A>

=item * Switch case:

C<~>

=item * Repeat change:

C<.>

=item * Repeat

C<ftFT: ; ,>

=item * Registers:

C<"a-"z "" "0 "* "+ "_> (black hole)

=item * Line-wise shortcuts:

C<dd cc yy>

=item * Shortcuts:

C<s S C D>

=item * Scroll the scrollback buffer:

C<Ctrl-E Ctrl-D Ctrl-Y Ctrl-U Ctrl-F Ctrl-B>

=item * Switch to last active window:

C<Ctrl-6/Ctrl-^>

=item * Switch split windows:

<Ctrl-W j Ctrl-W k>

=item * Undo/Redo:

C<u Ctrl-R>

=back

Counts and combinations work as well, e.g. C<d5fx> or C<3iabcE<lt>escE<gt>>. Counts also work with mapped ex-commands (see below), e.g. if you map C<gb> to do C<:bn>, then C<2gb> will switch to the second next buffer.  Repeat also supports counts.

=head3 REGISTERS

=over 4

=item * Appending to register with C<"A-"Z>

=item * C<""> is the default yank/delete register.

=item * C<"0> contains the last yank (if no register was specified).

=item * The special registers C<"* "+> both contain irssi's internal cut-buffer.

=back

=head2 INSERT MODE

The following insert mode mappings are supported:

=over 4

=item * Insert register content: Ctrl-R x (where x is the register to insert)

=back

=head2 EX-MODE

Ex-mode (activated by C<:> in command mode) supports the following commands:

=over 4

=item * Command History:

C<E<lt>uparrowE<gt>> - cycle backwards through history

C<E<lt>downarrowE<gt>> - cycle forwards through history

C<:eh> - show ex history

=item * Switching buffers:

C<:[N]b [N]> - switch to channel number

C<:b#>       - switch to last channel

C<:b> E<lt>partial-channel-nameE<gt>

C<:b> <partial-server>/<partial-channel>

C<:buffer {args}> (same as C<:b>)

C<:[N]bn[ext] [N]> - switch to next window

C<:[N]bp[rev] [N]> - switch to previous window

=item * Close window:

C<:[N]bd[elete] [N]>

=item * Display windows:

C<:ls>, C<:buffers>

=item * Display registers:

C<:reg[isters] {args}>, C<:di[splay] {args}>

=item * Display undolist:

C<:undol[ist]> (mostly used for debugging)

=item * Source files:

C<:so[urce]> - only sources vim_moderc at the moment,
                         F<{file}> not supported

=item * Mappings:

C<:map> - display custom mappings

=item * Saving mappings:

C<:mkv[imrc][!]> - like in Vim, but [file] not supported

=item * Substitution:

C<:s///> - I<i> and I<g> are supported as flags, only C<///> can be used as
eparator, and it uses Perl regex syntax instead of Vim syntax.

=item * Settings:

C<:se[t]> - display all options

C<:se[t] {option}>         - display all matching options

C<:se[t] {option} {value}> - change option to value

=back

=head3 MAPPINGS

=head4 Commands

=over 4

=item * C<:map {lhs}>       - display mappings starting with {lhs}

=item * C<:map {lhs} {rhs}> - add mapping

=item * C<:unm[ap] {lhs}>   - remove custom mapping

=back

=head4 Parameters

I<{lhs}> is the key combination to be mapped, I<{rhs}> the target. The
C<E<lt>E<gt>> notation is used

(e.g. C<E<lt>C-FE<gt>> is I<Ctrl-F>), case is ignored.
 Supported C<E<lt>E<gt>> keys are:

=over 4

=item * C<E<lt>C-AE<gt>> - C<E<lt>C-ZE<gt>>,

=item * C<E<lt>C-^E<gt>>, C<E<lt>C-6E<gt>>

=item * C<E<lt>SpaceE<gt>>

=item * C<E<lt>CRE<gt>> - Enter

=item * C<E<lt>BSE<gt>> - Backspace

=item * C<E<lt>NopE<gt>> - No-op (Do Nothing).

=back

Mapping ex-mode and irssi commands is supported. When mapping ex-mode commands
the trailing C<E<lt>CrE<gt>> is not necessary. Only default mappings can be used
in I<{rhs}>.

Examples:

=over 4

=item * C<:map w  W>      - to remap w to work like W

=item * C<:map gb :bnext> - to map gb to call :bnext

=item * C<:map gB :bprev>

=item * C<:map g1 :b 1>   - to map g1 to switch to buffer 1

=item * C<:map gb :b>     - to map gb to :b, 1gb switches to buffer 1, 5gb to 5

=item * C<:map E<lt>C-LE<gt> /clear> - map Ctrl-L to irssi command /clear

=item * C<:map E<lt>C-GE<gt> /window goto 1>

=item * C<:map E<lt>C-EE<gt> <Nop>> - disable E<lt>C-EE<gt>, it does nothing now

=item * C<:unmap E<lt>C-EE<gt>> - restore default behavior of C<E<lt>C-EE<gt>>
after disabling it

=back

Note that you must use C</> for irssi commands (like C</clear>), the current value
of Irssi's cmdchars does B<not> work! This is necessary do differentiate between
ex-commands and irssi commands.

=head2 SETTINGS

The settings are stored as irssi settings and can be set using C</set> as usual
(prepend C<vim_mode_> to setting name) or using the C<:set> ex-command. The
following settings are available:

=over 4

=item * utf8 - Support UTF-8 characters, boolean, default on

=item * debug - Enable debug output, boolean, default off

=item * cmd_seq - Char that when double-pressed simulates C<E<lt>EscE<gt>>, string, default '' (disabled)

=item * start_cmd - Start every line in command mode, boolean, default off

=item * max_undo_lines - Sze of the undo buffer. Integer, default 50 items.

=item * ex_history_size - Number of items stored in the ex-mode history. Integer, default 100.

=item * prompt_leading_space - Ddetermines whether ex mode prepends a space to the displayed input. Boolean, default on

=back

In contrast to irssi's settings, C<:set> accepts 0 and 1 as values for boolean
settings, but only vim_mode's settings can be set/displayed.

Examples:

   :set cmd_seq=j   # set cmd_seq to j
   :set cmd_seq=    # disable cmd_seq
   :set debug=on    # enable debug
   :set debug=off   # disable debug

=head1 SUPPORT

Any behavior different from Vim (unless explicitly documented) should be
considered a bug and reported.

B<NOTE:> This script is still under heavy development, and there may be bugs.
Please submit reproducible sequences to the bug-tracker at:
L<http://github.com/shabble/irssi-scripts/issues/new>

or contact rudi_s or shabble on irc.freenode.net (#irssi and #irssi_vim)

=head1 AUTHORS

Copyright E<copy> 2010-2011 Tom Feist C<E<lt>shabble+irssi@metavore.orgE<gt>> and

Copyright E<copy> 2010-2011 Simon Ruderich C<E<lt>simon@ruderich.orgE<gt>>

=head1 THANKS

Particular thanks go to

=over 4

=item * estragib: a lot of testing and many bug reports and feature requests

=item * iaj: testing

=item * tmr: explaining how various bits of vim work

=back

as well as the rest of C<#irssi> and C<#irssi_vim> on Freenode IRC.

=head1 LICENCE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

=head1 BUGS

=over 4

=item *

count before register doesn't work: e.g. 3"ap doesn't work, but "a3p does

=item *

mapping an incomplete ex-command doesn't open the ex-mode with the partial
command (e.g. C<:map gb :b> causes an error instead of opening the ex-mode and
displaying C<:bE<lt>cursorE<gt>>)

=item *

 undo/redo cursor positions are mostly wrong

=back

=head1 TODO

=over 4

=item *

History:

=over 4

=item *

 C< * /,?,n,N> to search through history (like rl_history_search.pl)

=back

=item *

Window switching (C<:b>)

=over 4

=item *

Tab completion of window(-item) names

=item *

non-sequential matches(?)

=back

=back

See also the TODO file at
L<github|https://github.com/shabble/irssi-scripts/blob/master/vim-mode/TODO> for
many many more things.

=head2 WONTFIX

Things we're not ever likely to do:

=over 4

=item * Macros

=back



=cut