*vim-javascript-imports.txt* Easily Maintain Ember Import Statements CONTENTS 1. Intro ...................... |JavaScriptImportsIntro| 2. Command .................... |:JSImport| 3. Mapping .................... |JavaScriptImportsMapping| 4. Configuration .............. |JavaScriptImportsConfig| 5. Adding Import Definitions... |:JSAdd| |JSAddImport()| 6. License .................... |JavaScriptImportsLicense| 7. Contributing ............... |JavaScriptImportsContributing| ============================================================================== 1. Intro *JavaScriptImportsIntro* Keep your import statements in sync with your code by appending or updating statements with defined keywords. The intended audience for this are JavaScript developers who use Vim and want to automate the look up process when it comes to import statements. With this plugin Vim will update the import list for you. By looking up the import statement for a keyword under the cursor and either adding it or updating the current one to have the new keyword. You can manually add import definitions or use a compatible plugin which defines import definitions for you. ============================================================================== 2. :JSImport *:JSImport* Import statements can be added/updated via a command. The first argument is the JavaScript keyword you wish to add. It has auto completion for all the defined keywords. If you leave the keyword blank it will take the word under the cursor. Usage: > :JSImport [KEYWORD] < Examples: > :JSImport < Will lookup the keyword under the cursor and add/update the import statement list at the top of the file. > :JSImport Component < Will add this if it doesn't already exist: import Component from '@ember/component'; ============================================================================== 3. Mapping *JavaScriptImportsMapping* For convenience a mapping can be used to grab the keyword under the cursor and execute the |:JSImport| command for you. By default this is "e". The map can be adjusted or disabled. See |JavaScriptImportsConfig| for more on this. ============================================================================== 4. Configuration *JavaScriptImportsConfig* Mapping You can set the map that triggers the imports plugin. > let g:vim_javascript_imports_map = 'e' < To disable set to 0. > let g:vim_javascript_imports_map = 0 < Disable Semicolons You can disable the use of semicolons by setting this to 0. (Default 1) > let g:vim_javascript_imports_use_semicolons = 0 < Definition Wrapping To make code easier to read this plugin will break long a import statement across multiple lines. Long lines are defined by how many destructuring variables there are and how long the line is. For example by default if you have more then 3 variables defined it will reformat the line like so: import DefaultVar, { var1, var2, var3, var4 } from 'foobar'; This number can be adjusted (0 to disable): > let g:vim_javascript_imports_multiline_max_vars = 3 < Alternatively if the line has less then that number of variables but still exceeds a maximum column (default: 80) it can split the line in two. import DefaultVar, { var1, var2, var3 } from 'foobar'; This can be adjusted (0 to disable): > let g:vim_javascript_imports_multiline_max_col = 80 < Import Sorting If you create a function called `JavaScriptImportSort` in your .vimrc it will run after the import has been added. For example this will call into https://github.com/ruanyl/vim-sort-imports > function JavaScriptImportSort() silent exec "w" call import_sort#run() endfunction < ============================================================================== 5. Adding Import Definitions *:JSAdd* Import definitions can be added in two ways. Easiest is to use the |:JSAdd| command. > :JSAdd import [IMPORT NAMES] from [IMPORT FROM] < Example: > :JSAdd import { foo } from bar < Will add the foo keyword and definition to the database and make it available via the |:JSImport| command. Because this command will parse the import statement doing this for a large set of definitions could slow down Vim while it loads. To avoid a performance hit for large sets you can alternatively add the definitions manually with |JSAddImportDefinition()|. *JSAddImport()* You can also call a function if it is more convinient with |JSAddImport()|. > :call JSAddImport('import [IMPORT NAMES] from [IMPORT FROM]') < Example: > :call JSAddImport('import { foo } from bar') < Will add the foo keyword and definition to the database and make it available via the |:JSImport| command. Because this function will parse the import statement doing this for a large set of definitions could slow down Vim while it loads. To avoid a performance hit for large sets you can alternatively add the definitions manually with |JSAddImportDefinition()|. *JSAddImportDefinition()* The function |JSAddImportDefinition()| will allow you to add definitions without parsing the import string. The function takes a |Dictionary| with the following keys: name, default, from, and aliased. name (string) - The name used to lookup an import. default (number) - 0 for this definition to be defined inside the { brackets } - 1 for this definition to be defined as a default import from (string) - The module name / file path for this definition aliased (string) (optional) - The actual name to import. The name above will be used with "as" Example: > call JSAddImportDefinition({"name": "foo", "default": 1, "from": "bar"}) < Will add the foo keyword and definition to the database and make it available via the |:JSImport| command. And would result in the following import statement when completed: > import foo from 'bar'; < Example: > call JSAddImportDefinition({ \ "name": "foo", \ "default": 0, \ "from": "bar", \ "aliased": "baz" \ }) < Will add the foo keyword and definition to the database and make it available via the |:JSImport| command. And would result in the following import statement when completed: > import { baz as foo } from 'bar'; < ============================================================================== 6. License *JavaScriptImportsLicense* Released under the MIT License. ============================================================================== 7. Contributing *JavaScriptImportsContributing* Contributions are welcomed and appreciated. Just follow the normal Github procedure. Go to: https://github.com/sukima/vim-javascript-imports Fork the project. Work on what you think would make it better. Send a pull request.