paste.rs

  1use std::cmp;
  2
  3use editor::{display_map::ToDisplayPoint, movement, scroll::Autoscroll, DisplayPoint, RowExt};
  4use gpui::{impl_actions, ViewContext};
  5use language::{Bias, SelectionGoal};
  6use serde::Deserialize;
  7use workspace::Workspace;
  8
  9use crate::{
 10    normal::yank::copy_selections_content,
 11    state::{Mode, Register},
 12    Vim,
 13};
 14
 15#[derive(Clone, Deserialize, PartialEq)]
 16#[serde(rename_all = "camelCase")]
 17struct Paste {
 18    #[serde(default)]
 19    before: bool,
 20    #[serde(default)]
 21    preserve_clipboard: bool,
 22}
 23
 24impl_actions!(vim, [Paste]);
 25
 26pub(crate) fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
 27    workspace.register_action(paste);
 28}
 29
 30fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {
 31    Vim::update(cx, |vim, cx| {
 32        vim.record_current_action(cx);
 33        vim.store_visual_marks(cx);
 34        let count = vim.take_count(cx).unwrap_or(1);
 35
 36        vim.update_active_editor(cx, |vim, editor, cx| {
 37            let text_layout_details = editor.text_layout_details(cx);
 38            editor.transact(cx, |editor, cx| {
 39                editor.set_clip_at_line_ends(false, cx);
 40
 41                let selected_register = vim.update_state(|state| state.selected_register.take());
 42
 43                let Some(Register {
 44                    text,
 45                    clipboard_selections,
 46                }) = vim
 47                    .read_register(selected_register, Some(editor), cx)
 48                    .filter(|reg| !reg.text.is_empty())
 49                else {
 50                    return;
 51                };
 52                let clipboard_selections = clipboard_selections
 53                    .filter(|sel| sel.len() > 1 && vim.state().mode != Mode::VisualLine);
 54
 55                if !action.preserve_clipboard && vim.state().mode.is_visual() {
 56                    copy_selections_content(vim, editor, vim.state().mode == Mode::VisualLine, cx);
 57                }
 58
 59                let (display_map, current_selections) = editor.selections.all_adjusted_display(cx);
 60
 61                // unlike zed, if you have a multi-cursor selection from vim block mode,
 62                // pasting it will paste it on subsequent lines, even if you don't yet
 63                // have a cursor there.
 64                let mut selections_to_process = Vec::new();
 65                let mut i = 0;
 66                while i < current_selections.len() {
 67                    selections_to_process
 68                        .push((current_selections[i].start..current_selections[i].end, true));
 69                    i += 1;
 70                }
 71                if let Some(clipboard_selections) = clipboard_selections.as_ref() {
 72                    let left = current_selections
 73                        .iter()
 74                        .map(|selection| cmp::min(selection.start.column(), selection.end.column()))
 75                        .min()
 76                        .unwrap();
 77                    let mut row = current_selections.last().unwrap().end.row().next_row();
 78                    while i < clipboard_selections.len() {
 79                        let cursor =
 80                            display_map.clip_point(DisplayPoint::new(row, left), Bias::Left);
 81                        selections_to_process.push((cursor..cursor, false));
 82                        i += 1;
 83                        row.0 += 1;
 84                    }
 85                }
 86
 87                let first_selection_indent_column =
 88                    clipboard_selections.as_ref().and_then(|zed_selections| {
 89                        zed_selections
 90                            .first()
 91                            .map(|selection| selection.first_line_indent)
 92                    });
 93                let before = action.before || vim.state().mode == Mode::VisualLine;
 94
 95                let mut edits = Vec::new();
 96                let mut new_selections = Vec::new();
 97                let mut original_indent_columns = Vec::new();
 98                let mut start_offset = 0;
 99
100                for (ix, (selection, preserve)) in selections_to_process.iter().enumerate() {
101                    let (mut to_insert, original_indent_column) =
102                        if let Some(clipboard_selections) = &clipboard_selections {
103                            if let Some(clipboard_selection) = clipboard_selections.get(ix) {
104                                let end_offset = start_offset + clipboard_selection.len;
105                                let text = text[start_offset..end_offset].to_string();
106                                start_offset = end_offset + 1;
107                                (text, Some(clipboard_selection.first_line_indent))
108                            } else {
109                                ("".to_string(), first_selection_indent_column)
110                            }
111                        } else {
112                            (text.to_string(), first_selection_indent_column)
113                        };
114                    let line_mode = to_insert.ends_with('\n');
115                    let is_multiline = to_insert.contains('\n');
116
117                    if line_mode && !before {
118                        if selection.is_empty() {
119                            to_insert =
120                                "\n".to_owned() + &to_insert[..to_insert.len() - "\n".len()];
121                        } else {
122                            to_insert = "\n".to_owned() + &to_insert;
123                        }
124                    } else if !line_mode && vim.state().mode == Mode::VisualLine {
125                        to_insert = to_insert + "\n";
126                    }
127
128                    let display_range = if !selection.is_empty() {
129                        selection.start..selection.end
130                    } else if line_mode {
131                        let point = if before {
132                            movement::line_beginning(&display_map, selection.start, false)
133                        } else {
134                            movement::line_end(&display_map, selection.start, false)
135                        };
136                        point..point
137                    } else {
138                        let point = if before {
139                            selection.start
140                        } else {
141                            movement::saturating_right(&display_map, selection.start)
142                        };
143                        point..point
144                    };
145
146                    let point_range = display_range.start.to_point(&display_map)
147                        ..display_range.end.to_point(&display_map);
148                    let anchor = if is_multiline || vim.state().mode == Mode::VisualLine {
149                        display_map.buffer_snapshot.anchor_before(point_range.start)
150                    } else {
151                        display_map.buffer_snapshot.anchor_after(point_range.end)
152                    };
153
154                    if *preserve {
155                        new_selections.push((anchor, line_mode, is_multiline));
156                    }
157                    edits.push((point_range, to_insert.repeat(count)));
158                    original_indent_columns.extend(original_indent_column);
159                }
160
161                editor.edit_with_block_indent(edits, original_indent_columns, cx);
162
163                // in line_mode vim will insert the new text on the next (or previous if before) line
164                // and put the cursor on the first non-blank character of the first inserted line (or at the end if the first line is blank).
165                // otherwise vim will insert the next text at (or before) the current cursor position,
166                // the cursor will go to the last (or first, if is_multiline) inserted character.
167                editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
168                    s.replace_cursors_with(|map| {
169                        let mut cursors = Vec::new();
170                        for (anchor, line_mode, is_multiline) in &new_selections {
171                            let mut cursor = anchor.to_display_point(map);
172                            if *line_mode {
173                                if !before {
174                                    cursor = movement::down(
175                                        map,
176                                        cursor,
177                                        SelectionGoal::None,
178                                        false,
179                                        &text_layout_details,
180                                    )
181                                    .0;
182                                }
183                                cursor = movement::indented_line_beginning(map, cursor, true);
184                            } else if !is_multiline {
185                                cursor = movement::saturating_left(map, cursor)
186                            }
187                            cursors.push(cursor);
188                            if vim.state().mode == Mode::VisualBlock {
189                                break;
190                            }
191                        }
192
193                        cursors
194                    });
195                })
196            });
197        });
198        vim.switch_mode(Mode::Normal, true, cx);
199    });
200}
201
202#[cfg(test)]
203mod test {
204    use crate::{
205        state::Mode,
206        test::{NeovimBackedTestContext, VimTestContext},
207        UseSystemClipboard, VimSettings,
208    };
209    use gpui::ClipboardItem;
210    use indoc::indoc;
211    use settings::SettingsStore;
212
213    #[gpui::test]
214    async fn test_paste(cx: &mut gpui::TestAppContext) {
215        let mut cx = NeovimBackedTestContext::new(cx).await;
216
217        // single line
218        cx.set_shared_state(indoc! {"
219            The quick brown
220            fox ˇjumps over
221            the lazy dog"})
222            .await;
223        cx.simulate_shared_keystrokes("v w y").await;
224        cx.shared_clipboard().await.assert_eq("jumps o");
225        cx.set_shared_state(indoc! {"
226            The quick brown
227            fox jumps oveˇr
228            the lazy dog"})
229            .await;
230        cx.simulate_shared_keystrokes("p").await;
231        cx.shared_state().await.assert_eq(indoc! {"
232            The quick brown
233            fox jumps overjumps ˇo
234            the lazy dog"});
235
236        cx.set_shared_state(indoc! {"
237            The quick brown
238            fox jumps oveˇr
239            the lazy dog"})
240            .await;
241        cx.simulate_shared_keystrokes("shift-p").await;
242        cx.shared_state().await.assert_eq(indoc! {"
243            The quick brown
244            fox jumps ovejumps ˇor
245            the lazy dog"});
246
247        // line mode
248        cx.set_shared_state(indoc! {"
249            The quick brown
250            fox juˇmps over
251            the lazy dog"})
252            .await;
253        cx.simulate_shared_keystrokes("d d").await;
254        cx.shared_clipboard().await.assert_eq("fox jumps over\n");
255        cx.shared_state().await.assert_eq(indoc! {"
256            The quick brown
257            the laˇzy dog"});
258        cx.simulate_shared_keystrokes("p").await;
259        cx.shared_state().await.assert_eq(indoc! {"
260            The quick brown
261            the lazy dog
262            ˇfox jumps over"});
263        cx.simulate_shared_keystrokes("k shift-p").await;
264        cx.shared_state().await.assert_eq(indoc! {"
265            The quick brown
266            ˇfox jumps over
267            the lazy dog
268            fox jumps over"});
269
270        // multiline, cursor to first character of pasted text.
271        cx.set_shared_state(indoc! {"
272            The quick brown
273            fox jumps ˇover
274            the lazy dog"})
275            .await;
276        cx.simulate_shared_keystrokes("v j y").await;
277        cx.shared_clipboard().await.assert_eq("over\nthe lazy do");
278
279        cx.simulate_shared_keystrokes("p").await;
280        cx.shared_state().await.assert_eq(indoc! {"
281            The quick brown
282            fox jumps oˇover
283            the lazy dover
284            the lazy dog"});
285        cx.simulate_shared_keystrokes("u shift-p").await;
286        cx.shared_state().await.assert_eq(indoc! {"
287            The quick brown
288            fox jumps ˇover
289            the lazy doover
290            the lazy dog"});
291    }
292
293    #[gpui::test]
294    async fn test_yank_system_clipboard_never(cx: &mut gpui::TestAppContext) {
295        let mut cx = VimTestContext::new(cx, true).await;
296
297        cx.update_global(|store: &mut SettingsStore, cx| {
298            store.update_user_settings::<VimSettings>(cx, |s| {
299                s.use_system_clipboard = Some(UseSystemClipboard::Never)
300            });
301        });
302
303        cx.set_state(
304            indoc! {"
305                The quick brown
306                fox jˇumps over
307                the lazy dog"},
308            Mode::Normal,
309        );
310        cx.simulate_keystrokes("v i w y");
311        cx.assert_state(
312            indoc! {"
313                The quick brown
314                fox ˇjumps over
315                the lazy dog"},
316            Mode::Normal,
317        );
318        cx.simulate_keystrokes("p");
319        cx.assert_state(
320            indoc! {"
321                The quick brown
322                fox jjumpˇsumps over
323                the lazy dog"},
324            Mode::Normal,
325        );
326        assert_eq!(cx.read_from_clipboard(), None);
327    }
328
329    #[gpui::test]
330    async fn test_yank_system_clipboard_on_yank(cx: &mut gpui::TestAppContext) {
331        let mut cx = VimTestContext::new(cx, true).await;
332
333        cx.update_global(|store: &mut SettingsStore, cx| {
334            store.update_user_settings::<VimSettings>(cx, |s| {
335                s.use_system_clipboard = Some(UseSystemClipboard::OnYank)
336            });
337        });
338
339        // copy in visual mode
340        cx.set_state(
341            indoc! {"
342                The quick brown
343                fox jˇumps over
344                the lazy dog"},
345            Mode::Normal,
346        );
347        cx.simulate_keystrokes("v i w y");
348        cx.assert_state(
349            indoc! {"
350                The quick brown
351                fox ˇjumps over
352                the lazy dog"},
353            Mode::Normal,
354        );
355        cx.simulate_keystrokes("p");
356        cx.assert_state(
357            indoc! {"
358                The quick brown
359                fox jjumpˇsumps over
360                the lazy dog"},
361            Mode::Normal,
362        );
363        assert_eq!(
364            cx.read_from_clipboard().map(|item| item.text().clone()),
365            Some("jumps".into())
366        );
367        cx.simulate_keystrokes("d d p");
368        cx.assert_state(
369            indoc! {"
370                The quick brown
371                the lazy dog
372                ˇfox jjumpsumps over"},
373            Mode::Normal,
374        );
375        assert_eq!(
376            cx.read_from_clipboard().map(|item| item.text().clone()),
377            Some("jumps".into())
378        );
379        cx.write_to_clipboard(ClipboardItem::new("test-copy".to_string()));
380        cx.simulate_keystrokes("shift-p");
381        cx.assert_state(
382            indoc! {"
383                The quick brown
384                the lazy dog
385                test-copˇyfox jjumpsumps over"},
386            Mode::Normal,
387        );
388    }
389
390    #[gpui::test]
391    async fn test_paste_visual(cx: &mut gpui::TestAppContext) {
392        let mut cx = NeovimBackedTestContext::new(cx).await;
393
394        // copy in visual mode
395        cx.set_shared_state(indoc! {"
396                The quick brown
397                fox jˇumps over
398                the lazy dog"})
399            .await;
400        cx.simulate_shared_keystrokes("v i w y").await;
401        cx.shared_state().await.assert_eq(indoc! {"
402                The quick brown
403                fox ˇjumps over
404                the lazy dog"});
405        // paste in visual mode
406        cx.simulate_shared_keystrokes("w v i w p").await;
407        cx.shared_state().await.assert_eq(indoc! {"
408                The quick brown
409                fox jumps jumpˇs
410                the lazy dog"});
411        cx.shared_clipboard().await.assert_eq("over");
412        // paste in visual line mode
413        cx.simulate_shared_keystrokes("up shift-v shift-p").await;
414        cx.shared_state().await.assert_eq(indoc! {"
415            ˇover
416            fox jumps jumps
417            the lazy dog"});
418        cx.shared_clipboard().await.assert_eq("over");
419        // paste in visual block mode
420        cx.simulate_shared_keystrokes("ctrl-v down down p").await;
421        cx.shared_state().await.assert_eq(indoc! {"
422            oveˇrver
423            overox jumps jumps
424            overhe lazy dog"});
425
426        // copy in visual line mode
427        cx.set_shared_state(indoc! {"
428                The quick brown
429                fox juˇmps over
430                the lazy dog"})
431            .await;
432        cx.simulate_shared_keystrokes("shift-v d").await;
433        cx.shared_state().await.assert_eq(indoc! {"
434                The quick brown
435                the laˇzy dog"});
436        // paste in visual mode
437        cx.simulate_shared_keystrokes("v i w p").await;
438        cx.shared_state().await.assert_eq(&indoc! {"
439                The quick brown
440                the•
441                ˇfox jumps over
442                 dog"});
443        cx.shared_clipboard().await.assert_eq("lazy");
444        cx.set_shared_state(indoc! {"
445            The quick brown
446            fox juˇmps over
447            the lazy dog"})
448            .await;
449        cx.simulate_shared_keystrokes("shift-v d").await;
450        cx.shared_state().await.assert_eq(indoc! {"
451            The quick brown
452            the laˇzy dog"});
453        // paste in visual line mode
454        cx.simulate_shared_keystrokes("k shift-v p").await;
455        cx.shared_state().await.assert_eq(indoc! {"
456            ˇfox jumps over
457            the lazy dog"});
458        cx.shared_clipboard().await.assert_eq("The quick brown\n");
459    }
460
461    #[gpui::test]
462    async fn test_paste_visual_block(cx: &mut gpui::TestAppContext) {
463        let mut cx = NeovimBackedTestContext::new(cx).await;
464        // copy in visual block mode
465        cx.set_shared_state(indoc! {"
466            The ˇquick brown
467            fox jumps over
468            the lazy dog"})
469            .await;
470        cx.simulate_shared_keystrokes("ctrl-v 2 j y").await;
471        cx.shared_clipboard().await.assert_eq("q\nj\nl");
472        cx.simulate_shared_keystrokes("p").await;
473        cx.shared_state().await.assert_eq(indoc! {"
474            The qˇquick brown
475            fox jjumps over
476            the llazy dog"});
477        cx.simulate_shared_keystrokes("v i w shift-p").await;
478        cx.shared_state().await.assert_eq(indoc! {"
479            The ˇq brown
480            fox jjjumps over
481            the lllazy dog"});
482        cx.simulate_shared_keystrokes("v i w shift-p").await;
483
484        cx.set_shared_state(indoc! {"
485            The ˇquick brown
486            fox jumps over
487            the lazy dog"})
488            .await;
489        cx.simulate_shared_keystrokes("ctrl-v j y").await;
490        cx.shared_clipboard().await.assert_eq("q\nj");
491        cx.simulate_shared_keystrokes("l ctrl-v 2 j shift-p").await;
492        cx.shared_state().await.assert_eq(indoc! {"
493            The qˇqick brown
494            fox jjmps over
495            the lzy dog"});
496
497        cx.simulate_shared_keystrokes("shift-v p").await;
498        cx.shared_state().await.assert_eq(indoc! {"
499            ˇq
500            j
501            fox jjmps over
502            the lzy dog"});
503    }
504
505    #[gpui::test]
506    async fn test_paste_indent(cx: &mut gpui::TestAppContext) {
507        let mut cx = VimTestContext::new_typescript(cx).await;
508
509        cx.set_state(
510            indoc! {"
511            class A {ˇ
512            }
513        "},
514            Mode::Normal,
515        );
516        cx.simulate_keystrokes("o a ( ) { escape");
517        cx.assert_state(
518            indoc! {"
519            class A {
520                a()ˇ{}
521            }
522            "},
523            Mode::Normal,
524        );
525        // cursor goes to the first non-blank character in the line;
526        cx.simulate_keystrokes("y y p");
527        cx.assert_state(
528            indoc! {"
529            class A {
530                a(){}
531                ˇa(){}
532            }
533            "},
534            Mode::Normal,
535        );
536        // indentation is preserved when pasting
537        cx.simulate_keystrokes("u shift-v up y shift-p");
538        cx.assert_state(
539            indoc! {"
540                ˇclass A {
541                    a(){}
542                class A {
543                    a(){}
544                }
545                "},
546            Mode::Normal,
547        );
548    }
549
550    #[gpui::test]
551    async fn test_paste_count(cx: &mut gpui::TestAppContext) {
552        let mut cx = NeovimBackedTestContext::new(cx).await;
553
554        cx.set_shared_state(indoc! {"
555            onˇe
556            two
557            three
558        "})
559            .await;
560        cx.simulate_shared_keystrokes("y y 3 p").await;
561        cx.shared_state().await.assert_eq(indoc! {"
562            one
563            ˇone
564            one
565            one
566            two
567            three
568        "});
569
570        cx.set_shared_state(indoc! {"
571            one
572            ˇtwo
573            three
574        "})
575            .await;
576        cx.simulate_shared_keystrokes("y $ $ 3 p").await;
577        cx.shared_state().await.assert_eq(indoc! {"
578            one
579            twotwotwotwˇo
580            three
581        "});
582    }
583
584    #[gpui::test]
585    async fn test_numbered_registers(cx: &mut gpui::TestAppContext) {
586        let mut cx = NeovimBackedTestContext::new(cx).await;
587
588        cx.update_global(|store: &mut SettingsStore, cx| {
589            store.update_user_settings::<VimSettings>(cx, |s| {
590                s.use_system_clipboard = Some(UseSystemClipboard::Never)
591            });
592        });
593
594        cx.set_shared_state(indoc! {"
595                The quick brown
596                fox jˇumps over
597                the lazy dog"})
598            .await;
599        cx.simulate_shared_keystrokes("y y \" 0 p").await;
600        cx.shared_register('0').await.assert_eq("fox jumps over\n");
601        cx.shared_register('"').await.assert_eq("fox jumps over\n");
602
603        cx.shared_state().await.assert_eq(indoc! {"
604                The quick brown
605                fox jumps over
606                ˇfox jumps over
607                the lazy dog"});
608        cx.simulate_shared_keystrokes("k k d d").await;
609        cx.shared_register('0').await.assert_eq("fox jumps over\n");
610        cx.shared_register('1').await.assert_eq("The quick brown\n");
611        cx.shared_register('"').await.assert_eq("The quick brown\n");
612
613        cx.simulate_shared_keystrokes("d d shift-g d d").await;
614        cx.shared_register('0').await.assert_eq("fox jumps over\n");
615        cx.shared_register('3').await.assert_eq("The quick brown\n");
616        cx.shared_register('2').await.assert_eq("fox jumps over\n");
617        cx.shared_register('1').await.assert_eq("the lazy dog\n");
618
619        cx.shared_state().await.assert_eq(indoc! {"
620        ˇfox jumps over"});
621
622        cx.simulate_shared_keystrokes("d d \" 3 p p \" 1 p").await;
623        cx.set_shared_state(indoc! {"
624                The quick brown
625                fox jumps over
626                ˇthe lazy dog"})
627            .await;
628    }
629
630    #[gpui::test]
631    async fn test_named_registers(cx: &mut gpui::TestAppContext) {
632        let mut cx = NeovimBackedTestContext::new(cx).await;
633
634        cx.update_global(|store: &mut SettingsStore, cx| {
635            store.update_user_settings::<VimSettings>(cx, |s| {
636                s.use_system_clipboard = Some(UseSystemClipboard::Never)
637            });
638        });
639
640        cx.set_shared_state(indoc! {"
641                The quick brown
642                fox jˇumps over
643                the lazy dog"})
644            .await;
645        cx.simulate_shared_keystrokes("\" a d a w").await;
646        cx.shared_register('a').await.assert_eq("jumps ");
647        cx.simulate_shared_keystrokes("\" shift-a d i w").await;
648        cx.shared_register('a').await.assert_eq("jumps over");
649        cx.shared_register('"').await.assert_eq("jumps over");
650        cx.simulate_shared_keystrokes("\" a p").await;
651        cx.shared_state().await.assert_eq(indoc! {"
652                The quick brown
653                fox jumps oveˇr
654                the lazy dog"});
655        cx.simulate_shared_keystrokes("\" a d a w").await;
656        cx.shared_register('a').await.assert_eq(" over");
657    }
658
659    #[gpui::test]
660    async fn test_special_registers(cx: &mut gpui::TestAppContext) {
661        let mut cx = NeovimBackedTestContext::new(cx).await;
662
663        cx.update_global(|store: &mut SettingsStore, cx| {
664            store.update_user_settings::<VimSettings>(cx, |s| {
665                s.use_system_clipboard = Some(UseSystemClipboard::Never)
666            });
667        });
668
669        cx.set_shared_state(indoc! {"
670                The quick brown
671                fox jˇumps over
672                the lazy dog"})
673            .await;
674        cx.simulate_shared_keystrokes("d i w").await;
675        cx.shared_register('-').await.assert_eq("jumps");
676        cx.simulate_shared_keystrokes("\" _ d d").await;
677        cx.shared_register('_').await.assert_eq("");
678
679        cx.shared_state().await.assert_eq(indoc! {"
680                The quick brown
681                the ˇlazy dog"});
682        cx.simulate_shared_keystrokes("\" \" d ^").await;
683        cx.shared_register('0').await.assert_eq("the ");
684        cx.shared_register('"').await.assert_eq("the ");
685
686        cx.simulate_shared_keystrokes("^ \" + d $").await;
687        cx.shared_clipboard().await.assert_eq("lazy dog");
688        cx.shared_register('"').await.assert_eq("lazy dog");
689
690        cx.simulate_shared_keystrokes("/ d o g enter").await;
691        cx.shared_register('/').await.assert_eq("dog");
692        cx.simulate_shared_keystrokes("\" / shift-p").await;
693        cx.shared_state().await.assert_eq(indoc! {"
694                The quick brown
695                doˇg"});
696
697        // not testing nvim as it doesn't have a filename
698        cx.simulate_keystrokes("\" % p");
699        cx.assert_state(
700            indoc! {"
701                    The quick brown
702                    dogdir/file.rˇs"},
703            Mode::Normal,
704        );
705    }
706
707    #[gpui::test]
708    async fn test_multicursor_paste(cx: &mut gpui::TestAppContext) {
709        let mut cx = VimTestContext::new(cx, true).await;
710
711        cx.update_global(|store: &mut SettingsStore, cx| {
712            store.update_user_settings::<VimSettings>(cx, |s| {
713                s.use_system_clipboard = Some(UseSystemClipboard::Never)
714            });
715        });
716
717        cx.set_state(
718            indoc! {"
719               ˇfish one
720               fish two
721               fish red
722               fish blue
723                "},
724            Mode::Normal,
725        );
726        cx.simulate_keystrokes("4 g l w escape d i w 0 shift-p");
727        cx.assert_state(
728            indoc! {"
729               onˇefish•
730               twˇofish•
731               reˇdfish•
732               bluˇefish•
733                "},
734            Mode::Normal,
735        );
736    }
737}