{"id":25219450,"url":"https://github.com/jakobknauer/cppswitch","last_synced_at":"2026-04-30T20:31:04.734Z","repository":{"id":238316541,"uuid":"796204615","full_name":"jakobknauer/cppswitch","owner":"jakobknauer","description":"A Neovim plugin for switching between a C++ header file and the corresponding implementation file","archived":false,"fork":false,"pushed_at":"2024-05-05T14:07:55.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T20:55:47.886Z","etag":null,"topics":["c","cpp","neovim","neovim-plugin"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakobknauer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-05T08:55:55.000Z","updated_at":"2024-05-05T14:09:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"15b92703-6314-442e-a418-0e1e597aaaf9","html_url":"https://github.com/jakobknauer/cppswitch","commit_stats":null,"previous_names":["jakobknauer/cppswitch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jakobknauer/cppswitch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakobknauer%2Fcppswitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakobknauer%2Fcppswitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakobknauer%2Fcppswitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakobknauer%2Fcppswitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakobknauer","download_url":"https://codeload.github.com/jakobknauer/cppswitch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakobknauer%2Fcppswitch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32476682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","neovim","neovim-plugin"],"created_at":"2025-02-10T21:08:52.121Z","updated_at":"2026-04-30T20:31:04.728Z","avatar_url":"https://github.com/jakobknauer.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intro\n\n`cppswitch` is a Neovim plugin for switching between a C++ (or C) header file and the corresponding implementation file,\nor creating the corresponding file if it doesn't exist.\n\nIt is able to handle both situations where header and implementation are located in the same directory,\nand where they are in separate \"src\" and \"include\" (names configurable) directories, called \"twin directories\" in what follows.\n\n\n# Setup\n\n1. Install the plugin, e.g. using vim-plug:\n\n```lua\nlocal Plug = vim.fn[\"plug#\"]\nvim.call(\"plug#begin\")\nPlug \"jakobknauer/cppswitch\"\nvim.call(\"plug#end\")\n```\n\n2. Setup\n\n```lua\nrequire(\"cppswitch\").setup()\n```\n\n3. Configure\n\nAdapt some global variables to modify the behavior of the plugin.\nThe following are the default values - if you're happy with them, skip this step.\nSee below for details on the behavior, and how the 'twin directory' mechanic works.\n\n```lua\n-- File extensions that indicate header files\nvim.g.cppswitch_header_extensions = {\"h\", \"hpp\", \"hh\", \"h++\", \"hxx\", \"H\"}\n-- File extensions that indicate implementation files\nvim.g.cppswitch_impl_extensions = {\"c\", \"cpp\", \"cc\", \"c++\", \"cxx\", \"C\"}\n\n-- The file extension to use for creating a header file, when none exists\nvim.g.cppswitch_preferred_header_extension = \"h\"\n-- The file extension to use for creating an implementation file, when none exists\nvim.g.cppswitch_preferred_impl_extension = \"cpp\"\n\n-- In which directories to search for the corresponding header/implementation file, and in which order.\n-- List, allowed items: \"same\" and \"twin\"\nvim.g.cppswitch_search_dirs = {\"same\", \"twin\"}\n\n-- In which directory to create a header/implementation file, if it doesn't exist.\n-- Possible values: \"same\" or \"twin\"\nvim.g.cppswitch_creation_dir = \"same\"\n\n-- For determining the 'twin directories'\nvim.g.cppswitch_header_dir = \"include\"\nvim.g.cppswitch_impl_dir = \"src\"\n```\n\n4. Create keymaps for using the plugin - adapt to your liking\n\n```lua\nvim.keymap.set(\"n\", \"\u003cleader\u003eS\", \"\u003ccmd\u003eCppswitchSwitch\u003cCR\u003e\")\nvim.keymap.set(\"n\", \"\u003cleader\u003eh\", \"\u003ccmd\u003eCppswitchGotoHeader\u003cCR\u003e\")\nvim.keymap.set(\"n\", \"\u003cleader\u003ec\", \"\u003ccmd\u003eCppswitchGotoImpl\u003cCR\u003e\")\n```\n\n5. When in an implementation file, use `\u003cleader\u003eh` (or whichever keymap you configured) to switch to the corresponding header file, and use `\u003cleader\u003ec` for the opposite direction.\nOr simply use `\u003cleader\u003eS` for letting the plugin detect in which type of file you currently are, and switch to the other one.\n\n# Behavior\n\n## `CppswitchGotoHeader` \u0026 `CppswitchGotoImpl`\n\nThe commands `CppswitchGotoHeader` and `CppswitchGotoImpl` behave the same, but with roles of header and implementation files reversed.\nIn this section, we will thus only explain the behavior of `CppswitchGotoHeader`.\n\n`CppswitchGotoHeader` is intended to switch from a C++ implementation file to the corresponding header file. In the following, suppose that the current file is called \"util.cpp\". In fact, the file extension of the current file is irrelevant for what follows, only its location and the part of the name before the extension (\"util\" in this case) play a role.\n\n### Search\n\nThe command first searches if a suitable header file already exists. If this is not the case, the header file is newly created.\n\nThe search for the header file is first of all influenced by the variable `cppswitch_search_dirs`.\n\n- If this list contains the item \"same\" then the header file will be searched for in the directory in which \"util.cpp\" is located. \n\n- If this list contains the item \"twin\" then the header file will be searched for in \"twin directory\" of the directory in which \"util.cpp\" is located.\nThe twin directory is obtained by going up the directory hierarchy until a directory called \"src\" is reached,\nand replacing that by \"include\".\nFor example, the twin directory of `/my/project/src/helpers/` would be `/my/project/include/helpers/`.\nIf there is no parent directory called \"src\", or the twin directory does not exist, the twin directory is not used for the search.\n\n__Note:__ The directory names \"src\" and \"include\" are merely the defaults used by the plugin, but they can be configured using the variables `cppswitch_impl_dir` and `cppswitch_header_dir`.\n\nIf `cppswitch_search_dirs` contains both \"twin\" and \"same\", then both directories are used for searching the header file, in the order they appear in the list.\n\nIn the specified search directories, the plugin then searches for a file called \"util.?\", where \"?\" is replaced by all extensions listed in `cppswitch_header_extensions`, in the same order.\nThe first file of that kind that actually exists is loaded.\n\nFor example, if we have\n\n- `cppswitch_search_dirs = {\"twin\", \"same\"}`, \n- `cppswitch_header_extensions = {\"hpp\", \"h\"}`, \n- `cppswtich_impl_dir` and `cppswitch_header_dir` are the defaults, \n- and \"util.cpp\" is located in `/my/project/src/helpers/`,\n\nthen the following files are checked in that order:\n\n- `/my/project/include/helpers/util.hpp`\n- `/my/project/include/helpers/util.h`\n- `/my/project/src/helpers/util.hpp`\n- `/my/project/src/helpers/util.h`\n\n### Creation\n\nIf the search is not successful and no matching header file is found, the header file is created instead.\nThe directory in which the header file is created is controlled by the variable `cppswitch_creation_dir` (which may be \"same\" or \"twin\"),\nand the file extension is determined by the variable `cppswitch_preferred_header_extension`.\nFor example, in the scenario from above, if\n- `cppswitch_creation_dir = \"twin\"`,\n- and `cppswitch_preferred_header_extension = \"hpp\"`,\nthen the file `/my/project/src/helpers/util.hpp` is created (including the directory, if it does not exist).\n\n\n## `CppswitchSwitch`\n\nThe command `CppswitchSwitch` is basically a convenience wrapper around `CppswitchGotoHeader` and `CppswitchGotoImpl`.\nIt uses the variables `cppswitch_header_extensions` and `cppswitch_impl_extensions` to determine if the current buffer is a header or implementation file,\nand then switches to the other one.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakobknauer%2Fcppswitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakobknauer%2Fcppswitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakobknauer%2Fcppswitch/lists"}