Built-in Alternative to Vimium "F" shortcut?
-
Hi,
I have been trying to move a bit of my mouse work to the keyboard shortcuts and discovered Vimium in the process. Seeing that Vivaldi already has a robust keyboard shortcut system, is there a shortcut (or a way of creating one) that would act like the F shortcut in Vimium? I really like it how Vimium creates shortcuts to links all over the screen, but I am on a quest to keep my browser as extension-light as possible, so I wonder if something like this already exists in Vivaldi?
Thanks in advance, everyone.
-
@alvk said in Built-in Alternative to Vimium "F" shortcut?:
Vimium
Vivaldi effectively supports keyboard shortcuts and mouse gestures, which you can configure to your liking
> Shortcuts
-
Thank you for the reply. This is what the F button does in Vimium. It marks every link with a shortcut so you don't need a mouse at all. Literally. Does Vivaldi have anything like this?
-
Vivaldi has spatial navigation (which gets rarely mentioned as a unique feature): shift+arrows to select everything you want in a webpage.
-
@TalGarik
That's one thing I can't get to work. I saw it in the menus, but when I try it, nothing happens. Am I doing it wrong? -
Ok, I didn't realize I had to enable Spatial navigation in the settings. It's working properly and is indeed a kind of alternative to Vimium. However, I find Vimium a lot more efficient at figuring out all the possible buttons/links and it takes less time to get them pressed as all you have to do is to type the shortcut.
-
According to the devs, the Spatial Navigation in Vivaldi needs a lot of work and breaks some sites. I believe they turned it off by default a while back - which IMO was a stupid move as how will new users learn to use the keyboard more if they have to turn on the functions to do so first?
I agree the link highlighting feature in Vimium is great, and I wish Vivaldi had something similar. I see already you've created a feature request
As a workaround, I've installed the extension:
https://chrome.google.com/webstore/detail/spatial-navigation/gogippjaikoijhcdcioeajgpmlmchkbaThis has spatial nav + link highlighting. In fact the spatial nav works a lot better than Vivaldi's. But the default WASD felt wrong to me since I've used Shift+Arrows since forever - so I had to rewrite parts of it. And also to turn off the stupid always open link in background feature.
For instance to keep only the link highlighting you can edit it and remove everything else, just use the Vivaldi spatial nav.
-
@Pathduck
Indeed, I am one of those users who couldn't figure it out until I search for Spatial in the settings and so it was disabled. I also didn't realize it was considered somewhat broken by the dev team. I see why. It's far from perfect.The extension you recommended does spacial navigation a lot better. I like it. Actually, it does what I expect it to do most of the time. The link mapping is great, too. How did you change the open link behavior and edit the sttings? Do you need a lot of know-how for that? I'm not a github person.
-
@alvk Yes, I agree - this small extension, even if it's not been updated for a long time now (and probably won't be), still works better than the default navigation in Vivaldi. I hope that the devs take a look at the code and adapt it for their uses - I've mentioned it to them in another thread, not sure if they saw it though...
I changed some of the code to work how I wanted it since I want Shift+Arrows, and also Shift to open a tab in the background. I was not able to change it so that Shift open a new tab, while Ctrl opens in background (as is standard behaviour in all browsers), because I don't fully understand the code. But for me, it works, I usually open tabs in the background anyway. Just Enter opens a link the regular way at least.
To change it open this file in a good text editor:
c:\Users\<username>\AppData\Local\Vivaldi\User Data\Default\Extensions\gogippjaikoijhcdcioeajgpmlmchkba\0.4.7_0\dist\raw\spatial-navigation.js
Search for "function key2command", and replace it with this:
function key2command(event) { if (event.altKey || event.metaKey) { return 11 /* INVALID */; } if (event.shiftKey) { switch (event.keyCode) { case 37: /* ArrowLeft */ return 4; /* LEFT */ case 38: /* ArrowUp */ return 0; /* UP */ case 39: /* ArrowRight */ return 5; /* RIGHT */ case 40: /* ArrowDown */ return 2; /* DOWN */ case 81: /* Q */ return 10; /* QUIT */ case 69: /* E */ return 6; /* EXPAND */ case 13: /* Enter */ return 9; /* ENTER */ default: return 11; /* INVALID */ } } else if (event.ctrlKey) { switch (event.keyCode) { case 13: /* Enter */ return 9; /* ENTER */ default: return 11; /* INVALID */ } } else { switch (event.keyCode) { case 13: /* ENTER */ return 8; /* ENTER */ default: return 11; /* INVALID */ } } }
If you want something different you'd need to change it again, but I can help out a bit if you want. The logic should be pretty straight-forward. You can find the relevant keycodes here:
https://keycode.info/Since the extension is "never" updated it's pretty safe to do so, but if it ever gets updated you'd need to do it again, so take a backup when you've got it working as you want
-
@Pathduck
Thanks a lot! This is new to me, but thanks to your help, I figured it out. In fact, I just wanted to change the Enter-key behavior, which turned out to be as easy as swapping the left and right parts of the code responsible for that As a gamer, I am fine with the WASD navigation.=)Well, I hope Vivaldi devs do notice and implement this in the future.
-
@alvk Glad it worked out for you
Yeah, I tried to use WASD for a bit (a gamer as well) but Shift+Arrows is ingrained in my muscle memory when surfing so I had to completely change the function to deal with that, as somehow the keycodes didn't work out for me when using the arrows.
If anyone figures out how to make Shift+Enter open a new (focused) tab as opposed to a new (background) tab then please let me know!
-
@Pathduck
Since we are on the subject, did you figure out how to open the mapped links in the current tab rather than the background tab? I see that the mapped links open in the current tab if I hold Shift, but I'd like it the other way around. I have exhausted my knowledge of java after 15 minutes of going through the code...ADD
And it looks like I was wrong that swapping pieces of code solved my Enter issue. It works in button menus and on-page switches, but on links. Bummer. -
Well, the code is JavaScript, so by its very nature is a complete horrid mess. The developer also seems to have a complete disregard for helpful comments in the code, apart from a couple in kanji... Note also the very Ingrish usage of "LIBRALY" for "Library"
Changing the function of the Shift+Enter key should be editing the ENTER code line and swapping the 8 and 9 returns, like so (I think you've done this?):
EDIT: Actually leave this as-is, I was confused because I had to roll back to the vanilla version to test this.case 13 /* ENTER */: return event.shiftKey ? 9 /* ENTER_S */ : 8 /* ENTER */;
To change it so the marked links with E works as expected, change line 2780 and remove the not from before shiftKey:
click(cursor, shiftKey && !(cursor.tagName.toLowerCase() === 'a' && cursor.getAttribute('href') === '#'));
What they're originally doing there's REALLY BAD practice btw, to negate a boolean on function input, it makes no f-in sense and confuses everyone to no end. Something is either true or false, not (not)true or (not)false.
They're probably a very good programmer, just certainly very eccentric
I'm looking into how to make Ctrl/Shift work as expected, Ctrl is new background tab, Shift is new focused tab, will keep you posted.
-
@Pathduck
Wow, thanks for that. That'll take me a while to digest. JavaScript is gibberish to me, and that technical language you use is Greek. I'll do my best) I wish I could help you with your predicament, but that's beyond my expertise) -
@alvk said in Built-in Alternative to Vimium "F" shortcut?:
@Pathduck
Wow, thanks for that. That'll take me a while to digest. JavaScript is gibberish to me, and that technical language you use is Greek. I'll do my best) I wish I could help you with your predicament, but that's beyond my expertise)Yeah, sorry, I tend to do that
By "removing the not" I mean removing the '!' in front of it. You can just leave the "case 13" clause (see, there I go again lol!), as it originally was: 9 first, then 8.
-
Update: I've had some time this afternoon to play around with it. Here's what I've got so far, and I think it works much better now. I moved back to using WASD - might as well give it a chance.
Changes
- Added 'F' (with Ctrl & Shift) key as alternative to Enter ("Follow link") for when you want to keep your other hand on the mouse. Note: This will break Ctrl+F for Find in Page, so if you don't like it, comment out the "// F" lines from the key2command function. F3 still works for Find.
- Added support for Ctrl+link to follow browser standard of opening link in background tab.
- To accomplish the above, replaced the Shift+E command for "Contract" which is rarely used. It still works for some reason, probably it operates on a different level in the code.
- Some minor CSS styling on the cursor, and the URL display at bottom to match dark theme. Can be changed in function displayUrl().
- Removed the Shift+WASD keys as I had no idea what they were used for. Can be easily added in now that the code is cleaner.
Note
- For some reason pressing 'Q' when highlighting links sometimes scrolls the page to the bottom. No idea why, it also does so in the vanilla version. To avoid, just use ESC to quit link-highlight mode.
Pastebin:
https://pastebin.com/igYwrvWC -
@Pathduck
Thank you. This is certainly much better than the default version) You should probably upload it to the Chrome store with credit to the original creator. He or she should be proud his/her work lives on through generations):smiling_face_with_open_mouth_cold_sweat: -
For those who like Vim-style navigation, I can recommend Surfingkeys.
I tried Vimium -> cVim -> Surfingkeys, and Surfingkeys is the best one in my opinion.
-
@Avi
Thanks! It is definitely more user-friendly than Vimium. Going to take it for a spin for a few days. -
@Pathduck Is there something you could do so I can easily disable/re enable spatial nav w/ this extension? Some things I want to do need the w/a/s/d/f/e keys. Totally fine if not, so don't worry about it