GitPedia

Nvim treesitter cpp tools

C++ Helper Snippets Using Treesitter

From Badhi·Updated April 22, 2026·View on GitHub·

Experimental treesitter based neovim plugin to create intelligent implementations for C++ The project is written primarily in Lua, distributed under the Apache License 2.0 license, first published in 2021. Key topics include: cpp, lua, neovim, nvim, nvim-treesitter.

nt-cpp-tools

Unit Tests

Experimental treesitter based neovim plugin to create intelligent implementations for C++

Features

  1. Out-of class member function implementation
  2. Concrete class implement from Abstract class or Interface
  3. Add missing functions to obey Rule of 3
  4. Add missing functions to obey Rule of 5

Install

Using paq

lua
require "paq" { "nvim-treesitter/nvim-treesitter", "Badhi/nvim-treesitter-cpp-tools", }

Using packer.nvim

lua
use { requires = { "nvim-treesitter/nvim-treesitter" }, "Badhi/nvim-treesitter-cpp-tools", }

Using lazy.nvim

lua
{ "Badhi/nvim-treesitter-cpp-tools", dependencies = { "nvim-treesitter/nvim-treesitter" }, -- Optional: Configuration opts = function() local options = { preview = { quit = "q", -- optional keymapping for quit preview accept = "<tab>", -- optional keymapping for accept preview }, header_extension = "h", -- optional source_extension = "cpp", -- optional custom_define_class_function_commands = { -- optional TSCppImplWrite = { output_handle = require("nt-cpp-tools.output_handlers").get_add_to_cpp(), }, --[[ <your impl function custom command name> = { output_handle = function (str, context) -- string contains the class implementation -- do whatever you want to do with it end } ]] }, } return options end, -- End configuration config = true, }

Setup

For lazy.nvim, see Install

Add the following config to your init script

Note: The config for this plugin, included in the treesitter.config is now moved to an independent config. Please make required changes

lua
require 'nt-cpp-tools'.setup({ preview = { quit = 'q', -- optional keymapping for quit preview accept = '<tab>' -- optional keymapping for accept preview }, header_extension = 'h', -- optional source_extension = 'cxx', -- optional custom_define_class_function_commands = { -- optional TSCppImplWrite = { output_handle = require'nt-cpp-tools.output_handlers'.get_add_to_cpp() } --[[ <your impl function custom command name> = { output_handle = function (str, context) -- string contains the class implementation -- do whatever you want to do with it end } ]] } })

Usage

  • Select the range of the class using visual mode
  • Use below commands
CommandFeature
TSCppDefineClassFuncImplement out of class member functions<br><br> subset of functions can be implemented by selecting required function declarations using visual mode or simply keeping the cursor on the function declaration before calling the command<br><br>Supported special features<br>1. Templates (with default args)<br>2. Function arguments with default values<br>3. Nested classes<br>(check test_cases for tested examples)
TSCppMakeConcreteClassCreate a concrete class implementing all the pure virtual functions
TSCppRuleOf3Adds the missing function declarations to the class to obey the Rule of 3 (if eligible)
TSCppRuleOf5Adds the missing function declarations to the class to obey the Rule of 5 (if eligible)

Example

  1. TSCppDefineClassFunc

TSImplementFunc

  1. TSCppMakeConcreteClass

TSConcreteClass

  1. TSCppRuleOf3

TSRuleOf3

Contributors

Showing top 7 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from Badhi/nvim-treesitter-cpp-tools via the GitHub API.Last fetched: 6/27/2026