CofCat456 / template-string.nvim

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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

License:MIT License


Languages

Language:Lua 100.0%