Coder Social home page Coder Social logo

open-editor's Introduction

open-editor

Open files in your editor at a specific line and column

Supports any editor, but only the following editors will open at a specific line and column:

  • Sublime Text
  • Atom
  • Visual Studio Code
  • VSCodium
  • WebStorm*
  • TextMate
  • Vim
  • NeoVim
  • IntelliJ IDEA*

*Doesn't support column.

Install

npm install open-editor

Usage

import openEditor from 'open-editor';

openEditor([
	{
		file: 'readme.md',
		line: 10,
		column: 2,
	}
]);

openEditor([
	'unicorn.js:5:3',
]);

API

openEditor(files, options?)

Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit unless you specify wait: true in the options.

files

Type: Array<string | object>

Items should be in the format foo.js:1:5 or {file: 'foo.js', line: 1: column: 5}.

options

Type: object

wait

Type: boolean
Default: false

Wait until the editor is closed.

import openEditor from 'open-editor';

await openEditor(['unicorn.js:5:3'], {wait: true});

console.log('File was closed');
editor

Type: string
Default: Auto-detected

The name, command, or binary path of the editor.

Only use this option if you really have to. Can be useful if you want to force a specific editor or implement your own auto-detection.

getEditorInfo(files, options?)

Same as openEditor(), but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal.

Example: {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false}

Can be useful if you want to handle opening the files yourself.

import {getEditorInfo} from 'open-editor';

getEditorInfo([
	{
		file: 'foo.js',
		line: 1,
		column: 5,
	}
]);
//=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false}

Related

open-editor's People

Contributors

bendingbender avatar coreyfarrell avatar gimenete avatar koenpunt avatar simenb avatar sindresorhus avatar snowmarble avatar sphinxknight avatar tandibar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

open-editor's Issues

Support editor guessing

Hey @sindresorhus thank you once again for another great package!

Currently users only benefit from this package, if their EDITOR env var is set.
But this doesn't have to be like that, since we can detect the editor automatically if no EDITOR env is set.

react-dev-utils/launchEditor.js implements such a feature.

What do you think about adding this functionality to open-editor or env-editor package? I believe this would be the right place.

@Timer What do you think about moving your code to open-editor?

Find out if it worked

If I have a typo (e.g. export EDITOR=cude) or I supply some spec that fails horribly it would be nice to know if it worked. E.g.

if (openEditor(['unicorn.js:5:3'])) {
  console.log('Editor opening working');
} else {
  console.warn('Editor opening failed');
}

Even better if it could be try { } catch instead of a boolean return.

Error using VS Code and Windows 10 / "Windows cannot find --goto"

Steps to reproduce:

  1. Set up the EDITOR environment variable to code on a Windows 10 machine with VS Code installed
  2. Run npm install open-editor in a directory
  3. Load a node console
  4. Import the package
  5. Use the function to open a file in the editor

Actual result:

A Windows error popup appears stating (pardon my French installation) "Windows cannot find '--goto'."

Expected result:

VS Code should spawn with the file opened

Additional information:

  • This is related to mdn/yari#2142 which I reproduced after following the instructions on mdn/content to contribute to the new MDN platform and after having set up a development environment with mdn/yari
  • I also use Git Bash and reproduce as well in that context

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.