Home Explore Blog CI



neovim

5th chunk of `runtime/doc/usr_07.txt`
bc49dd85f5df7f915a82ea150c09dac7a3d2dc5dce78cc9c00000001000008b8
 f register (f for First): >

	"fyas

The "yas" command yanks a sentence like before.  It's the "f that tells Vim
the text should be placed in the f register.  This must come just before the
yank command.
   Now yank three whole lines to the l register (l for line): >

	"l3yy

The count could be before the "l just as well.  To yank a block of text to the
b (for block) register: >

	CTRL-Vjjww"by

Notice that the register specification "b is just before the "y" command.
This is required.  If you would have put it before the "w" command, it would
not have worked.
   Now you have three pieces of text in the f, l and b registers.  Edit
another file, move around and place the text where you want it: >

	"fp

Again, the register specification "f comes before the "p" command.
   You can put the registers in any order.  And the text stays in the register
until you yank something else into it.  Thus you can put it as many times as
you like.

When you delete text, you can also specify a register.  Use this to move
several pieces of text around.  For example, to delete-a-word and write it in
the w register: >

	"wdaw

Again, the register specification comes before the delete command "d".


APPENDING TO A FILE

When collecting lines of text into one file, you can use this command: >

	:write >> logfile

This will write the text of the current file to the end of "logfile".  Thus it
is appended.  This avoids that you have to copy the lines, edit the log file
and put them there.  Thus you save two steps.  But you can only append to the
end of a file.
   To append only a few lines, select them in Visual mode before typing
":write".  In chapter 10 you will learn other ways to select a range of lines.

==============================================================================
*07.6*	Viewing a file

Sometimes you only want to see what a file contains, without the intention to
ever write it back.  There is the risk that you type ":w" without thinking and
overwrite the original file anyway.  To avoid this, edit the file read-only.
   To start Vim in readonly mode, use this command: >

	vim -R file

On Unix this command should do the same thing: >

	view file

You are now editing "file" in read-only mode.  When

Title: Using Registers for Copying, Appending to Files, and Viewing Files Read-Only in Vim
Summary
This section explains how to use registers in Vim to copy and move multiple pieces of text. It provides examples of yanking text into registers (e.g., "fyas for a sentence, "l3yy for three lines, CTRL-Vjjww"by for a block) and putting text from registers into another file (e.g., "fp). It also discusses appending the current file or selected lines to another file using the `:write >> logfile` command. Finally, it describes how to open a file in read-only mode using `vim -R file` or `view file` to prevent accidental overwrites.