Skip to content

Lightning-fast TypeScript/React component restructuring for Neovim - seamlessly nest and unnest your components with a single command.

License

Notifications You must be signed in to change notification settings

harisb2012/tsnest.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

tsnest.nvim

🪺 Lightning-fast TypeScript/React component restructuring for Neovim - seamlessly nest and unnest your components with a single command.

Features

  • 📁 Nest components into folder structures (Component.tsxComponent/index.tsx)
  • 📄 Unnest folder components into files (Component/index.tsxComponent.tsx)
  • 🌳 Seamless NvimTree integration
  • ⚡ Zero configuration needed
  • 🛡️ Safe operations with validation checks
  • 🧠 Smart buffer handling

Installation

Using vim-plug

Plug 'nvim-tree/nvim-tree.lua' " Required dependency
Plug 'harisb2012/tsnest.nvim'
use {
  'harisb2012/tsnest.nvim',
  requires = {
    'nvim-tree/nvim-tree.lua'
  }
}

Using lazy.nvim

{
  'harisb2012/tsnest.nvim',
  dependencies = {
    'nvim-tree/nvim-tree.lua'
  }
}

Setup

require('tsnest').setup({
  -- Optional configuration (shown with defaults)
  commands = {
    nest = 'TsNest',     -- Command to nest file into folder
    unnest = 'TsUnnest'  -- Command to unnest folder into file
  },
  -- Coming soon:
  -- auto_format = true,     -- Format file after transformation
  -- notify = true,          -- Show notifications
  -- patterns = {            -- Custom file patterns
  --   index = "index",      -- Default index file name
  --   extensions = {"ts", "tsx"} -- Supported file extensions
  -- }
})

Usage

  1. Nesting a component into a folder

    • Open a .ts/.tsx file or hover over it in NvimTree
    • Run :TsNest
    • Button.tsx becomes Button/index.tsx
  2. Unnesting a folder component into a file

    • Open an index.ts/index.tsx file or hover over it in NvimTree
    • Run :TsUnnest
    • Button/index.tsx becomes Button.tsx

Both commands work seamlessly:

  • From the buffer with the file open
  • From NvimTree with cursor over the file

Why tsnest.nvim?

Modern React/TypeScript projects often require restructuring components as they evolve - adding styles, tests, or sub-components means converting a single file into a folder structure. This usually involves multiple manual steps: creating directories, moving files, renaming, and updating imports. tsnest.nvim makes this instantaneous and foolproof.

Coming Soon

  • Auto-formatting after transformation
  • Custom patterns support
  • Multi-file folder support
  • Undo/redo stack
  • LSP workspace refresh
  • Integration with other file explorers

Contributing

Contributions welcome! Feel free to submit issues and pull requests.

License

MIT

About

Lightning-fast TypeScript/React component restructuring for Neovim - seamlessly nest and unnest your components with a single command.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages