" the function where everything happens
function! MagicPaste()
" create a new buffer, see :help :enew
enew
" grab the content of register "+
let reg = getreg("+", 1, 1)
" figure out how many empty lines there are at the top
" and remove them, if any
let i = 0
while reg[i] == ""
let i += 1
endwhile
if i > 0
call remove(reg, 0, i - 1)
endif
" insert the the remaining lines in the buffer,
" see :help setline() and :help getreg()
call setline(1, reg)
" perform filetype detection
filetype detect
endfunction
" the custom mapping
nnoremap <key> <Cmd>call MagicPaste()<CR>
1条答案
按热度按时间lfapxunr1#
您可以创建一个单一的Map来完成所有事情:
字符串
请注意,此代码片段假设您有一个适当的Vim,构建时支持剪贴板。