user16948
user16948

Reputation: 4951

Mapping Alt+Tab in Vim

In Vim, I have mapped F9 key to :w<CR>. After pressign F9, I usually switch back to firefox to see the result. is it possible to map a key to Alt+Tab so I can save the file and switch, with pressing a single key? for example nmap :w<Cr><M-Tab>

Upvotes: 2

Views: 2867

Answers (1)

Conner
Conner

Reputation: 31040

Vim handles vim keybindings, not system keybindings. So in short, no you can't do that. However, you can use something else to accomplish this. For example xdg-open on Linux or open on Mac are the standard "use the default program to open this" commands. You could use this to open the current file (or a link) in your web browser.

nnoremap <F9> :w<CR>:!open %<CR>

or

nnoremap <F9> :w<CR>:!open http://mysite.com<CR>

If you're on a mac you could use some AppleScript via osascript to simply "activate" Firefox if you don't want to open a new window. I'm sure there's something similar for Linux it's just been a couple years since I've had to do that.

Upvotes: 1

Related Questions