@@ -302,6 +302,7 @@ impl Command {
302 format_selections, "Format selection",
302 format_selections, "Format selection",
303 join_selections, "Join lines inside selection",
303 join_selections, "Join lines inside selection",
304 keep_selections, "Keep selections matching regex",
304 keep_selections, "Keep selections matching regex",
305+ remove_selections, "Remove selections matching regex",
305 keep_primary_selection, "Keep primary selection",
306 keep_primary_selection, "Keep primary selection",
306 remove_primary_selection, "Remove primary selection",
307 remove_primary_selection, "Remove primary selection",
307 completion, "Invoke completion popup",
308 completion, "Invoke completion popup",
@@ -4320,12 +4321,12 @@ fn join_selections(cx: &mut Context) {
4320 doc.append_changes_to_history(view.id);
4321 doc.append_changes_to_history(view.id);
4323−fn keep_selections(cx: &mut Context) {
4324+fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
4324− // keep selections matching regex
4325+ // keep or remove selections matching regex
4325 let reg = cx.register.unwrap_or('/');
4326 let reg = cx.register.unwrap_or('/');
4326 let prompt = ui::regex_prompt(
4327 let prompt = ui::regex_prompt(
4328− "keep:".into(),
4329+ if !remove { "keep:" } else { "remove:" }.into(),
4329 Some(reg),
4330 Some(reg),
4330 |_input: &str| Vec::new(),
4331 |_input: &str| Vec::new(),
4331 move |view, doc, regex, event| {
4332 move |view, doc, regex, event| {
@@ -4334,7 +4335,9 @@ fn keep_selections(cx: &mut Context) {
4335 let text = doc.text().slice(..);
4336 let text = doc.text().slice(..);
4338+ if let Some(selection) =
4337− if let Some(selection) = selection::keep_matches(text, doc.selection(view.id), ®ex) {
4339+ selection::keep_or_remove_matches(text, doc.selection(view.id), ®ex, remove)
4338 doc.set_selection(view.id, selection);
4341 doc.set_selection(view.id, selection);
@@ -4343,6 +4346,14 @@ fn keep_selections(cx: &mut Context) {
4343 cx.push_layer(Box::new(prompt));
4346 cx.push_layer(Box::new(prompt));
4349+fn keep_selections(cx: &mut Context) {
4350+ keep_or_remove_selections_impl(cx, false)
4353+fn remove_selections(cx: &mut Context) {
4354+ keep_or_remove_selections_impl(cx, true)
4346fn keep_primary_selection(cx: &mut Context) {
4357fn keep_primary_selection(cx: &mut Context) {
4347 let (view, doc) = current!(cx.editor);
4358 let (view, doc) = current!(cx.editor);
4348 // TODO: handle count
4359 // TODO: handle count