From 983abefc30facb1b30d6bed1ee91b71e5602042d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 24 Dec 2013 16:48:52 +0000 Subject: [PATCH] Add alt-| for piping and appending rather than replacing --- README.asciidoc | 4 +++- src/normal.cc | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index c08a7c74..be717d15 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -159,7 +159,9 @@ Changes indent (3 leading spaces when indent is 4) * _|_: pipe each selections through the given external filter program - and replace with it's output. + and replace the selection with it's output. + * _alt-|_: pipe each selections through the given external filter program + and append the selection with it's output. * _u_: undo last change * _U_: redo last change diff --git a/src/normal.cc b/src/normal.cc index d042d9fa..4922b70f 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -418,6 +418,7 @@ void command(Context& context, int) }); } +template void pipe(Context& context, int) { auto completer = [](const Context& context, CompletionFlags flags, @@ -450,7 +451,8 @@ void pipe(Context& context, int) return completions; }; - context.input_handler().prompt("pipe:", get_color("Prompt"), completer, + const char* prompt = mode == InsertMode::Replace ? "pipe:" : "pipe (ins):"; + context.input_handler().prompt(prompt, get_color("Prompt"), completer, [](const String& cmdline, PromptEvent event, Context& context) { if (event != PromptEvent::Validate) @@ -484,7 +486,7 @@ void pipe(Context& context, int) strings.push_back(str); } ScopedEdition edition(context); - insert(buffer, selections, strings); + insert(buffer, selections, strings); }); } @@ -1280,7 +1282,8 @@ KeyMap keymap = { '%', [](Context& context, int) { select_whole_buffer(context.buffer(), context.selections()); } }, { ':', command }, - { '|', pipe }, + { '|', pipe }, + { alt('|'), pipe }, { ' ', [](Context& context, int count) { if (count == 0) clear_selections(context.buffer(), context.selections()); else keep_selection(context.selections(), count-1); } }, { alt(' '), [](Context& context, int count) { if (count == 0) flip_selections(context.selections());