I'd like to be able to send the HTML file I'm currently editing in vim
to my web browser, Chrome. I'm running Linux.
This gets me very close:
nmap <silent> <leader>w :!google-chrome % &
The browser opens and displays the correct file. However, the command isn't running in the background, which is what the &
is supposed to do. Instead vim
drops to the background and I get some text output to my terminal window. I then have to do some clicking and Enter
pressing to get my vim
to come back to the foreground.
Am I missing something?
UPDATE: Thanks for all the suggestions. The issue seems to be that the focus seems to shift away from my terminal window when the browser window opens. Not sure if there's anything I can do about this.
Launching Vim In order to launch Vim, open a terminal, and type the command vim . You can also open a file by specifying a name: vim foo. txt .
The command :Explore opens the file explorer window. Select a file or directory name and press Enter to open that file or directory. (For example :e /home/user displays the contents of that directory.) To return to the explorer window, press Ctrl-^ (usually Ctrl-6).
From my .vimrc:
nnoremap <F12>f :exe ':silent !firefox %'<CR>
nnoremap <F12>c :exe ':silent !chromium-browser %'<CR>
nnoremap <F12>o :exe ':silent !opera %'<CR>
These three commands open the current file in the chosen browser without side effects. The use of <F12>
makes it GVim-only, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With