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

1 Commit
 
 
 
 
 
 

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

  • Wrap template literals with {``} when inside JSX/TSX components.
  • Revert template literals to their original form when necessary.
  • Configurable options to enable/disable wrapping with {``}.

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",
    },
    config = function()
        require("template-string").setup()
    end,
}

Usage

Once installed, the plugin automatically wraps template literals with `` when editing JavaScript or TypeScript files. To use template literals, simply enclose your JavaScript or TypeScript expressions in ${}. For example:

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

On JSX/TSX components, the plugin will wrap template literals with {``}. For example:

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

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

Configuration

The setup function accepts an optional configuration object with the following options:

  • jsx_brackets boolean | nil: Enable/disable wrapping template literals with {``} inside JSX/TSX components. Defaults to true if not provided.
-- Default configuration
require('template-string').setup({
    jsx_brackets = true, -- Wrap template literals with {``} inside JSX/TSX components
})

License

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages