• Stars
    star
    128
  • Rank 279,651 (Top 6 %)
  • Language
    Lua
  • License
    MIT License
  • Created about 2 years ago
  • Updated 9 months ago

Reviews

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

Repository Details

Neovim plugin to automatic change normal string to template string in JS like languages

Template String Converter

This plugin is inspired by the VS Code plugin: Template String Converted

Explanation

As soon as this plugin detects you're trying to use template strings (adding ${}) the quotes will be changed to backticks

Examples

Before           Input            After
----------------------------------------
'foo ${|'          }          `foo ${}|`

'bar $|}'          {          `bar ${|}`

'idk |{}'          $          `idk $|{}`
----------------------------------------

Demo video

Remove template string

Opposite function, remove backticks when there are no template strings

Remove template string demo

Requirements

Supported languages

  • Javascript / Typescript
  • JSX
  • Vue
  • Svelte
  • Python

Configuration

Example with the default config. If you prefer, you could call the setup function with partial or no config, and the default will be taken

require('template-string').setup({
  filetypes = { 'html', 'typescript', 'javascript', 'typescriptreact', 'javascriptreact', 'vue', 'svelte', 'python' }, -- filetypes where the plugin is active
  jsx_brackets = true, -- must add brackets to JSX attributes
  remove_template_string = false, -- remove backticks when there are no template strings
  restore_quotes = {
    -- quotes used when "remove_template_string" option is enabled
    normal = [[']],
    jsx = [["]],
  },
})

License

Licensed under the MIT license.