How to paste in the line where the cursor is?

2019-01-13 01:58发布

The command p pastes below the cursor and P pastes above the cursor. What's the command to paste in the line where cursor is?

10条回答
2楼-- · 2019-01-13 02:41

(I know this thread is old, just leaving this and hope this may help someone)

Inspired by @wbg's comment above regarding deleting the line feed, I added these to my mappings:

nnoremap <leader>p :let @"=substitute(@", '\n\+$', '', '')<CR>p

inoremap <leader>p <esc>:let @"=substitute(@", '\n\+$', '', '')<CR>pa

This is useful when I have a file with some SQLs (line by line) and I have to yank into the code.

查看更多
做自己的国王
3楼-- · 2019-01-13 02:44

To paste in insert mode you just press Control+R. Then enter the register, e.g. Shift++.

To paste in command mode, you press P, however you've to make sure your line doesn't have a new line character (e.g. yanked by 0v$hy), otherwise it'll appear above the cursor.

The same for visual mode, see: How to paste a line in a vertical selection block? at Vim SE

查看更多
疯言疯语
4楼-- · 2019-01-13 02:47

The Edit menu in gvim lists the following:

  • Paste = "+gP

  • Put Before = [p

  • Put After = ]p

If you're running vim in Windows, you can do the following to get Ctrl+C and Ctrl+V to work as expected:

source $VIMRUNTIME/mswin.vim
behave mswin
查看更多
【Aperson】
5楼-- · 2019-01-13 02:47

I needed to "cast" register contents into a certain (characterwise / linewise / blockwise) mode so often, I wrote the UnconditionalPaste plugin for it. It provides gcp, glp, etc. alternatives to the built-in paste commands that force a certain mode (and by now several more variations on this theme, like pasting with joined by commas or queried characters).

With it, you can just use gcp / gcP to paste after / before the cursor position, regardless of how you've yanked the text.

查看更多
Summer. ? 凉城
6楼-- · 2019-01-13 02:54

I'm not sure there is one. I tried to find documentation and ran across the following three documents:

Unfortunately, all three only have the two commands that you list. Particularly, the third link states that The commands to paste are p and P...

查看更多
再贱就再见
7楼-- · 2019-01-13 02:55
  1. divide the line into 2 wherever you want to insert

  2. paste the section between them

  3. merge the 3 lines with j as described here (Delete newline in Vim)

works, but tedious, and had to think about, look it up => vi and emacs are garbage software

查看更多
登录 后发表回答