Search code examples
vim

Copy/Past from vim command-line mode


Is there a way to read (yank) or/and write (paste) to the buffer form the vim's command-line mode ? I mean beside the norm command ?

for example:

  1. how can I put the content of register 'a' into line 5, position 6 from the command-line, without using the normal command?
  2. how to store the letters in register 'b' from the current buffer from position (line 3, col 4) till 5, 2 ?

Solution

  • how can I put the content of register 'a' into line 5, position 6 from the command-line, without using the normal command?

    The built-in editing-related Ex commands are all line-wise by design so they can't be used for charater-wise edits. They simply don't know anything beyond line numbers. That is the job of normal mode and executing normal mode commands in the command-line is done via :normal.

    This would be one way to do what you want with :normal:

    :5normal 5l"ap
    

    And this would be a substitution-based alternative:

    :5s/\%>6c/\=getreg("a")/
    

    And this would be a vimscript-based alternative:

    :call getline('5')->substitute('\%>6c', getreg('a'), '')->setline('5')
    

    Pick your poison.

    how to store the letters in register 'b' from the current buffer from position (line 3, col 4) till 5, 2 ?

    There is no way to do that with the built-in editing-related Ex commands, for the reason mentioned above.

    Just use :normal, that is what it was made for.