Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
update vim-for-javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
David O'Trakoun committed Jan 12, 2016
1 parent a73437a commit ee240b4
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions md/_posts/vim-for-javascript.md
Expand Up @@ -13,6 +13,12 @@ tags:


### Updates ### Updates


- Jan 12, 2016 ([diff]())
> Make sure plugin names are all linkified. Add more notes on what the
> indent plugins do.
> Added example of multi-omni-completion for neocomplete.
> Some language changes.
- Jan 11, 2016 ([diff](https://github.com/davidosomething/16.davidosomething.com/commit/0eb309472728f5855823d4d1b35bf4e52e524d7b)) - Jan 11, 2016 ([diff](https://github.com/davidosomething/16.davidosomething.com/commit/0eb309472728f5855823d4d1b35bf4e52e524d7b))
> Update omni-completion with basic info on how `omnifunc` works and > Update omni-completion with basic info on how `omnifunc` works and
> added [1995eaton/vim-better-javascript-completion]. > added [1995eaton/vim-better-javascript-completion].
Expand Down Expand Up @@ -64,19 +70,19 @@ There are quite a few options:
- Does not include custom indent settings - Does not include custom indent settings
- Updated about once a month according to the GitHub contributors graph - Updated about once a month according to the GitHub contributors graph
- [othree/yajs.vim] - [othree/yajs.vim]
- This is a fork of `jelera/vim-javascript-syntax` - This is a fork of [jelera/vim-javascript-syntax]
- Does not include custom indent settings - Does not include custom indent settings
- Updated very often - Updated very often to keep in line with ES specifications
- [sheerun/vim-polyglot], or [sheerun/yajs.vim] - [sheerun/vim-polyglot], or [sheerun/yajs.vim]
- This is a plugin that bundles a bunch of language syntax plugins into one. - This is a plugin that bundles a bunch of language syntax plugins into one.
It particularly includes `sheerun/yajs.vim`, which is an outdated mirror It particularly includes `sheerun/yajs.vim`, which is an outdated mirror
of `othree/yajs.vim`. of `othree/yajs.vim`.


All of these provide ES2015 (ES6) and JSDoc support to varying degrees. Of **All of these provide ES2015 (ES6) and JSDoc support to varying degrees**,
these, I personally use and recommend `othree/yajs.vim` since it has most which Vim lacks be default. I personally use and recommend [othree/yajs.vim]
up-to-date language support. The author also writes a few other plugins that can since it has most up-to-date language support. The author also writes a few
be used in conjunction with it (although they may work with the other syntaxes other plugins that can be used in conjunction with it (although they may work
too. with the other syntaxes too).


Using [vim-plug], I recommend installing the plugin like this: Using [vim-plug], I recommend installing the plugin like this:


Expand All @@ -92,26 +98,34 @@ will have already run, and the plugin's syntax will override it.
### Plugins that provide better indentation support ### Plugins that provide better indentation support


Vim's bundled JavaScript indent may be enough for you, especially if you use Vim's bundled JavaScript indent may be enough for you, especially if you use
a strictly C-style whitespace (Vim's indent options even call themselves a strictly C-style whitespace (Vim's C-style indent options is even called
`cindent`). `cindent`).


Some notable options in this case are: Some notable options in this case are:


- [pangloss/vim-javascript] - [pangloss/vim-javascript]
- Using this entire syntax plugin will provide you with a more JavaScripty - Using this entire syntax plugin will provide you with a more JavaScripty
indent for things like switch/case and multi-line var declarations. indent for things like switch/case and multi-line var declarations.
- This indent plugin has a side-effect in that it also changes the format
expression -- that is, if you highlight a block and use `gq` to reformat
it, it will re-indent the code using this plugin as well.
- [gavocanov/vim-js-indent] - [gavocanov/vim-js-indent]
- This is the indent portion of `pangloss/vim-javascript`, ripped out into - This is the indent portion of [pangloss/vim-javascript], ripped out into
its own plugin. its own plugin.
- There are modifications to it, diverging it from
[pangloss/vim-javascript], notably support for the syntax group names in
[othree/yajs.vim]. That helps it pick out keywords and when you are
inside comments if you are using [othree/yajs.vim].
- The format expression from the original has been removed.
- [itspriddle/vim-javascript-indent] - [itspriddle/vim-javascript-indent]
- This is a git mirror of [Ryan Fabella's indent script] - This is a git mirror of [Ryan Fabella's indent script]
- It mostly detects closing brackets and parentheses and indents based on - It mostly detects closing brackets and parentheses and indents based on
that. what it finds.
- [jiangmiao/simple-javascript-indenter] - [jiangmiao/simple-javascript-indenter]
- An indent plugin with an option for alignment under functions. - An indent plugin with an option for alignment under functions.


Since I use `othree/yajs.vim` for my syntax, I tack on pangloss's indent via the Since I use [othree/yajs.vim] for my syntax, I use [gavocanov/vim-js-indent]
`gavocanov/vim-js-indent plugin`. for improved indenting.


## Related syntaxes ## Related syntaxes


Expand Down Expand Up @@ -156,16 +170,16 @@ Plug 'elzr/vim-json'
### JSDoc ### JSDoc


If you document using JSDoc, all of the syntax plugins above support JSDoc If you document using JSDoc, all of the syntax plugins above support JSDoc
already. There's a plugin called `othree/jsdoc-syntax.vim` that pulls that already. There's a plugin called [othree/jsdoc-syntax.vim] that pulls that
support out of `othree/yajs.vim`, but it is only for adding JSDoc support to support out of [othree/yajs.vim], but it is only for adding JSDoc support to
_other_ languages like TypeScript. _other_ languages like TypeScript.


- [othree/jsdoc-syntax.vim] - [othree/jsdoc-syntax.vim]


### jQuery Plugins ### jQuery Plugins


Files named `jquery.*.js` are typically jQuery plugins. There's a specific Files named `jquery.*.js` are typically jQuery plugins. There's a specific
syntax highlighting plugin for such files: `itspriddle/vim-jquery`, but it's syntax highlighting plugin for such files: [itspriddle/vim-jquery], but it's
pretty old and you'll have better support combining an up-to-date syntax plugin pretty old and you'll have better support combining an up-to-date syntax plugin
with the JavaScript libraries plugin in the next section. with the JavaScript libraries plugin in the next section.


Expand Down Expand Up @@ -206,9 +220,19 @@ menu, caching of keywords, and integration with other sources of completion
(allowing for multiple `omnifunc`s) than what's in the current Vim buffer. (allowing for multiple `omnifunc`s) than what's in the current Vim buffer.


For portability across my systems without needing a recompile, I use For portability across my systems without needing a recompile, I use
`Shougo/neocomplete.vim`. They're both offer roughly the same feature set, [Shougo/neocomplete.vim]. They're both offer roughly the same feature set,
though, so whatever might be missing in one can probably be configured into it. though, so whatever might be missing in one can probably be configured into it.


With [Shougo/neocomplete.vim], using multiple sources of completion can be done
by providing a list of function names like so:

```viml
let g:neocomplete#sources#omni#functions.javascript = [
\ 'jspc#omni',
\ 'tern#Complete',
\ ]
```

### Extended omni-completion ### Extended omni-completion


The plugin [1995eaton/vim-better-javascript-completion] provides a somewhat The plugin [1995eaton/vim-better-javascript-completion] provides a somewhat
Expand Down Expand Up @@ -277,7 +301,7 @@ default completion is (typically `javascriptcomplete#CompleteJS`).


### Jumping between CommonJS modules ### Jumping between CommonJS modules


The plugin [moll/vim-node] adds keybindings for jumping to files in your The plugin [moll/vim-node] adds keybindings like for jumping to files in your
CommonJS `require` statements. CommonJS `require` statements.


```viml ```viml
Expand Down Expand Up @@ -320,7 +344,7 @@ an option.


## Formatting ## Formatting


Vim has a built-in reformatter for whitespace. Visually select some text and Vim has a built-in re-formatter for whitespace. Visually select some text and
use the `=` key to re-indent all of it. use the `=` key to re-indent all of it.


For minified JS, there's a vim plugin, [vim-jsbeautify], that can run your code For minified JS, there's a vim plugin, [vim-jsbeautify], that can run your code
Expand All @@ -334,8 +358,8 @@ something.


You can dig through [my Vim configuration on GitHub]. The plugins I use are You can dig through [my Vim configuration on GitHub]. The plugins I use are
all in the main `vimrc` file, and their configurations are interspersed into all in the main `vimrc` file, and their configurations are interspersed into
`plugin/`, `ftplugin/`, and `after/*/` to cope with the order in which Vim loads `plugin/`, `ftplugin/`, and `after/*/` to cope with the order in which Vim
files. loads files.


- [my Vim configuration on GitHub] - [my Vim configuration on GitHub]


Expand Down

0 comments on commit ee240b4

Please sign in to comment.