I'm trying to write a mapping that will copy the text and automatically unwrap it at the same time. Here's what I got:function! CopyUnwrapped(type, ...)    if a:0        normal! gvay    else        normal! `[v`]ay    endif    new    setlocal buftype=nofile bufhidden=hide noswapfile nobuflisted    normal! ap    %normal! vipJ    normal! ggvG$+y    qendfunctionvnoremap <leader>y :call CopyUnwrapped(visualmode(), 1)<CR>nnoremap <leader>y :set opfunc=CopyUnwrapped<CR>g@It works almost perfectly works fine in visual mode as far as I can tell. But when I try <leader>yip, for instance, the last line of the paragraph is cut off, I don't understand why. Any ideas?
Problem mapping operator
key bindings;vimscript;map operator
If you look at example in documentation for g@, you can notice that your function is missing handling of a linewise selection. ip motion apparently acts as a linewise in this case and if you handle it as characterwise only first character of the last line is copied (because that's where `] is positioned; do vipv on a paragraph to see it for yourself).Thus that if-statement should look like this:if a:0    normal! gvayelseif a:type == 'line'    normal! `[V`]ayelse    normal! `[v`]ayendifNotice that for linewise selection, V is used to select by lines (which quotes are used is irrelevant for this kind of selection).