Related
How would I move the current line behind the line above it? Say I have:
function foo()
{
^ Cursor is here
And want to turn that into:
function foo() {
I am still new to vim, so what I do now is i[backspace][backspace]...etc. :)
Several ways:
In normal mode, kJ or kgJ or VkJ or VkgJ (the last two commands do the same in visual mode).
k will go to previous line, and J or gJ will merge with next line (J inserts a space inbetween, gJ just removes the EOL characters)
In command mode, :-,j or :-,j!
-, is a range that is abbreviation for .-1,. which means “from previous line to current line”
j is the ex command for concatenating lines in a range. The banged (with exclamation mark) version acts like gJ.
With a substitution: :-s/\s*\n\s*//
- means previous line
:s is probably known to you, else you should run vimtutor.
/\s*\n\s*/ is pattern for as many spaces as possible plus line terminator (matches different byte sequences according to the file format: LF, CR or CRLF) plus as many spaces as possible.
Here, replacement pattern is empty.
in insert mode, hit CTRL-W twice (each time it deletes a word, or leading whitespace on a line, or newline) (as ib. suggests, this depends on the backspace setting).
References:
:help J
:help gJ
:help k
:help range
:help :j
:help pattern
:help i_CTRL-W
Is there a way to indent a selection of lines in Vim, like we have in text editors where we select a bunch of lines and press tab (or shift tab) to indent/unindent the selected lines?
I am talking about general indentation and not related to code indentation.
You can select a set of lines with visual line mode (via Shift + V), and then type
>
and, to dedent,
<
You can also add numeric arguments. Find out you didn't indent enough? Hit gv to re-select your previous selection.
While typing in normal mode, try out Ctrl + T or Ctrl + D to indent or dedent.
Use visual mode as Peter suggests. You can also use X>> where X is the number of lines you want to indent. E.g. 5>> indents five lines from current line and down.
I use the following mappings to indent/unindent:
vmap <TAB> >gv
vmap <S-TAB> <gv
Use TAB to indent and shift-TAB to unindent the visually selected lines.
If a block is selected Vim indents/unindents what is right of the start of
the block.
As suggested by the other answers you can use >. Alternatively, you can automatically correctly indent your code by selecting the set of line in visual mode (using shift+V), and then using =, or using == to indent the current line.
There's a Vim Cast on this topic: Indentation commands
I like Vim Casts. They are informative and pleasant to watch.
I often have to paste some stuff on a new line in vim. What I usually do is:
o<Esc>p
Which inserts a new line and puts me in insertion mode, than quits insertion mode, and finally pastes.
Three keystrokes. Not very efficient. Any better ideas?
Shortly after :help p it says:
:[line]pu[t] [x] Put the text [from register x] after [line] (default
current line). This always works |linewise|, thus
this command can be used to put a yanked block as
new lines.
:[line]pu[t]! [x] Put the text [from register x] before [line]
(default current line).
Unfortunately it’s not shorter than your current solution unless you combined it with some keyboard map as suggested in a different answer. For instance, you can map it to any key (even p):
:nmap p :pu<CR>
Options:
1) Use yy to yank the whole line (including the end of line character). p will then paste the line on a new line after the current one and P (Shift-P) will paste above the current line.
2) Make a mapping: then it's only one or two keys:
:nmap ,p o<ESC>p
:nmap <F4> o<ESC>p
3) The function version of the mapping (unnecessary really, but just for completeness):
:nmap <F4> :call append(line('.'), #")<CR>
" This one may be a little better (strip the ending new-line before pasting)
:nmap <F4> :call append(line('.'), substitute(#", '\n$', '', ''))<CR>
:help let-register
:help :call
:help append()
:help line()
:help nmap
You can paste a buffer in insert mode using <C-R> followed by the name of the buffer to paste. The default buffer is ", so you would do
o<C-R>"
I found that I use <C-R>" very often and bound that to <C-F> in my vimrc:
inoremap <C-F> <C-R>"
This still uses three keystrokes, but I find it easier than Esc:
o<Alt-p>
Since you're in insert mode after hitting o, the Alt modifier will allow you to use a command as if you weren't.
Using this plugin: https://github.com/tpope/vim-unimpaired
]p pastes on the line below
[p pastes on the line above
advantages:
works on all yanked text (word, line, character, etc)
indents the pasted text to match the indentation of the text
around it
2 keystrokes instead of 3 and much "easier" strokes
fast
Personally I've nmapped Enter (CR) like this:
nmap <CR> o<Esc>k
...based on this Vim Wikia article.
This way I can make newlines directly from normal mode, and combining this with wanting to paste to a newline below I'd do:
<CR>jp
You could also skip k in the nmap above, depending on what functionality you prefer from Enter, so it would just be <CR>p.
I've also imapped jj to Esc, which would also assist in this case. Esc is way too far away from the home row for how significant it is in vim.
Not shorter than the other solutions, but I do think it feels less clunky than some of them, and it has other uses too.
If you wanted to stay in the insert mode, you can do o ctrl+o p
o – insert mode and go to the new line
ctrl+o – run a single command
like in normal mode
p – paste
It's three keystrokes but you stay in insert mode and also o ctrl+o is quite fast so I personally treat it as 2.5 keystrokes.
If you're copying a whole line then pasting a whole line, use Y to yank the line or lines, including line break, in the first place, and p to paste. You can also use V, which is visual line mode, in contrast with plain v for visual mode.
I have mapping inoremap jj <ESC>. So it is easy to insert new line with ojj and Ojj and then p.
so ojjp paste new a newline. it have one more stroke then o<esc>p but ojjp is easy for me.
I found an elegant solution to this. If you are putting the yank register in your OS's clipboard (which is great anyway), with
set clipboard+=unnamed
than you can do o<Ctl-v>.
Besides being fewer strokes, this improves on both o<Esc>p and :pu because it preserves indenting: both of the other options start you at character zero on the new line.
Caveat is that this may or may not be OS dependent. All I know is that it works on recent version of OS X, but clipboard is just one of many ways to get yank in the OS clipboard.
If you want to paste in a new line and still keep indentation, create this mapping:
nnoremap <leader>p oq<BS><Esc>p
Prerequisite: you have leader mapped and you have set autoindent in your .vimrc.
Explanation: a new line is created with 'o', 'q' is typed and then back-spaced on (to keep indentation), and 'esc' brings you back to normal mode where you finally paste.
If you also want to end in insert mode, it is possible to paste while in insert mode using CTRL-R ". https://stackoverflow.com/a/2861909/461834
Still three keystrokes, but no escape, and you save a keystroke if you want to end in insert anyway.
I use the following mapping in my Neovim config:
nnoremap <leader>p m`o<ESC>p``
nnoremap <leader>P m`O<ESC>p``
A little explanation:
m`: set a mark in the current cursor position.
o<Esc>p: create a new line below and paste the text in this line
O<Esc>P: create a new line above and paste the text in this line
``: put the cursor in the original position
See :h mark for more information about marks in Vim.
This solution only seems to apply when the block of copied text starts on a new line (as opposed to grabbing a snippet of text somewhere within a line), but you can always start your copy on the last character you want to grab, then navigate to the last character at the end of line prior to the start of your desired copy block. Then when you want to paste it, place the cursor at the end of the line under which you want your text to be pasted and hit p. If I haven't screwed up the explanation, this should provide the effect you're looking for.
It should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?
Use the > command. To indent five lines, 5>>. To mark a block of lines and indent it, Vjj> to indent three lines (Vim only). To indent a curly-braces block, put your cursor on one of the curly braces and use >% or from anywhere inside block use >iB.
If you’re copying blocks of text around and need to align the indent of a block in its new location, use ]p instead of just p. This aligns the pasted block with the surrounding text.
Also, the shiftwidth setting allows you to control how many spaces to indent.
This answer summarises the other answers and comments of this question, and it adds extra information based on the Vim documentation and the Vim wiki. For conciseness, this answer doesn't distinguish between Vi and Vim-specific commands.
In the commands below, "re-indent" means "indent lines according to your indentation settings." shiftwidth is the primary variable that controls indentation.
General Commands
>> Indent line by shiftwidth spaces
<< De-indent line by shiftwidth spaces
5>> Indent 5 lines
5== Re-indent 5 lines
>% Increase indent of a braced or bracketed block (place cursor on brace first)
=% Reindent a braced or bracketed block (cursor on brace)
<% Decrease indent of a braced or bracketed block (cursor on brace)
]p Paste text, aligning indentation with surroundings
=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block
>i{ Increase inner block indent
<i{ Decrease inner block indent
You can replace { with } or B, e.g. =iB is a valid block indent command. Take a look at "Indent a Code Block" for a nice example to try these commands out on.
Also, remember that
. Repeat last command
, so indentation commands can be easily and conveniently repeated.
Re-indenting complete files
Another common situation is requiring indentation to be fixed throughout a source file:
gg=G Re-indent entire buffer
You can extend this idea to multiple files:
" Re-indent all your C source code:
:args *.c
:argdo normal gg=G
:wall
Or multiple buffers:
" Re-indent all open buffers:
:bufdo normal gg=G:wall
In Visual Mode
Vjj> Visually mark and then indent three lines
In insert mode
These commands apply to the current line:
CTRL-t insert indent at start of line
CTRL-d remove indent at start of line
0 CTRL-d remove all indentation from line
Ex commands
These are useful when you want to indent a specific range of lines, without moving your
cursor.
:< and :> Given a range, apply indentation e.g.
:4,8> indent lines 4 to 8, inclusive
Indenting using markers
Another approach is via markers:
ma Mark top of block to indent as marker 'a'
...move cursor to end location
>'a Indent from marker 'a' to current location
Variables that govern indentation
You can set these in your .vimrc file.
set expandtab "Use softtabstop spaces instead of tab characters for indentation
set shiftwidth=4 "Indent by 4 spaces when using >>, <<, == etc.
set softtabstop=4 "Indent by 4 spaces when pressing <TAB>
set autoindent "Keep indentation from previous line
set smartindent "Automatically inserts indentation in some cases
set cindent "Like smartindent, but stricter and more customisable
Vim has intelligent indentation based on filetype. Try adding this to your .vimrc:
if has ("autocmd")
" File type detection. Indent based on filetype. Recommended.
filetype plugin indent on
endif
References
Indent a code block
Shifting blocks visually
Indenting source code
:help =
A big selection would be:
gg=G
It is really fast, and everything gets indented ;-)
Also try this for C-indenting indentation. Do :help = for more information:
={
That will auto-indent the current code block you're in.
Or just:
==
to auto-indent the current line.
Key presses for more visual people:
Enter Command Mode:
Escape
Move around to the start of the area to indent:
hjkl↑↓←→
Start a block:
v
Move around to the end of the area to indent:
hjkl↑↓←→
(Optional) Type the number of indentation levels you want
0..9
Execute the indentation on the block:
>
In addition to the answer already given and accepted, it is also possible to place a marker and then indent everything from the current cursor to the marker.
Thus, enter ma where you want the top of your indented block, cursor down as far as you need and then type >'a (note that "a" can be substituted for any valid marker name). This is sometimes easier than 5>> or vjjj>.
The master of all commands is
gg=G
This indents the entire file!
And below are some of the simple and elegant commands used to indent lines quickly in Vim or gVim.
To indent the current line
==
To indent the all the lines below the current line
=G
To indent n lines below the current line
n==
For example, to indent 4 lines below the current line
4==
To indent a block of code, go to one of the braces and use command
=%
These are the simplest, yet powerful commands to indent multiple lines.
When you select a block and use > to indent, it indents then goes back to normal mode. I have this in my .vimrc file:
vnoremap < <gv
vnoremap > >gv
It lets you indent your selection as many time as you want.
Go to the start of the text
press v for visual mode.
use up/down arrow to highlight text.
press = to indent all the lines you highlighted.
As well as the offered solutions, I like to do things a paragraph at a time with >}
Suppose you use 2 spaces to indent your code. Type:
:set shiftwidth=2
Type v (to enter visual block editing mode)
Move the cursor with the arrow keys (or with h/j/k/l) to highlight the lines you want to indent or unindent.
Then:
Type > to indent once (2 spaces).
Type 2> to indent twice (4 spaces).
Type 3> to indent thrice (6 spaces).
...
Type < to unindent once (2 spaces).
Type 2< to unindent twice (4 spaces).
Type 3< to unindent thrice (6 spaces).
...
You get the idea.
(Empty lines will not get indented, which I think is kind of nice.)
I found the answer in the (g)vim documentation for indenting blocks:
:help visual-block
/indent
If you want to give a count to the command, do this just before typing
the operator character: "v{move-around}3>" (move lines 3 indents to
the right).
The beauty of Vim's UI is that its consistency. Editing commands are made up of the command and a cursor move.
The cursor moves are always the same:
H to top of screen, L to bottom, M to middle
nG to go to line n, G alone to bottom of file, gg to top
n to move to next search match, N to previous
} to end of paragraph
% to next matching bracket, either of the parentheses or the tag kind
enter to the next line
'x to mark x where x is a letter or another '.
many more, including w and W for word, $ or 0 to tips of the line, etc., that don't apply here because are not line movements.
So, in order to use vim you have to learn to move the cursor and remember a repertoire of commands like, for example, > to indent (and < to "outdent").
Thus, for indenting the lines from the cursor position to the top of the screen you do >H, >G to indent to the bottom of the file.
If, instead of typing >H, you type dH then you are deleting the same block of lines, cH for replacing it, etc.
Some cursor movements fit better with specific commands. In particular, the % command is handy to indent a whole HTML or XML block. If the file has syntax highlighted (:syn on) then setting the cursor in the text of a tag (like, in the "i" of <div> and entering >% will indent up to the closing </div> tag.
This is how Vim works: one has to remember only the cursor movements and the commands, and how to mix them.
So my answer to this question would be "go to one end of the block of lines you want to indent, and then type the > command and a movement to the other end of the block" if indent is interpreted as shifting the lines, = if indent is interpreted as in pretty-printing.
You can use the norm i command to insert given text at the beginning of the line. To insert 10 spaces before lines 2-10:
:2,10norm 10i
Remember that there has to be a space character at the end of the command - this will be the character we want to have inserted. We can also indent a line with any other text, for example to indent every line in a file with five underscore characters:
:%norm 5i_
Or something even more fancy:
:%norm 2i[ ]
More practical example is commenting Bash/Python/etc code with # character:
:1,20norm i#
To re-indent use x instead of i. For example, to remove first 5 characters from every line:
:%norm 5x
:line_num_start,line_num_end>
For example,
14,21> shifts line number 14 to 21 to one tab
Increase the '>' symbol for more tabs.
For example,
14,21>>> for three tabs
Press "SHIFT + v" to enter VISUAL LINE mode.
Select the text you wish to indent but using either the cursor keys or the "j" and "k" keys.
To indent right press "SHIFT + dot" (> character).
To indent left press "SHIFT + comma" (< character).
Source: https://www.fir3net.com/UNIX/General/how-do-i-tab-multiple-lines-within-vi.html
Do this:
$vi .vimrc
And add this line:
autocmd FileType cpp setlocal expandtab shiftwidth=4 softtabstop=4 cindent
This is only for a cpp file. You can do this for another file type, also just by modifying the filetype...
A quick way to do this using VISUAL MODE uses the same process as commenting a block of code.
This is useful if you would prefer not to change your shiftwidth or use any set directives and is flexible enough to work with TABS or SPACES or any other character.
Position cursor at the beginning on the block
v to switch to -- VISUAL MODE --
Select the text to be indented
Type : to switch to the prompt
Replacing with 3 leading spaces:
:'<,'>s/^/ /g
Or replacing with leading tabs:
:'<,'>s/^/\t/g
Brief Explanation:
'<,'> - Within the Visually Selected Range
s/^/ /g - Insert 3 spaces at the beginning of every line within the whole range
(or)
s/^/\t/g - Insert Tab at the beginning of every line within the whole range
>} or >{ indent from current line up to next paragraph
<} or <{ same un-indent
I like to mark text for indentation:
go to beginning of line of text then type ma (a is the label from the 'm'ark: it could be any letter)
go to end line of text and type mz (again, z could be any letter)
:'a,'z> or :'a,'z< will indent or outdent (is this a word?)
Voila! The text is moved (empty lines remain empty with no spaces)
PS: you can use the :'a,'z technique to mark a range for any operation (d, y, s///, etc.) where you might use lines, numbers, or %.
For me, the MacVim (Visual) solution was, select with mouse and press ">", but after putting the following lines in "~/.vimrc" since I like spaces instead of tabs:
set expandtab
set tabstop=2
set shiftwidth=2
Also it's useful to be able to call MacVim from the command-line (Terminal.app), so since I have the following helper directory "~/bin", where I place a script called "macvim":
#!/usr/bin/env bash
/usr/bin/open -a /Applications/MacPorts/MacVim.app $#
And of course in "~/.bashrc":
export PATH=$PATH:$HOME/bin
MacPorts messes with "~/.profile" a lot, so the PATH environment variable can get quite long.
:help left
In ex mode you can use :left or :le to align lines a specified amount.
Specifically, :left will Left align lines in the [range]. It sets the indent in the lines to [indent] (default 0).
:%le3 or :%le 3 or :%left3 or :%left 3 will align the entire file by padding with three spaces.
:5,7 le 3 will align lines 5 through 7 by padding them with three spaces.
:le without any value or :le 0 will left align with a padding of 0.
This works in Vim and gVim.
5== will indent five lines from the current cursor position.
So you can type any number before ==. It will indent the number of lines. This is in command mode.
gg=G will indent the whole file from top to bottom.
I didn't find a method I use in the comments, so I'll share it (I think Vim only):
Esc to enter command mode
Move to the first character of the last line you want to indent
Ctrl + V to start block select
Move to the first character of the first line you want to indent
Shift + I to enter special insert mode
Type as many space/tabs as you need to indent to (two for example
Press Esc and spaces will appear in all lines
This is useful when you don't want to change indentation/tab settings in vimrc or to remember them to change it while editing.
To unindent I use the same Ctrl + V block select to select spaces and delete it with D.
I don’t know why it's so difficult to find a simple answer like this one...
I myself had to struggle a lot to know this. It's very simple:
Edit your .vimrc file under the home directory.
Add this line
set cindent
in your file where you want to indent properly.
In normal/command mode type
10== (This will indent 10 lines from the current cursor location)
gg=G (Complete file will be properly indented)
I use block-mode visual selection:
Go to the front of the block to move (at the top or bottom).
Press Ctrl + V to enter visual block mode.
Navigate to select a column in front of the lines.
Press I (Shift + I) to enter insert mode.
Type some spaces.
Press Esc. All lines will shift.
This is not a uni-tasker. It works:
In the middle of lines.
To insert any string on all lines.
To change a column (use c instead of I).
yank, delete, substitute, etc...
For a block of code, {}: = + %
For a selected line: Shift + v select using the up/down arrow keys, and then press =.
For the entire file: gg + = + G
Note: 'gg' means go to line 1, '=' is the indent command, and 'G' moves the cursor to the end of file.
For who like modern editors to indent selected line with <TAB> -> Tab and <S-TAB> -> Shift+Tab:
vnoremap <TAB> >gv
vnoremap <S-TAB> <gv
Usage:
Hit V for line-wise visual-mode, select lines you want, then hit Tab(maybe with shift), then indention applies as you want and selection remains...
Using Python a lot, I find myself needing frequently needing to shift blocks by more than one indent. You can do this by using any of the block selection methods, and then just enter the number of indents you wish to jump right before the >
For example, V5j3> will indent five lines three times - which is 12 spaces if you use four spaces for indents.
To indent every line in a file type, Esc and then G=gg.
How to indent highlighted code in vi immediately by a number of spaces:
Option 1: Indent a block of code in vi to three spaces with Visual Block mode:
Select the block of code you want to indent. Do this using Ctrl+V in normal mode and arrowing down to select text. While it is selected, enter : to give a command to the block of selected text.
The following will appear in the command line: :'<,'>
To set indent to three spaces, type le 3 and press enter. This is what appears: :'<,'>le 3
The selected text is immediately indented to three spaces.
Option 2: Indent a block of code in vi to three spaces with Visual Line mode:
Open your file in vi.
Put your cursor over some code
Be in normal mode and press the following keys:
Vjjjj:le 3
Interpretation of what you did:
V means start selecting text.
jjjj arrows down four lines, highlighting four lines.
: tells vi you will enter an instruction for the highlighted text.
le 3 means indent highlighted text three lines.
The selected code is immediately increased or decreased to three spaces indentation.
Option 3: use Visual Block mode and special insert mode to increase indent:
Open your file in vi.
Put your cursor over some code
Be in normal mode press the following keys:
Ctrl+V
jjjj
(press the spacebar five times)
Esc
Shift+i
All the highlighted text is indented an additional five spaces.
How do I duplicate a whole line in Vim in a similar way to Ctrl+D in IntelliJ IDEA/ Resharper or Ctrl+Alt+↑/↓ in Eclipse?
yy or Y to copy the line (mnemonic: yank)
or
dd to delete the line (Vim copies what you deleted into a clipboard-like "register", like a cut operation)
then
p to paste the copied or deleted text after the current line
or
Shift + P to paste the copied or deleted text before the current line
Normal mode: see other answers.
The Ex way:
:t. will duplicate the line,
:t 7 will copy it after line 7,
:,+t0 will copy current and next line at the beginning of the file (,+ is a synonym for the range .,.+1),
:1,t$ will copy lines from beginning till cursor position to the end (1, is a synonym for the range 1,.).
If you need to move instead of copying, use :m instead of :t.
This can be really powerful if you combine it with :g or :v:
:v/foo/m$ will move all lines not matching the pattern “foo” to the end of the file.
:+,$g/^\s*class\s\+\i\+/t. will copy all subsequent lines of the form class xxx right after the cursor.
Reference: :help range, :help :t, :help :g, :help :m and :help :v
YP or Yp or yyp.
Doesn't get any simpler than this! From normal mode:
yy
then move to the line you want to paste at and
p
yy
will yank the current line without deleting it
dd
will delete the current line
p
will put a line grabbed by either of the previous methods
Do this:
First, yy to copy the current line, and then p to paste.
If you want another way:
"ayy:
This will store the line in buffer a.
"ap:
This will put the contents of buffer a at the cursor.
There are many variations on this.
"a5yy:
This will store the 5 lines in buffer a.
See "Vim help files for more fun.
yyp - remember it with "yippee!"
Multiple lines with a number in between:
y7yp
yyp - paste after
yyP - paste before
I like:
Shift+v (to select the whole line immediately and let you select other lines if you want), y, p
Another option would be to go with:
nmap <C-d> mzyyp`z
gives you the advantage of preserving the cursor position.
You can also try <C-x><C-l> which will repeat the last line from insert mode and brings you a completion window with all of the lines. It works almost like <C-p>
For someone who doesn't know vi, some answers from above might mislead him with phrases like "paste ... after/before current line".
It's actually "paste ... after/before cursor".
yy or Y to copy the line
or
dd to delete the line
then
p to paste the copied or deleted text after the cursor
or
P to paste the copied or deleted text before the cursor
For more key bindings, you can visit this site: vi Complete Key Binding List
I know I'm late to the party, but whatever; I have this in my .vimrc:
nnoremap <C-d> :copy .<CR>
vnoremap <C-d> :copy '><CR>
the :copy command just copies the selected line or the range (always whole lines) to below the line number given as its argument.
In normal mode what this does is copy . copy this line to just below this line.
And in visual mode it turns into '<,'> copy '> copy from start of selection to end of selection to the line below end of selection.
Default is yyp, but I've been using this rebinding for a year or so and love it:
" set Y to duplicate lines, works in visual mode as well.
nnoremap Y yyp
vnoremap Y y`>pgv
I prefer to define a custom keymap Ctrl+D in .vimrc to duplicate the current line both in normal mode and insert mode:
" duplicate line in normal mode:
nnoremap <C-D> Yp
" duplicate line in insert mode:
inoremap <C-D> <Esc> Ypi
1 gotcha: when you use "p" to put the line, it puts it after the line your cursor is on, so if you want to add the line after the line you're yanking, don't move the cursor down a line before putting the new line.
For those starting to learn vi, here is a good introduction to vi by listing side by side vi commands to typical Windows GUI Editor cursor movement and shortcut keys. It lists all the basic commands including yy (copy line) and p (paste after) or P(paste before).
vi (Vim) for Windows Users
If you would like to duplicate a line and paste it right away below the current like, just like in Sublime Ctrl+Shift+D, then you can add this to your .vimrc file.
nmap <S-C-d> <Esc>Yp
Or, for Insert mode:
imap <S-C-d> <Esc>Ypa
I like to use this mapping:
:nnoremap yp Yp
because it makes it consistent to use alongside the native YP command.
I use this mapping, which is similar to vscode. I hope it is useful!!!.
nnoremap <A-d> :t. <CR>==
inoremap <A-d> <Esc>:t. <CR>==gi
vnoremap <A-d> :t$ <CR>gv=gv