14

I have some online tutorial open in my Google chrome. It tells me to run some commands in a terminal.

My current workflow is to select the necessary parts via mouse, and insert the copied text via middle mouse click in a terminal.

I want to to avoid using the mouse at most instances, so I want to highlight text on a web page by only using the keyboard instead. I want for the text to be automatically saved into the buffer similar to mouse selection, yet even then being able to ctr+c without selecting text with the mouse would be fine.

Is there a mode in Chrome for that purpose?

16

As I am a user of vimium, it turns out I had the capabilities already shipped with it even though I wasn't aware that it existed.

  • Search the starting point by: /yourSeach
  • Press enter.
  • Enable visual mode via: v, and visual mode on a line basis via Shift + V
  • Select text by vim navigation keys, aka: h, j, k, l, b, e, w, $ (I especially like shift + w, as it goes to the end of the next word)
  • Yank via y

You now can switch the context and paste the text via Ctrl+V

There also seems to be a caret mode, yet as of yet I somtimes don't see the current place of the cursor, which is why I prefer the search-first approach as of now.

  • Oh my! That is amazing! Thanks for sharing this gem! I have been for this for a long time! I even created a Keyboard Maestro macro but your solution is even better! – politicus Jul 26 at 11:23
  • Quite a few permissions required though. – Jesus Iniesta Sep 6 at 11:56
  • @JesusIniesta They need those though to work: github.com/philc/vimium/issues/366#issuecomment-210642835 – k0pernikus Sep 6 at 12:05
  • @JesusIniesta On their webstore page they even say: "NOTE Chrome has some alarmist messaging around the permissions that Vimium needs to run. Really all it's asking for is that Vimium's javascript be loaded into every page. Don't be alarmed. Vimium never talks to any servers and does absolutely nothing with your data. Read the open source code if you're curious." – k0pernikus Sep 6 at 12:07
3

Use the arrow keys to navigate the page.

To highlight text on a page with a keyboard use Shift and a direction, up is up a line down is down a line. Left is left one character and right is right one character.

Copy is Ctrl + C and paste is Ctrl + V.

The only way I could find to move the selection cursor is using find to highlight the first word of the text you want to copy, press Ctrl + F, type your word, to highlight it in the page and press ESC to leave find then use the Shift plus arrows to highlight the rest.

Finally to swap from Chrome to a Terminal use Alt + Tab

  • OP wants to know how to highlight text without using the mouse to select it, ie. just with the keyboard... – TellMeWhy Nov 5 '15 at 12:52
  • 1
    @DevRobot, that's what I gave them :) – Mark Kirby Nov 5 '15 at 12:53
  • No work :( - the keyboard needs to find a focus to be able to highlight text... – TellMeWhy Nov 5 '15 at 12:54
  • Could it be that you have an extension running that provides this feature? As what you are describing is not working for me. – k0pernikus Nov 5 '15 at 13:11
  • No the issue is that the selection curser must be focused on the text you want to highlight, as pointed out by @DevRobot this means that this is not work for keyboard only as you must click some text first to highlight it. Only work around I can find is using the find option, I will add to answer but if it is not sufficient please say and I will remove. – Mark Kirby Nov 5 '15 at 13:15
0

There's an Google supported extension called Caret Browsing among other extensions to improve accessability.

It toggles via F7 like in Firefox. Though I still find text selection to be a bit flunky on some pages, it works for most basic use cases.

0

this tampermonkey script toggles contentEditable

in that mode you navigate to the desired text and select it with keyboard - as in standard text editor

// ==UserScript==
// @name         Toggle ContentEditable
// @namespace    http://tampermonkey.net/
// @version      0.1
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var range;

    document.addEventListener('keydown', function(e) {
        if (e.keyCode == 12 && e.ctrlKey && e.altKey) // CTRL + ALT + NumPadCenter
        {
            if (!document.body.getAttribute("contenteditable"))
            {
                document.body.setAttribute("contenteditable", "true");

                var selection = window.getSelection();
                selection.removeAllRanges();
                if (!range) range = document.createRange();
                var el = document.elementFromPoint(window.innerWidth/2, window.innerHeight/2);
                if (!el) el = document.body;
                range.setStart(el, 0);
                range.collapse(true);
                selection.addRange(range);
            }
        }
        else if (e.keyCode == 27  // ESC
                 && document.body.getAttribute("contenteditable"))
            document.body.removeAttribute("contenteditable");
    });

})();

I use it when I read books in foreign languages and have to frequently copy-paste some words to the dictionary

Ctrl+Alt+NumPadCenter turns it ON ESC turns it OFF (i.e. returns to regular browsing)

To change key combinations to whatever you prefer, edit lines that have respective comments next to them.

When you turn in ON, script places caret at the beginning of the element (usually paragraph) that is in the center of the browser window.

Googling led me to this page and the solutions proposed seemed overkill, so here it is.

  • @mook765 This is a tampermonkey script. Install tampermonkey Chrome extension, in that extension's dashboard add new script and copypaste this code into it. – jaborandi Sep 28 '16 at 9:44
  • @jaborandi Tried your script. Had an alert message "line 31 Expected { after 'if' condition". Didn't see any caret at the beginning of any element. – politicus Aug 26 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.