1

There are two common things I do when I code something. I either open that file in the browser or run it in node. So I'd like to create a couple of shortcuts inside vim to that effect.

I'd like F5 to open a new gnome terminal in the current directory and run http-server and then open up a new tab in firefox hitting port 8000.

Also, I'd like F6 to open a new gnome terminal and run nodemon and then open a new firefox tab and hit port 8000.

nnoremap <F5> :exe ':silent !firefox %'
nnoremap <F5> :exe ':silent !firefox %'

1 Answer 1

1

This may be better suited to the vi/vim stack over at vi.stackexchange.com

Note that the :silent tag negates hitting enter, so that has to be added after the set of commands to make it run in the command line. I had quite a bit of luck with the following.

:nnoremap <F5> :exe ':silent !firefox % 2>/dev/null &'^M^L

Please note that you have to hit ctrl-V to get the ctrl-M and ctrl-L bits at the end. Here is a quick rundown of what I added.

2>/dev/null to avoid dumping stderr to screen.
& to allow us to drop back to vim without waiting for firefox to finish
^M to execute the command
^L to initiate a redraw (the command frequently blacked out my screen)

Weirdly enough, without the stderr redirect, I just had to wait until firefox finished dumping errors to the screen and redraw again. Much easier to just trash those lines before they can display weird bits.

1
  • Here's what I ended up using: nnoremap <F5> :!gnome-terminal -e http-server <CR> :silent !firefox thinkmachine:8080<CR> <C-l> Worked really nicely. Just have to alt-tab-tab to get back. Apr 2, 2015 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .