Skip to content

Instantly share code, notes, and snippets.

@mutewinter
Last active February 8, 2018 21:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutewinter/825f44bfd3aa810088ea5de2f61bad63 to your computer and use it in GitHub Desktop.
Save mutewinter/825f44bfd3aa810088ea5de2f61bad63 to your computer and use it in GitHub Desktop.
Magic Import for Vim UltiSnips

Magic Import for Vim UltiSnips

GIF of magic import in action

  1. Be a Vim user.
  2. Install UltiSnips.
  3. Add the code below to $YOUR_VIM_FOLDER/UltiSnips/javascript.snippets.
snippet ii "magic import" b
import `!p
def formatVariableName(path):
  parts = path.split('/')
  module = parts[0]
  if len(parts) > 1:
    return parts[-1]
  else:
    return re.sub(r'[_\-]', '', module.title())
snip.rv = formatVariableName(t[1])
` from '${1}';$0
endsnippet

Use ii<tab> to invoke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment