Skip to content

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

License

Notifications You must be signed in to change notification settings

axelvc/template-string.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages