Insert at the end of a file in VIM without moving the cursor

In a word document, I [visually or otherwise] select multiple lines by cutting them with d

... I would like to insert those lines at the end of the file without moving the cursor. Is there a relatively simple way to do this?

+3


source to share


4 answers


Use implicit sign from last jump

You can use an implicit label (for example '

) to return the cursor to the position it occupied just before the last jump. For example:



G p ' '

This will be (G) o to the end of the file, (p) after the contents of the last line, and then back to your position at the time you typed G.

+4


source


You can define a mapping that marks the current location, inserts at the end of the buffer with :$put

, and then returns to the original cursor location with the label.

This works because it :put

allows the line number to be prefixed (the last line is represented as $

). From :help put

:

:[line]pu[t] [x]        Put the text [from register x]

      



This would map it to <leader>

p:

:nnoremap <leader>p :mark '<cr>:$put<cr>`'

      

It sets the label '

to the cursor, inserts at the end, and then returns to the icon '

with`

+2


source


There are several ways:

Marks

Set a mark, make a paste, then go back to mark

m':$pu<cr>``

      

Visual mode

Visually select your rows, copy them, add and then restore the visual selection (optionally remove)

y:$pu<cr>gv

      

Add to file

Visually select your lines, use :w

to append to the file, and then reload the file. (Note: move the cursor to the beginning of the visually selected lines)

:w >><cr>:e!

      

Create your own command / mapping

You can create your own team and / or a comparison that will be used winsaveview()

and winrestview()

to add and restore the cursor.

+2


source


Depends on how you mean "without moving the cursor".

This will insert at the bottom of the current file and then allow you to continue where you cut off the lines.

  • splitting the window with: split
  • move down shift+g
  • insert with p
  • close duplicate split view ( z zor: q)

If you don't like split view you can use ctrl + o to go back after G

  • move down shift+g
  • insert with p
  • return with ctrl+o
+1


source







All Articles