diff options
Diffstat (limited to 'vim-mode')
-rw-r--r-- | vim-mode/vim_mode.pl | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 3a2bdec..f18fb09 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -73,6 +73,7 @@ # {file} not supported # * Mappings: :map - display custom mappings # :map {lhs} {rhs} - add mapping +# * Save mappings: :mkv[imrc] - like in Vim, but [file] not supported # * Substitute: :s/// - i and g are supported as flags, only /// can be # used as separator, uses Perl regex instead of # Vim regex @@ -383,6 +384,8 @@ my $commands_ex map => { char => ':map', func => \&ex_map, type => C_EX }, source => { char => ':source', func => \&ex_source, type => C_EX }, so => { char => ':so', func => \&ex_source, type => C_EX }, + mkvimrc => { char => ':mkvimrc', func => \&ex_mkvimrc, type => C_EX }, + mkv => { char => ':mkv', func => \&ex_mkvimrc, type => C_EX }, }; # MAPPINGS @@ -1700,6 +1703,29 @@ sub ex_source { } } +sub ex_mkvimrc { + # :mkv[imrc], [file] not supported + + my $vim_moderc = Irssi::get_irssi_dir(). '/vim_moderc'; + if (-f $vim_moderc) { + return _warn_ex('mkvimrc', "$vim_moderc already exists"); + } + + open my $file, '>', $vim_moderc or return; + + # copied from ex_map() + foreach my $key (sort keys %$maps) { + my $map = $maps->{$key}; + my $cmd = $map->{cmd}; + if (defined $cmd) { + next if $map->{char} eq $cmd->{char}; # skip default mappings + print $file "$map->{char} $cmd->{char}\n"; + } + } + + close $file; +} + sub _warn_ex { my ($command, $description) = @_; my $message = "Error in ex-mode command $command"; |