• Stars
    star
    710
  • Rank 63,323 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Live browser editing for Vim

Looking for a new owner

This plugin was much fun to build but it clearly needs more love than I am able to devote right now. If someone would like to take ownership of the project, email me or file a bug.

Browserlink.vim

Browserlink is a live browser editing plugin for Vim.

Live edit CSS

Browserlink allows you to live edit CSS files, which are sent to the browser on change, without reloading or changing the state of the page.

Live evaluate JavaScript

Browserlink allows you to evaluate buffers or selections of JavaScript directly, or even call individual functions within the buffer, for instant feedback in the browser.

New: Keep in sync with Chrome Inspector

The Chrome inspector allows you to set source maps from network resources to the local filesystem. In the latest version of Browserlink, you can set

window.__BL_OVERRIDE_CACHE = true

to disable the cache breaker. After setting up Chrome as desired, enable :set autoread and you'll get results like this:

Browserlink.vim staying in sync with Chrome inspector

How it works

Browserlink is very simple. The plugin itself hooks autocommands for file changes (and other things) to the provided functions. The functions connect through HTTP to a node.js backend, which your webpage connects also to. The entire process happens extremely fast.

Installation and Setup

To install, either download the repo, or as I would recommend, use Pathogen.

git clone git://github.com/jaxbot/browserlink.vim.git

If you haven't already, you'll need to install Node.js (Node is used to send refresh commands to your page(s))

Lastly, you need some javascript on your page(s) to listen for the refresh commands. For this there are two options:

  1. Add this script to your page(s)
<script src='http://127.0.0.1:9001/js/socket.js'></script>
  1. OR Use a GreaseMonkey script to inject the javascript into your project:

Userscript injection extensions/solutions:

Userscript template (update the @match rule to the url of your local project):

// ==UserScript==
// @name       Browserlink Embed
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      http://localhost/*
// @copyright  2012+, You
// ==/UserScript==

var src = document.createElement("script");
src.src = "http://127.0.0.1:9001/js/socket.js";
src.async = true;
document.head.appendChild(src);

I prefer the GreaseMonkey/Userscript method, as it's more universal and I don't have extra development junk in my projects. But it's totally up to you.

Usage

Once set up, Vim should now call the Node server whenever you save a .html, .js, .php, or .css file. Then just load up your web project like normal, and Vim should send signals over the websocket to reload the pages automatically. Nifty.

In addition:

:BLReloadPage

will reload the current pages

:BLReloadCSS

will reload the current stylesheets

:BLEvaluateBuffer

will evaluate the current buffer

You can also use be to evaluate selections or buffers, br to reload, and bc to reload stylesheets manually.

:BLConsole

An experimental feature that will print out console.log results from the webpage into a buffer. When in console mode:

  • i - shortcut to :BLEval
  • cc - clears console buffer
  • r - refreshes console buffer
  • <CR> - attempts to load the highlighted trace line

If you want to disable the overriding of console.log on your page, set:

window.__BL_NO_CONSOLE_OVERRIDE = true

:BLErrors

Load accumulated Javascript errors of the current session into the quickfix list

:BLClearErrors

Reset the error list.

If you want to get super efficient, you can hook an autocmd to when you leave insert mode (or other times) to reload, say, the stylesheets:

au InsertLeave *.css :BLReloadCSS

This function can be easily tweaked to fit your needs/workflow, and I highly recommend you do so to maximize your utility from this plugin.

Options

g:bl_no_autoupdate

If set, Browserlink won't try to reload pages/CSS when you save respective files.

g:bl_no_eager

If set, Browserlink won't autostart the server when a command is run and the server does not respond.

g:bl_no_mappings

If set, Browserlink won't map be, br, and bc commands.

g:bl_serverpath

Set if your server is not hosted on 127.0.0.1:9001. You will also need to change the socket.js file.

g:bl_urlpaths

A dictionary defining mappings from URLs to filesystem paths. Set this if you want to use the quickfix list for pages not accessed via a file://-URL.

g:bl_pagefiletypes

A list of filetype strings that should trigger automatic page reloads on write. Defaults to ['html', 'javascript', 'php'].

Notes

This is an experimental project, but it works really well for me, and I hope you enjoy it! I kept the source as simple as possible, and it's pretty easy to edit to your needs. I'm open to any suggestions, too, so let me know.

Shameless plug

I hack around with Vim plugins, so follow me if you're into that kind of stuff (or just want to make my day) ;)

More Repositories

1

semantic-highlight.vim

Semantic Highlighting for Vim
Vim Script
486
star
2

github-issues.vim

Github issue lookup in Vim
Python
405
star
3

syntastic-react

React.js JSX support for Syntastic
JavaScript
93
star
4

