@@ -302,6 +302,7 @@ impl Command {
302302 format_selections, "Format selection",
303303 join_selections, "Join lines inside selection",
304304 keep_selections, "Keep selections matching regex",
305+ remove_selections, "Remove selections matching regex",
305306 keep_primary_selection, "Keep primary selection",
306307 remove_primary_selection, "Remove primary selection",
307308 completion, "Invoke completion popup",
@@ -4320,12 +4321,12 @@ fn join_selections(cx: &mut Context) {
43204321 doc.append_changes_to_history(view.id);
43214322}
43224323
4323−fn keep_selections(cx: &mut Context) {
4324− // keep selections matching regex
4324+fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
4325+ // keep or remove selections matching regex
43254326 let reg = cx.register.unwrap_or('/');
43264327 let prompt = ui::regex_prompt(
43274328 cx,
4328− "keep:".into(),
4329+ if !remove { "keep:" } else { "remove:" }.into(),
43294330 Some(reg),
43304331 |_input: &str| Vec::new(),
43314332 move |view, doc, regex, event| {
@@ -4334,7 +4335,9 @@ fn keep_selections(cx: &mut Context) {
43344335 }
43354336 let text = doc.text().slice(..);
43364337
4337− if let Some(selection) = selection::keep_matches(text, doc.selection(view.id), ®ex) {
4338+ if let Some(selection) =
4339+ selection::keep_or_remove_matches(text, doc.selection(view.id), ®ex, remove)
4340+ {
43384341 doc.set_selection(view.id, selection);
43394342 }
43404343 },
@@ -4343,6 +4346,14 @@ fn keep_selections(cx: &mut Context) {
43434346 cx.push_layer(Box::new(prompt));
43444347}
43454348
4349+fn keep_selections(cx: &mut Context) {
4350+ keep_or_remove_selections_impl(cx, false)
4351+}
4352+
4353+fn remove_selections(cx: &mut Context) {
4354+ keep_or_remove_selections_impl(cx, true)
4355+}
4356+
43464357fn keep_primary_selection(cx: &mut Context) {
43474358 let (view, doc) = current!(cx.editor);
43484359 // TODO: handle count