So I\'ve discovered that a common task for me in Vim is to PUT either to the start of the line or the end of the line. So my mapping could be:
nmap
This is perfectly possible. I first I though this solution was possible: https://stackoverflow.com/a/290723/15934, but <expr> won't let us move the cursor as we wish, and normal can't be used.
Still, we can do this:
function! s:PutAt(where)
" <setline($+1> appends, but <setline(0> does not insert, hence the hack
" with getline to build a list of what should be at the start of the buffer.
let line = a:where ==1
\ ? [getreg(), getline(1)]
\ : getreg()
call setline(a:where, line)
endfunction
nnoremap <silent> <leader>P :call <sid>PutAt(1)<cr>
nnoremap <silent> <leader>p :call <sid>PutAt(line('$')+1)<cr>
You can do this using <expr> mapping in one line:
nnoremap <expr> \p '$"'.v:register.v:count1.'p'
nnoremap <expr> \P '0"'.v:register.v:count1.'P'