{"id":13898865,"url":"https://github.com/LucHermitte/lh-cpp","last_synced_at":"2025-07-17T16:31:04.809Z","repository":{"id":28636459,"uuid":"32155375","full_name":"LucHermitte/lh-cpp","owner":"LucHermitte","description":"C\u0026C++ ftplugins suite for Vim","archived":false,"fork":false,"pushed_at":"2025-01-17T15:32:19.000Z","size":2234,"stargazers_count":131,"open_issues_count":4,"forks_count":10,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-01-17T16:40:49.133Z","etag":null,"topics":["brackets","cpp","snippets","vim","vim-plugins"],"latest_commit_sha":null,"homepage":"","language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucHermitte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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}},"created_at":"2015-03-13T12:46:33.000Z","updated_at":"2024-12-20T19:50:29.000Z","dependencies_parsed_at":"2024-01-14T16:07:31.604Z","dependency_job_id":"fdc2514e-8b3d-4449-841e-f26657f7c087","html_url":"https://github.com/LucHermitte/lh-cpp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/LucHermitte/lh-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2Flh-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2Flh-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2Flh-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2Flh-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucHermitte","download_url":"https://codeload.github.com/LucHermitte/lh-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2Flh-cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265629895,"owners_count":23801488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["brackets","cpp","snippets","vim","vim-plugins"],"created_at":"2024-08-06T18:04:29.957Z","updated_at":"2025-07-17T16:31:04.291Z","avatar_url":"https://github.com/LucHermitte.png","language":"Vim script","readme":"# lh-cpp [![Build Status](https://secure.travis-ci.org/LucHermitte/lh-cpp.png?branch=master)](http://travis-ci.org/LucHermitte/lh-cpp) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020)\n## Features\n\nlh-cpp is an heterogeneous suite of helpers for C and C++ programming.\n\nIt provides the following things:\n  * Smart snippets for [brackets pairs](#brackets), [control statements](#code-snippets)\n  * a few [templates](#templates)\n  * a few [advanced wizards, and high-level features](#wizards-and-other-high-level-features) to Generate classes and singletons, to Generate ready to fill-in function comments for Doxygen, Jump to a function implementation, Search for un-implemented or undeclared functions, _etc._\n  * [syntax highlighting](#syntax-highlighting) for identified counter-idioms and bad practices (catch by value, assignments in conditions, throw specifications)\n  * an [API](doc/API.md) to build even more complex wizards and advanced features\n\n  An exhaustive [list of all options](doc/options.md) is also available.\n  For help using this plugin for the first time, please take a look at `:h lh-cpp-first-steps`\n\n### Text insertion facilities\n\n\n#### Brackets\n\nThe insertion of pair of brackets-like characters is eased thanks to [lh-brackets](http://github.com/LucHermitte/lh-brackets).\n\n|   In mode               |   INSERT                                                            |   VISUAL                                      |   NORMAL                  |\n|:------------------------|:--------------------------------------------------------------------|:----------------------------------------------|:--------------------------|\n| **keys**                | Expands into ..                                                     | Surrounds the selection with ... \u003csup\u003e2\u003c/sup\u003e | Surrounds the current ... |\n| `(`                     | `(\u003ccursor\u003e)«»`                                                      | `(\u003cselection\u003e)`                               | word                      |\n| `[`                     | `[\u003ccursor\u003e]«»`                                                      | \u003csup\u003e1\u003c/sup\u003e                                  | \u003csup\u003e1\u003c/sup\u003e              |\n| `[` after a `[`         | `[[\u003ccursor\u003e]]«»`                                                    | n/a                                           | n/a                       |\n| `]` before `]]`         | close all `]]`                                                      | n/a                                           | n/a                       |\n| `\u003clocalleader\u003e[`        |                                                                     | `[\u003cselection\u003e]`                               | word                      |\n| `{`                     | `{\u003ccursor\u003e}«»`\u003csup\u003e3\u003c/sup\u003e                                          | `{\u003cselection\u003e}`                               | word                      |\n| `\u003clocalleader\u003e{`        |                                                                     | `{\\n\u003cselection\u003e\\n}«»`                         | line                      |\n| \u003c                       | `\u003c\u003ccursor\u003e\u003e«»` after `#include`, or `template` on the same line     |                                               |                           |\n| `\"` (1 double quote)    | `\"\u003ccursor\u003e\"«»`                                                      | \u003csup\u003e1\u003c/sup\u003e                                  | \u003csup\u003e1\u003c/sup\u003e              |\n| `\"\"`                    |                                                                     | `\"\u003cselection\u003e\"`                               | word                      |\n| `'`                     | `'\u003ccursor\u003e'«»`                                                      | \u003csup\u003e1\u003c/sup\u003e                                  | \u003csup\u003e1\u003c/sup\u003e              |\n| `''` (2 single quotes)  |                                                                     | `'\u003cselection\u003e'`                               | word                      |\n| `;`                     | closes all parenthesis after the cursor -- if there is nothing else |                                               |                           |\n\n##### Notes:\n  * \u003csup\u003e1\u003c/sup\u003e Not defined to avoid hijacking default vim key bindings.\n  * \u003csup\u003e2\u003c/sup\u003e The visual mode mappings do not surround the current marker/placeholder selected, but trigger the INSERT-mode mappings instead.\n  * \u003csup\u003e3\u003c/sup\u003e The exact behavior of this mapping has changed with release r719 (on Google Code). Now, no newline is inserted by default. However, hitting `\u003ccr\u003e` in the middle of a pair of curly-bracket will expand into `{\\n\u003ccursor\u003e\\n}`.\n  * `«»` represents a marker/placeholder, it may be expanded with other characters like `\u003c++\u003e` depending on your preferences.\n  * There is no way (yet) to deactivate this feature from the `.vimrc`\n\n\n#### Code snippets\n\n##### INSERT-mode snippets abbreviations\nThere exist, over the WWW, a lot of configurations and mappings regarding C programming. Once again you will find shortcuts for `if`, `else`, `elif`  (I know it is not a C keyword, but `else if` are), `for`, `while`, `do`, `switch`, and `main`. In C++, snippets are also provided for `try`, `catch`, and `namespace`.\nWhat is unique is the fact that when you type `if` in insert mode, it will automatically expand into ...\n```C++\nif () {\n}\n```\n... in respect of the context. I.e.: within comments or strings (delimited by single or double quotes) `if` is not expanded. If keyword characters precede the typing, `if` is not expanded as well. Thus variables like `tarif` can be used without getting any headache.\n\n\nMost of these same snippets, and a few variations, are\n[also provided](doc/snippets.md#control-statements) as template-files for\n[mu-template](http://github.com/LucHermitte/mu-template).\nThis time, you just need to type the first letters of the snippet/template\nname, and trigger the expansion (with `\u003cc-r\u003e\u003ctab\u003e` by default). If several\nsnippets match (like _c/for_, _c/fori_, _cpp/fori_ and _cpp/for-iterator_ when\nyou try to expand `fo`), mu-template will ask you to choose which (matching)\nsnippet you want to expand.\n\n##### Instruction surrounding mappings\nIn visual mode, `,if` wraps the selection within the curly brackets and inserts `if ()` just before. In normal mode `,if` does the same thing under the consideration that the selection is considered to be the current line under the cursor. Actually, it is not `,if` but `\u003cLocalLeader\u003eif,` with `maplocalleader` assigned by default to the coma `,`.\n\n##### Expression-condition surrounding mappings\nIn the same idea, `\u003cLocalLeader\u003e\u003cLocalLeader\u003eif` surrounds the selection with `if (` and `) {\\n«»\\n}«»`.\n\n##### Other notes\nAll the three mode oriented mappings respect and force the indentation regarding the current setting and what was typed.\n\nMore precisely, regarding the value of the buffer relative option b:usemarks (_cf._ [lh-brackets](http://github.com/LucHermitte/lh-brackets)), `if` could be expanded into:\n```C++\nif () {\n    «»\n}«»\n```\n\nThe exact style (Alman, Stroustroup, ...) regarding whether brackets are on a\nnew line, or not, can be tuned thanks to [lh-dev `:AddStyle` feature](http://github.com/LucHermitte/lh-dev#formatting-of-brackets-characters).\n\n#### Miscellaneous shortcuts\nNote: in all the following mappings, `,` is actually the localleader that\nlh-cpp sets to the comma characcter if it isn't set already.\n\n  * `tpl` expands into `template \u003c\u003ccursor\u003e\u003e«»` ;\n  * `\u003cm-t\u003e` inserts `typedef`, or `typename` depending on what is before the cursor ;\n  * `\u003cm-r\u003e` inserts `return`, and tries to correctly place the semicolon, and a placeholder, depending on what follows the cursor ;\n  * `\u003cc-x\u003ebe`, `\u003cc-x\u003erbe` replace `(foo\u003ccursor\u003e)` with `(foo.begin(),foo.end()\u003ccursor\u003e)` (or `rbegin`/`rend`) ;\n  * `\u003cc-\u003ese`: attempt to fill-in a `switch-case` from an enumerated type ;\n  * `,sc` | `,dc` | `,rc` | `,cc` | `,lc` surround the selection with ; `static_cast\u003c\u003ccursor\u003e\u003e(\u003cselection\u003e)`, `dynamic_cast`, `reinterpret_cast`, `const_cast`, or `boost::lexical_cast` ;\n  * `,,sc` | `,,dc` | `,,rc` | `,,cc` try to convert the C-cast selected into the C++-cast requested ;\n  * `#d` expands into `#define`, `#i` into `#ifdef`, `#e` into `endif`, `#n` into `#include` ;\n  * `,0` surrounds the selected lines with `#if 0 ... #endif` ;\n  * `,1` surrounds the selected lines with `#if 0 ... #else ... #endif` ;\n  * `:KeepPoundIfPath 0` (or `1`) will clean a `#if 0/1...#else...#endif`\n    construct to match either the true or the false path.\n  * `pub` expands into `public:\\n`, `pro` expands into `protected:\\n`, `pri` expands into `private:\\n` ;\n  * `vir` expands into `virtual` ;\n  * `firend` is replaced by `friend` ;\n  * `\u003cm-s\u003e` inserts `std::`, `\u003cm-b\u003e` inserts `boost:` ;\n  * `?:` expands into `\u003ccursor\u003e? «» : «»;` ;\n  * `\u003cC-X\u003ei` will look for the symbol under the cursor (or selected) in the current ctag database and it will try to automatically include the header file where the symbol is defined.\n  * `\u003cM-i\u003e` will look for the symbol under the cursor (or selected) in the current ctag database and it will try to automatically prepend it with its missing complete scope.\n  *  `[[` and `][` and been overridden to jump to the start/end of the current\n     function -- the default mappings were defined in C in mind, and they are\n     unable of this. See the related `v_if` and `o_if` mappings from [lh-dev](http://github.com/LucHermitte/lh-dev/#function) -- [see the demo](blob/master/doc/screencast-select-function.gif).\n\n#### Templates\n  * All templates, snippets and wizards respect the naming convention set for\n    the current project thanks to\n    [lh-dev styling feature](http://github.com/LucHermitte/lh-dev#naming-conventions)\n    -- see my [project style template](http://github.com/LucHermitte/mu-template/blob/master/after/template/vim/internals/vim-rc-local-cpp-style.template)\n    for an idea of what is supported and possible.\n  * stream inserters, stream extractor, binary operators.\n  * [bool operator](doc/snippets.md#cppbool-operator): almost portable hack to\n    provide a boolean operator, strongly inspired by Matthew Wilson's\n    _Imperfect C++_.\n  * Generation of [enums](doc/Enums.md), and of switch-case statements from enum\n    definition.\n  * constructors: [`copy-constructor`](doc/snippets.md#cppcopy-constructor),\n    [`default-constructor`](doc/snippets.md#cppdefault-constructor),\n    [`destructor`](doc/snippets.md#cppdestructor),\n    [`assignment-operator`](doc/snippets.md#cppassignment-operator)\n    (see `:h :Constructor`).\n  * Various [standard types](doc/snippets.md#standard-and-boost-types) and\n    [functions](doc/snippets.md#standard-and-boost-functions-and-idioms) (and a\n    few from boost) have a snippet that'll automatically include the related\n    header file there are are defined. NB: at this time, inclusions are not\n    optimized as IncludeWhatYouUse would optimize them for us.\n  * When a snippet/template requires header files, they will get included\n    automatically (as long as the snippet specifies the headers files required)\n    ; note: so far this feature cannot detect whether a required header file is\n    already indirectly included through other included files.\n  * Some snippets will try to detect the C++11 dialect (98/03/11/14/17) in\n    order to adapt the result produced -- it will be done through the analysis\n    of the [option `(bg):cpp_std_flavour`](doc/option.md#bgcpp_std_flavour-and-cxxflags) , or\n    the analysis of `$CXXFLAGS`, or through the analysis of CMake `CXXFLAGS`\n    variables (this will require\n    [lh-cmake](http://github.com/LucHermitte/lh-cmake), and the project to be\n    configured to CMake.)\n\nI'll try to maintain an up-to-date [documentation](doc/snippets.md) of the\nsnippets as most of them have options.\n\n#### Wizards and other high-level features\n  * [class](doc/snippets.md#cppclass): builds a class skeleton based on the selected (simplified) semantics (value copyable, stack-based non copyable, entity non-copyable, entity clonable)\n  * [singleton](doc/snippets.md#cppsingleton): my very own way to define singletons based on my conclusions on this anti-pattern -- you may prefer Loki's or ACE's solutions\n  * [:DOX](doc/Doxygen.md): analyses a function signature (parameters, return type, throw specification) and provide a default Doxygenized documentation\n  * [:GOTOIMPL](doc/GotoImplementation.md), :MOVETOIMPL: search and jump to a function definition from its declaration, provide a default one in the _ad'hoc_ implementation file if no definition is found\n  * [:ADDATTRIBUTE](doc/Accessors.md): old facility that helps define const-correct accessors and mutator, will be reworked. [lh-refactor](http://github.com/LucHermitte/vim-refactor) provides more ergonomic mappings for this purpose.\n  * [:CppDisplayUnmatchedFunctions](doc/UmatchedFunctions.md), `\u003cc-x\u003eu`: shows the list of functions for which there is neither a declaration, nor a definition\n  * [:Override](doc/Override.md): Ask which inherited virtual function should be overridden in the current class (feature still in its very early stages)\n  * `:Constructor` (that takes the following parameters: `init`, `default`, `copy`, `assign`), or `:ConstructorInit`, `:ConstructorDefault`, `:ConstructorCopy`, `AssignmentOperator`. They'll analyse the list of know attributes (from a ctags database) to generate the related construction functions.\n\n### Syntax highlighting\n  * assign in condition (bad practice)\n  * catch by value (bad practice)\n  * throw specifications ([do you really know what they are about, and still want them?](http://www.gotw.ca/gotw/082.htm)), BTW they have been deprecated in C++11\n  * C casts in C++ (bad practice)\n  * cases that fall through the next one (code smell -- disabled by default)\n  * function definitions\n\n### Miscellaneous\n  * home like VC++: mappings that override `\u003chome\u003e` and `\u003cend\u003e` to mimic how these keys behave in VC++.\n  * omap-param: defines the o-mappings `,i` and `,a` to select the current parameter (in a list of parameters).\n  * SiR,\n  * lh-cpp imports a [C\u0026C++ Folding plugin](https://github.com/LucHermitte/VimFold4C),\n    which is still experimental.\n  * [lh-dev](http://github.com/LucHermitte/lh-dev), which is required by\n    lh-cpp, provides a few commands like `:NameConvert` that permits to change\n    the naming style of a symbol. The possible styles are: `upper_camel_case`,\n    `lower_camel_case`, `snake`/`underscore`, `variable`, `local`, `global`,\n    `member`, `constant`, `static`, `param`, `getter`, `setter`)\n\n### Installation\n  * Requirements: Vim 7.+, [lh-vim-lib](https://github.com/LucHermitte/lh-vim-lib), [lh-style](https://github.com/LucHermitte/lh-style), [lh-brackets](https://github.com/LucHermitte/lh-brackets), [mu-template](https://github.com/LucHermitte/mu-template), [lh-dev](https://github.com/LucHermitte/lh-dev), [alternate-lite](https://github.com/LucHermitte/alternate-lite).\n  * With [vim-addon-manager](https://github.com/MarcWeber/vim-addon-manager), install lh-cpp. This is the preferred method because of the various dependencies.\n```vim\nActivateAddons lh-cpp\n```\n  * or with [vim-flavor](https://github.com/kana/vim-flavor) which also supports\n    dependencies:\n```\nflavor 'LucHermitte/lh-cpp'\n```\n  * or you can clone the git repositories (expecting I haven't forgotten anything):\n```\ngit clone git@github.com:LucHermitte/lh-vim-lib.git\ngit clone git@github.com:LucHermitte/lh-style.git\ngit clone git@github.com:LucHermitte/lh-tags.git\ngit clone git@github.com:LucHermitte/lh-dev.git\ngit clone git@github.com:LucHermitte/lh-brackets.git\ngit clone git@github.com:LucHermitte/searchInRuntime.git\ngit clone git@github.com:LucHermitte/mu-template.git\ngit clone git@github.com:tomtom/stakeholders_vim.git\ngit clone git@github.com:LucHermitte/alternate-lite.git\ngit clone git@github.com:LucHermitte/lh-cpp.git\n```\n  * or with Vundle/NeoBundle (expecting I haven't forgotten anything):\n```vim\nBundle 'LucHermitte/lh-vim-lib'\nBundle 'LucHermitte/lh-style'\nBundle 'LucHermitte/lh-tags'\nBundle 'LucHermitte/lh-dev'\nBundle 'LucHermitte/lh-brackets'\nBundle 'LucHermitte/searchInRuntime'\nBundle 'LucHermitte/mu-template'\nBundle 'tomtom/stakeholders_vim'\nBundle 'LucHermitte/alternate-lite'\nBundle 'LucHermitte/lh-cpp'\n```\n\n## Credits\n\nMany people have to be credited:\n  * the Vim \u0026 VimL gurus ;\n  * the people I've stolen scripts and functions from: Stephen Riehm, Michael\n    Sharpe, Georgi Slavchev, Johannes Zellner, Saul Lubkin ;\n  * the people that gave me many great ideas and even feedback: Gergely Kontra,\n    Leif Wickland, Robert Kelly IV [I've also stolen scripts from them] ;\n  * Thomas Ribo for his feedback and features-requirements.\n  * and many more that I have probably forgotten.\n\n## License\n\n  * Documentation is under CC-BY-SA 3.0\n  * lh-cpp is under GPLv3 with exceptions. See acompagning [license file](License.md), i.e.\n      * Plugin, snippets and templates are under GPLv3\n      * Most code generated from snippets (for control statements, proto\n        -\u003e definition, accessors, ...) are under the License Exception\n        detailled in the [license file](License.md).\n      * However, code generated from the following wizards: `class`,\n        `singleton`, `enum` (1\u00262, switch, for), `abs-rel` -\u003e is under Boost\n        Software Licence\n\n\n## See also\n  * [C++ tips on vim.wikia](http://vim.wikia.com/wiki/Category:C%2B%2B)\n  * c.vim\n  * **Project Management**: [local\\_vimrc](https://github.com/LucHermitte/local_vimrc)\n  * **Compilation**: [BuildToolsWrappers](http://github.com/LucHermitte/vim-build-tools-wrapper)\n  * **Errors Highlighting**: syntastic, [compil-hints](http://github.com/LucHermitte/vim-compil-hints) (a non-dynamic syntastic-lite plugin that'll only highlight errors found after a compilation stage)\n  * **CMake Integration**: [lh-cmake](https://github.com/LucHermitte/lh-cmake) + [local\\_vimrc](https://github.com/LucHermitte/local_vimrc) + [BuildToolsWrappers](http://github.com/LucHermitte/vim-build-tools-wrapper)\n  * **Refactoring**: refactor.vim, [my generic refactoring plugin](http://github.com/LucHermitte/vim-refactor)\n  * **Code Completion**: [YouCompleteMe](https://github.com/Valloric/YouCompleteMe), really, check this one!, or [OmniCppComplete](http://www.vim.org/scripts/script.php?script_id=1520), or [clang\\_complete](https://github.com/Rip-Rip/clang_complete)\n  * **Code Indexing**: [clang\\_indexer](https://github.com/LucHermitte/clang_indexer) and [vim-clang](https://github.com/LucHermitte/vim-clang), [lh-tags](http://github.com/LucHermitte/lh-tags)\n\n","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLucHermitte%2Flh-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLucHermitte%2Flh-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLucHermitte%2Flh-cpp/lists"}