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

Ctrl+W closes browser tab #90

Open
soichih opened this issue Sep 21, 2015 · 3 comments
Open

Ctrl+W closes browser tab #90

soichih opened this issue Sep 21, 2015 · 3 comments

Comments

@soichih
Copy link

soichih commented Sep 21, 2015

When I am using vi on terminal, I usually open more than 1 files opened via ":sp" command. In order to toggle between different files inside vim is by pressing CTRL+W - which happens to be a key combinations for most browsers to close the current tab - no questions asked.

After a doing a bit of research / experiments, it looks like it's impossible to capture / preventDefault() the behavior of CTRL+W. I understand why browser makers adopted this policy, but I am a heavy vim user and I don't think I can live without having to use CTRL+W..

I don't know if there is any solution to this problem - other than not using :sp for vim (or remapping it to something other than CTRL+W..) but I just wanted to report this so that others might know different solutions to this problem.

@IonicaBizau
Copy link
Contributor

@soichih This is really browser specific. Term.js does try to prevent that and it works in Firefox, but not in Chrome. 😭

In web-term, I used before-leaving-me.js to prevent accidental page closing. By wrapping web-term into an Electron instance (e.g. Magnesium), this is not an issue, because the shortcut can be prevented.

To be fast enough when working in web-term (in browser) I added this in my .vimrc:

nnoremap <silent> <F12> :wincmd w<CR>

With F12 I can switch between splits/windows in VIM.
I had exactly the same problems like you. 😂 Hope it helps.

@soichih
Copy link
Author

soichih commented Feb 2, 2016

@IonicaBizau Thanks for the suggestion!

I tried to map Shift+w to do what Ctrl+w normal does, but I couldn't figure out.. Your mapping works, but do you happen to know how I can basically replace Ctrl+w with Shift+w?

Also, I've looked at the before-leaving-me.js.. it's very interesting! However.. there really isn't a way to detect browser leave event caused by user hitting Ctrl+w rather than closing it by clicking on the tab close button, or closing browsers, right?

Thanks again for your suggestions!

@IonicaBizau
Copy link
Contributor

there really isn't a way to detect browser leave event caused by user hitting Ctrl+w rather than closing it by clicking on the tab close button, or closing browsers, right?

That's correct. And it's actually fine, because you probably don't want to close the tab via click too, because you will lose your work. That's how most of terminals work: if you have a process somewhere, they will ask you if you really want to close the terminal.

In web-term I added something like this: term.on("close", window.close.bind(window)). That will close the tab when the terminal is closed.

Shift+w is obviously not something you want because that simply means uppercase W. 😂
But that's configurable: create (or edit existing) the ~/.inputrc file and add this in it:

Control-F: backward-kill-word

That means Ctrl + F will delete the last word. It does work in terminal, but not in VIM. I'm sure it's fixable by adding some shortcut in VIM, tho. 😄

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

2 participants