Home

Awesome

:shield: cppguard.nvim

Automatically generates proper include guard for C++

:clipboard: Requirements

:inbox_tray: Installation

With lazy.nvim

return {
    "pogyomo/cppguard.nvim",
    dependencies = {
        "L3MON4D3/LuaSnip" -- If you're using luasnip.
    },
    lazy = true,
}

:notebook: Introduction

C++ requires developer to write include guard to prevent that file is included more than twice, and sometimes you need to write longer include guard, and it's painful.

So, this plugin provides apis that automatically generates such include guard.

:rocket: Usage

This plugin provides guard_string which generates a string that is unique for using in include guard.

For examples, consider the following directory structure.

project
|---CMakeLists.txt
|---src
    |---dir
        |---sub
            |---file.h <-here

When you open file.h, then call this function, you will get PROJECT_DIR_SUB_FILE_H_, that is following google C++ Style Guide.

If you're using luasnip, you can add a snippet that automatically creates include guard with following code:

local luasnip = require("luasnip")
luasnip.add_snippets("cpp", {
    -- Register snippet which can summon by typing `guard`
    require("cppguard").snippet_luasnip("guard")
})

This snippet works as follow when you're in such above, for example:

guard|

ā†“ expand

#ifndef PROJECT_DIR_SUB_FILE_H_
#define PROJECT_DIR_SUB_FILE_H_

|

#endif

:desktop_computer: APIS