Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/axelvc/template-string.nvim
Neovim plugin to automatic change normal string to template string in JS like languages
https://github.com/axelvc/template-string.nvim
Last synced: 3 days ago
JSON representation
Neovim plugin to automatic change normal string to template string in JS like languages
- Host: GitHub
- URL: https://github.com/axelvc/template-string.nvim
- Owner: axelvc
- License: mit
- Created: 2022-08-12T01:53:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-26T02:38:57.000Z (11 months ago)
- Last Synced: 2024-08-02T13:33:22.286Z (3 months ago)
- Language: Lua
- Size: 35.2 KB
- Stars: 127
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Template String Converter
This plugin is inspired by the VS Code plugin: [Template String Converted](https://marketplace.visualstudio.com/items?itemName=meganrogge.template-string-converter)
## 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](https://gist.githubusercontent.com/axelvc/b34d7fd659e573d0622f25d32ac3388a/raw/2b76682d7af471359325677fbebb6fd1b72558d3/demo.gif)
### Remove template string
Opposite function, remove backticks when there are no template strings
![Remove template string demo](https://gist.githubusercontent.com/axelvc/b34d7fd659e573d0622f25d32ac3388a/raw/4761aab9cd46c8d8112e9aaf5900a139d46e7241/demo_2.gif)
## Requirements
- Neovim 0.7.0 or later
- [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) plugin## 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
```lua
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) license.