Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight yanked area #104

Open
Taverius opened this issue Jun 5, 2017 · 4 comments
Open

Highlight yanked area #104

Taverius opened this issue Jun 5, 2017 · 4 comments

Comments

@Taverius
Copy link

Taverius commented Jun 5, 2017

I'm not even sure if its possible, but I would love to have this functionality.

@rafaeln
Copy link

rafaeln commented Jun 7, 2017

Have you checked whether vim-highlightedyank is compatible with vim-easyclip?

@vitmy0000
Copy link

Neither vim-highlightedyank nor vim-operator-flashy
works with EasyClip.

Below can be a workaround for Y and yy, however solution for y seems not trivial.
Any way combine two operators that accept same motion/text obect?

map y <Plug>(operator-flashy)
nmap Y :EasyClipBeforeYank<cr>y$:EasyClipOnYanksChanged<cr><Plug>(operator-flashy)$
nmap yy <Plug>YankLinePreserveCursorPosition<Plug>(operator-flashy)y

@vitmy0000
Copy link

This may be a temporary solution:

hi HighlightedyankRegion ctermfg=Black ctermbg=Blue
function! s:sallowsleep(ms) abort
  let t = reltime()
  while !getchar(1) && a:ms - str2float(reltimestr(reltime(t))) * 1000.0 > 0
  endwhile
endfunction
function! HighlightYankedLine()
  let l:curline = line('.')
  call matchaddpos("HighlightedyankRegion", [l:curline])
  redraw
  call s:sallowsleep(500)
  call clearmatches()
endfunction
function! HighlightYankedEOL()
  let l:curline = line(".")
  let l:curcol = virtcol(".")
  let l:eofcol = virtcol("$")
  call matchaddpos("HighlightedyankRegion", [[l:curline, l:curcol, l:eofcol - l:curcol]])
  redraw
  call s:sallowsleep(500)
  call clearmatches()
endfunction
function! EasyClipYankMotionHighlithWrapper(type)
  call EasyClip#Yank#YankMotion(a:type)
  let l:startline = line("'[")
  let l:startcol = virtcol("'[")
  let l:endline = line("']")
  let l:endcol = virtcol("']")
  if a:type ==# 'char' && l:startline == l:endline
    call matchaddpos("HighlightedyankRegion", [[l:startline, l:startcol, l:endcol - l:startcol + 1]])
  elseif a:type ==# 'char' && l:startline != l:endline
    execute "normal! '["
    let l:firstlineEndcol = virtcol("$")
    call matchaddpos("HighlightedyankRegion", [[l:startline, l:startcol, l:firstlineEndcol - l:startcol]])
    for l:line in range(l:startline + 1, l:endline - 1)
      call matchaddpos("HighlightedyankRegion", [l:line])
    endfor
    call matchaddpos("HighlightedyankRegion", [[l:endline, 0, l:endcol]])
  elseif a:type ==# 'line'
    for l:line in range(l:startline, l:endline)
      call matchaddpos("HighlightedyankRegion", [l:line])
    endfor
  endif
  redraw
  call s:sallowsleep(500)
  call clearmatches()
endfunction
nnoremap <silent> yy :<c-u>call EasyClip#Yank#PreYankMotion()<cr>:call EasyClip#Yank#YankLine()<cr>:<c-u>call HighlightYankedLine()<cr>
nnoremap <silent> <expr> Y ":<c-u>call EasyClip#Yank#PreYankMotion()<cr>:set opfunc=EasyClip#Yank#YankMotion<cr>" . (v:count > 0 ? v:count : '') . "g@$:<c-u>call HighlightYankedEOL()<cr>"
nnoremap <silent> <expr> y ":<c-u>call EasyClip#Yank#PreYankMotion()<cr>:set opfunc=EasyClipYankMotionHighlithWrapper<cr>" . (v:count > 0 ? v:count : '') . "g@"

@coachshea
Copy link

If you are using a fairly recent version of vim or neovim, vim-highlightedyank is perfectly compatible. The TextYankPost event makes the 'y' mapping unnecessary and it now works "out of the box" and therefore is perfectly compatible with easyclip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants