0
  1. place cursor in the middle of an existing line of text
  2. go to visual mode with 'v'
  3. hit 'l' several times to highlight some characters
  4. hit 'y' to copy
  5. hit 'esc'
  6. Go to another line of text
  7. Hit 'p' to paste
  8. copied text is pasted after current line instead of into current line

How do I paste the text into the middle of a line of text?

StevieD
  • 6,925
  • 2
  • 25
  • 45
  • 1
    This is probably better suited for the Vi/Vim Stack Exchange forum. – Jack Moody Dec 29 '18 at 19:28
  • 1
    Possible duplicate of [How to paste in the line where the cursor is?](https://stackoverflow.com/questions/9383709/how-to-paste-in-the-line-where-the-cursor-is) – Jack Moody Dec 29 '18 at 19:30
  • This works for me like expected. The yanked text is pasted into the current line after the cursor position. Why do you need step 5? You are in normal mode. – Ralf Dec 29 '18 at 21:30
  • 1
    BTW: Does this also happen if you start vim like this: `vim -u NONE -U NONE` – Ralf Dec 29 '18 at 21:39
  • Interesting. When I do -u NONE -U NONE I get the expected behavior. Time to look at the -u arguement. – StevieD Dec 29 '18 at 22:23
  • So has something to do with setting in vimrc. Wondering if it's my global clipboard setting? Any ideas? – StevieD Dec 29 '18 at 22:30
  • weird, the problem only happens when I'm editing a perl file. hmmm. – StevieD Dec 29 '18 at 22:34
  • OK, found the issue. Had the following in vimrc: ```nnoremap v nnoremap v vnoremap v vnoremap v ``` – StevieD Dec 29 '18 at 22:46
  • Anyway, I need to hit C-V instead of just 'v' for visual mode because of my modified .vimrc file. – StevieD Dec 29 '18 at 22:47
  • 1
    IMHO remapping base keys is rarely a wise idea. Note `v` is character-wise visual, `V` is line-wise and `` is block. – Ralf Dec 29 '18 at 23:51

1 Answers1

1

The steps you mentioned above should actually paste the yanked characters to the position where the cursor is while pasting. So I believe there are three possible reasons for getting pasted into the newline.

  1. Possibly one of your plugins/mappings is playing the devil here. Just try to use vim without any plugins or anything by running (clean equivalent to "-u DEFAULTS -U NONE -i NONE") and see if it's getting pasted as intended:

    vim --clean

  2. You have yanked the last characters of a line including the newline. Quite possible right? Like the last character of each line is a newline. So yanking and pasting those characters(including newline) to another line means the same newline is pasted into the "another line".

  3. A variant of the above, is when you yank using yy (that is yank the whole line) , then definitely while pasting it would go into a newline.

Hope this helps you somehow. Cheers!

Yedhin
  • 2,931
  • 13
  • 19