Skip to content

A simple Neovim plugin for efficiently handling template strings in JavaScript, TypeScript and JSX/TSX files.

License

Notifications You must be signed in to change notification settings

rxtsel/template-string.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

😸 template-string.nvim

template-string.nvim is a simple Neovim plugin for handling template strings in JavaScript and TypeScript files. It provides functionality to wrap template literals with {``} when inside JSX/TSX components and revert them back to their original form when necessary.

Features

  • Automatically wraps template literals with backticks `` when a ${} expression is added within single or double quotes in JavaScript or TypeScript files.
  • Wraps template literals with {``} when inside JSX/TSX components.
  • Reverts template literals to their original form when the ${} expression is removed.
  • Integration with nvim-treesitter for accurate detection and manipulation of JSX/TSX nodes, enhancing its functionality and precision.

Supported Languages

  • JavaScript
  • TypeScript
  • JSX
  • TSX

Installation

Install using your favorite package manager for Neovim. For example, using lazy.nvim:

{
    "rxtsel/template-string.nvim",
    event = "BufReadPost",
    dependencies = {
        "nvim-lua/plenary.nvim",
        "nvim-treesitter/nvim-treesitter",
    }
}

Usage

Once installed, the plugin automatically wraps template literals with backticks `...` when a ${} expression is added within single or double quotes in JavaScript or TypeScript files. For example, changing "Hello, ${name}" to `Hello, ${name}`. In JSX/TSX, it wraps with {``}.

JavaScript/TypeScript

const name = "World";
const greeting = `Hello, ${name}!`;
console.log(greeting);

JSX/TSX

const props = {
  name: "World",
};

<Test greeting={`Hello, ${props.name}!`} />;

License

This plugin is licensed under the MIT License. See the LICENSE file for details.