vimfiles

vim, tmux, zsh
Vim Script
61
star
5

selective-undo.vim

Selective undo for Vim
Vim Script
53
star
6

hangouts-bot

Node.js hangouts code
JavaScript
45
star
7

chrome-devtools.vim

Vim Script
24
star
8

ADB-File-Browser-OSX

AFT replacement for OSX
JavaScript
21
star
9

glass-prism

Google Glass Node.js framework
JavaScript
13
star
10

wph-seveneighter

C#
12
star
11

irssi-pushbullet-notifications

Quick Irssi script that redirects mentions and PMs to Pushbullet
Perl
11
star
12

glass-qrlens

QR Code scanner for Glass
Java
9
star
13

wear-LeafStatus

Quick Leaf Notifications app for Nissan Leaf cars
Java
9
star
14

quickglass

Quickly build voice triggers for Google Glass
Java
8
star
15

glass-barcode

Easy QR and barcode source for Google Glass
Java
5
star
16

gtop

Server monitoring and administration for Google Glass
JavaScript
5
star
17

udacity-car-projects

Projects from Udacity's Self-Driving Car Nanodegree
C++
5
star
18

glass-trello

Experimental Trello integration with Google Glass
JavaScript
5
star
19

colorpicker-windows-commandline

A quick color picker that can be called from the Windows command line. Returns the chosen color.
C#
5
star
20

medli

Source for my previous PHP-based blog
PHP
4
star
21

glass-mint

Mint.com integration for Glass
JavaScript
4
star
22

u2f-node-example

JavaScript
4
star
23

hubot-rain-alert

Live rain alerts for Hubot
CoffeeScript
4
star
24

orangemelt

A simple HTML5 collaboration game I made. Live: http://jaxbot.me/orangemelt
JavaScript
3
star
25

forthelazy

A series of "___ for the lazy" coding reference sheets
3
star
26

glass-lowbrightness

An experiment that puts Glass in low brightness mode to save power
Java
3
star
27

vim-getting-started

Getting Started Tutorial for the Vim Text Editor
CSS
3
star
28

reacterest

React.js and Flux example
JavaScript
3
star
29

wear-WearTap

Java
3
star
30

glass-vegeta

Ok Glass, what is his power level?
Groovy
3
star
31

epoch-to-human.vim

Quick conversion from Unix time to human time string. WIP.
Vim Script
2
star
32

moderate

JavaScript
2
star
33

cs-algorithms-multilang

Various practice algorithms in various languages, just cus.
C
2
star
34

glass-LeafControl

Java
2
star
35

vim-talk

JavaScript
2
star
36

PyconAutoWifi

Java
2
star
37

glasscoin

Proof of concept Bitcoin ticker for Glass using Mirror API
JavaScript
2
star
38

hubot-orlandodevs

CoffeeScript
2
star
39

uptime

Little uptime tracker for my RPi
JavaScript
2
star
40

glass-ucfwebcams

UCF Webcams on Glass
Java
2
star
41

dobble

A PHP social network site I made between Summer 2011 and 2012
PHP
2
star
42

wheresmysurface

Simple GPS/WiFi location tracking for Windows 8 devices. I use it for anti-theft of my Surface Pro 2
C#
2
star
43

android-contextual-examples

For a presentation
Java
1
star
44

reacterest-css-in-js

JavaScript
1
star
45

glass-presentation

Java
1
star
46

fizzfeed

Example blog in Koa using Harmony ES6 Node.js/Io.js
CSS
1
star
47

cat-classifier

Automatically determine which cat is eating all the food with Tensorflow
Python
1
star
48

SlackPack

Swift
1
star
49

macfiles

Shell
1
star
50

wiimote-presentation-remote

A userscript that allows using a Wii remote for presentations. Very hacky.
JavaScript
1
star
51

serverfiles

Random configurations I keep on my server
Nginx
1
star
52

tesla-cpo-history

JavaScript
1
star
53

hub.vim

Vim Script
1
star
54

minimal-vimrc

A minimal vimrc I wrote as part of a tutorial
Vim Script
1
star
55

my-lolcommits

Simple site for my lolcommits
PHP
1
star
56

wear-Vespr

When Vespr WiFi is detected, show a notification with your Vespr QR code on it.
Java
1
star
57

club

Club site
CSS
1
star
58

reactyl

JavaScript
1
star
59

knighthacks-git-tutorial

This is a fake repo that will be deleted.
1
star
60

spacebarteam

JavaScript
1
star
61

octoglass

JavaScript
1
star
62

viscendroid

Java
1
star
63

viscen

WIP home automation and monitoring stuff, specific to my setup mostly
PHP
1
star
64

test

A repository for testing various Github things
JavaScript
1
star