philc / vimium

The hacker's browser.
https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb
MIT License
23.38k stars 2.48k forks source link

How can I copy text from a page #3035

Open abbood opened 6 years ago

abbood commented 6 years ago

I was wondering if there is a way to select text from a page without using a mouse? for example if there is an email email@domain.com, i would like to simply copy the text of that email

smblott-github commented 6 years ago

You can try visual mode: https://github.com/philc/vimium/wiki/Visual-Mode.

Tip: start by searching (/) for the start of the text you want to select. Tip 2: search also works in visual mode itself.

abbood commented 6 years ago

@smblott-github this is awesome.. there is a small problem though that is preventing me from being able to use this feature. Maybe you can show me how to make it work. First let me explain the use case:

  1. first I go to a linkedin contact page
  2. I click on f, which gives me a letter for each link, i'm interested in contact info: linkedin 2018-05-29 06-54-54
  3. this launches the contact info dialogue, which amongst other things, has the persons contact: racha dsouki linkedin 2018-05-29 06-56-39

the problem is that clicking on Esc dismisses that dialogue.. following the instructions in the visual-mode, I need to do the following

how do i go around this?

smblott-github commented 6 years ago

Sounds like we might be leaking an <Escape> to the page.

I'll look into it.

abbood commented 6 years ago

ok great, please keep me posted (I'm curious as to how I can update my vimium to reflect your changes for example)

innaterebel commented 6 years ago

Wait, why did you need to exit visual mode before yank? Text yanking works within visual mode.

Edit: I see, the way the wiki lists the commands must had you misunderstood.

Exiting visual mode: Esc - just exit visual mode y - yank the selected text to the clipboard p/P - send the selected text to the default search engine

It simply is listing commands that will result in exiting visual mode, not instructing a set of steps to follow.

Perhaps the Exiting visual mode: line should be removed, it is not really something totally unexpected to be pointed out.

snippins commented 6 years ago

I think it would be much better if we can use the acejump/avy (emacs) or easymotion (vim) way of selecting text. Which mean to move the cursor, you can type a character first and the hint will appear at the locations of said character and we get the cursor at exactly where we look at, much like when using a mouse. I do not know if it is possible to implement with Webextension though.

innaterebel commented 6 years ago

Find mode pretty much does that, doesn't it? (/ still works while visual mode is operating) E.g. if I want to copy the Webextension in your comment, I do the following:

  1. v to activate visual mode or caret mode.
  2. / to evoke find mode and type web, hit Enter.
  3. Now I am back to visual mode with Webextension selected.
snippins commented 6 years ago

@innaterebel not really, if there are many words have the same prefix, it might scroll the page somewhere else, this is because unlike in VIM the cursor is not always on the visible part of the page. Thus a quite few "n" might be needed. The page scrolling also make the experience not consistent, and I found myself many times resorted to mouse more because of this. With something similar to acejump I can almost just look and the cursor move there.

Another solution is to allow moving the cursor to the beginning of the line/paragraph with hints when starting visual mode (surfingkeys does exact this). This guarantee the search will land on the correct words faster and the most important part is that the page will not scroll, resulted in a stable experience.

The second solution might be more desirable for more people. I've seen many coders adopted a similar flow in different text editors, which is move to the line - search for the word.

smblott-github commented 6 years ago

I find that what @innaterebel suggests usually works well in practice. It's usually possible to come up with a search that picks exactly what you want. Also, Vimium uses smartcase for search, so throwing in a suitable capital letter can help.

(Another tip: in visual mode, use o to select and move the other end of the selection.)

andmarti1424 commented 6 years ago

there seems to be a bug when copying text in visual mode. For instance, try to copy the 3rd paragraph on snippins comment of Aug 11: "The second..". when I press 'y' (and then paste it somewhere) it only gets yanked the first letter: 'T'..

Its weird since at the bottom it says: 181 characters yanked..

andmarti1424 commented 6 years ago

I believe the first letter gets copied in the primary clipboard.. and the entire content in the C-c clipboard..

smblott-github commented 6 years ago

The second solution might be more desirable for more people. I've seen many coders adopted a similar flow in different text editors, which is move to the line - search for the word.

Perhaps others are experiencing something different, but for me, the quoted text above was selected with visual mode. I tried pasting both with <c-v>, and with <s-INSERT>. No difference.

I believe the first letter gets copied in the primary clipboard.. and the entire content in the C-c clipboard..

Does anybody understand how that could happen? Code is here.

andmarti1424 commented 6 years ago

In my case, it is selected also, the thing is that is not yanked correctly..

hyiltiz commented 5 years ago

I think Tridactyl's interface to copy (yank) out text elements (e.g. paragraphs) is superb. It is simply hint mode for the elements, that looks like this: image

I imagine something like that isn't hard to create, as it is essentially the hint mode but instead of for links, it is for text elements (layered in div's etc.)

nathgit commented 4 years ago
  • type v
  • type / to search for the email
  • select the email using w or something like that
  • hit Esc to exit visual mode <---- this is my problem, b/c escape dismisses the dialogue
  • hit y to yank the text

after typing '/' & typing in the email to search, hit 'Enter' then hit 'y' to copy the selected text.

ghost commented 2 years ago

This is so complicated. The small things like these, preventing me to completely shift to keeb. I must have to use mouse to be on browser. There's no good way, even though I appreciate you guys developing great tools like vimium.

gdh1995 commented 2 years ago

Vimium now supports map xxx LinkHints.activateMode action=copy-text to copt text of links.

Hello, my customized version of Vimium, named Vimium C (https://github.com/gdh1995/vimium-c), has added LinkHints.activateModeToSelect to select any text slice and enter VisualMode, which might be more convenient. It has also LinkHints.activateCopyLinkText to select link and copy text directly.