{"id":13898234,"url":"https://github.com/ilyachur/cmake4vim","last_synced_at":"2025-07-17T15:32:41.511Z","repository":{"id":26699642,"uuid":"109562490","full_name":"ilyachur/cmake4vim","owner":"ilyachur","description":"Vim plugin for CMake projects","archived":false,"fork":false,"pushed_at":"2024-03-11T06:12:12.000Z","size":10551,"stargazers_count":128,"open_issues_count":2,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-07T18:45:45.317Z","etag":null,"topics":["cmake","cmake-cache","cmake-generator","cmake-target","cmake-targets","cmake4vim","ctrlp","fzf","neovim","ninja","quickfix","vim"],"latest_commit_sha":null,"homepage":"","language":"Vim Script","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/ilyachur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2017-11-05T09:17:36.000Z","updated_at":"2024-08-06T15:05:27.000Z","dependencies_parsed_at":"2023-02-14T00:00:27.869Z","dependency_job_id":"7c7ea373-0c44-4502-a1ba-491833e517d1","html_url":"https://github.com/ilyachur/cmake4vim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyachur%2Fcmake4vim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyachur%2Fcmake4vim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyachur%2Fcmake4vim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyachur%2Fcmake4vim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilyachur","download_url":"https://codeload.github.com/ilyachur/cmake4vim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226274710,"owners_count":17598860,"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":["cmake","cmake-cache","cmake-generator","cmake-target","cmake-targets","cmake4vim","ctrlp","fzf","neovim","ninja","quickfix","vim"],"created_at":"2024-08-06T18:04:10.634Z","updated_at":"2024-11-25T04:30:59.382Z","avatar_url":"https://github.com/ilyachur.png","language":"Vim Script","readme":"# **cmake4vim** - CMake integration to Vim/Neovim\n\n\u003cp\u003e\n    \u003ca href=\"#\"\u003e\u003cimg src=\"https://github.com/ilyachur/cmake4vim/workflows/CI/badge.svg\" alt=\"Build Status\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/ilyachur/cmake4vim\"\u003e\u003cimg src=\"https://codecov.io/gh/ilyachur/cmake4vim/branch/master/graph/badge.svg\" alt=\"Code coverage\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/ilyachur/cmake4vim/issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/ilyachur/cmake4vim\" alt=\"Issues\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/ilyachur/cmake4vim/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-green.svg\" alt=\"License\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/ilyachur/cmake4vim/commits/master\"\u003e\u003cimg src=\"https://img.shields.io/github/last-commit/ilyachur/cmake4vim\" alt=\"Latest commit\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/ilyachur/cmake4vim/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/ilyachur/cmake4vim\" alt=\"Repository's stars\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://gitter.im/cmake4vim/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\"\u003e\u003cimg src=\"https://badges.gitter.im/cmake4vim/Lobby.svg\" alt=\"Join the chat\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nI created this plugin in order to improve integration CMake to the Vim editor. I tried different plugins for vim which allow to work with cmake but I didn't find the plugin which was satisfied my requrements.\n\n![cmake4vim common](doc/common.gif)\n\n## Key features\n\n* Written in pure Vimscript\n* The plugin supports next CMake Generators:\n  * Unix Makefiles\n  * Visual Studio\n  * Ninja\n* The plugin shows cmake results using quickfix list. If you have installed **[vim-dispatch](https://github.com/tpope/vim-dispatch)** plugin, plugin will use it, this means that if you are using vim with tmux, cmake output will be printed in a separate window. In other case plugin will use `jobs` to async run if your Vim editor supports it.\n* The plugin shows cmake results using quickfix list. If you have installed **[vim-dispatch](https://github.com/tpope/vim-dispatch)** plugin, plugin will use it, this means that if you are using vim with tmux, cmake output will be printed in a separate window. In other case plugin will use `jobs` to async run if your Vim editor supports it.  * The plugin allows to specify cmake targets in order to avoid building of all project.\n* The plugin has an integration with next fuzzy finder plugins:\n   * **[CtrlP](https://github.com/ctrlpvim/ctrlp.vim)**\n   * **[FZF](https://github.com/junegunn/fzf.vim)**\n   * **[Telescope](https://github.com/nvim-telescope/telescope.nvim)** is supported through [extension](./README.md#extensions).\n* The plugin allows to specify make arguments for native build system (for example *-jN* and something else for Unix Make).\n* The plugin parses the output of cmake command and supports jump to warnings or errors.\n* Supports work with multiple build types\n* For CMake newer than 3.13 the plugin uses the CMake file API\n* Plugin allows to find and run executable file for selected target.\n* Plugin supports [Vimspector](https://github.com/puremourning/vimspector) plugin. Plugin can generate and modify Vimspector configuration file in order to save command line arguments and allows to debug application.\n\n## Extensions\n\n - [SantinoKeupp/telescope-cmake4vim.nvim](https://github.com/SantinoKeupp/telescope-cmake4vim.nvim) - [Telescope](https://github.com/nvim-telescope/telescope.nvim) integration.\n - [SantinoKeupp/lualine-cmake4vim.nvim](https://github.com/SantinoKeupp/lualine-cmake4vim.nvim) - Integration with [Lualine](https://github.com/nvim-lualine/lualine.nvim). Plugin adds information about elected kit, build type and build target.\n - [ilyachur/gtest-vim](https://github.com/ilyachur/gtest-vim) - Integrates vim with gtest. Plugin has a dependency on **cmake4vim** and can use **cmake4vim** capabilities to detect gtest executables.\n\n## Usage\n\n### Installation\n\nYou can use VimPlug for installation:\n```vim\nPlug 'ilyachur/cmake4vim'\n```\nOr Pathogen:\n```sh\ncd ~/.vim/bundle\ngit clone https://github.com/ilyachur/cmake4vim\n```\n\n### Commands\n\nThe current version of the plugin supports next commands:\n\n#### Basic\n\n - **`:CMake`** creates a build directory (if it is necessary) and generates cmake project.\n - **`:CMakeResetAndReload`** removes cmake cache and re-generates cmake project.\n - **`:CMakeReset`** removes cmake cache (this command removes the cmake build directory).\n - **`:CMakeBuild`** builds current cmake project. The command allows to specify cmake target.\n - **`:CMakeSelectTarget`** selects a target for project. You should put target name as a command line argument.\n - **`:CMakeSelectBuildType`** changes the cmake build type with argument passed and call **`:CMake`**.\n - **`:CMakeInfo`** creates a window with CMake information.\n - **`:CMakeClean`** cleans the project (it is equal of the execution `make clean`).\n - **`:CMakeCompileSource`** compiles source file in current buffer.\n\n#### Execute\n\n - **`:CMakeRun`** Run the current the binary of currently selected target. Allows to automatically change the [Vimspector](https://github.com/puremourning/vimspector) config file.\n - **`:CMakeRun!`** Run the current the binary of currently selected target. Command allows to reset previous arguments if plugin reads arguments from [Vimspector](https://github.com/puremourning/vimspector) config.\n - **`:CTest`** run `ctest`. The command allows to specify CTest arguments and default arguments can be set in `g:cmake_ctest_args`\n - **`:CTest!`** same as `:CTest` but ignores `g:cmake_ctest_args`.\n - **`:CTestCurrent`** same as `:CTest` but run tests with `-R current_cmake_target`.\n - **`:CTestCurrent!`** same as `:CTest!` but run tests with `-R current_cmake_target`.\n\n#### Integration\n\n - **`:CCMake`** allow to use *ccmake* command inside vim. The command supports next open modes: 'vsplit' - vertical mode, 'split' - horizontal mode, 'tab' - open ccmake in the new tab (by default the executor window split mode is used).\n\n#### FZF plugins\n\n - **`:CtrlPCMakeTarget`** you can use CtrlP in order to select a target for project.\n - **`:CtrlPCMakeBuildType`** allows to use CtrlP in order to select a project build type.\n - **`:CtrlPCMakeKit`** uses CtrlP to select a CMake kit for project.\n - **`:FZFCMakeSelectTarget`** you can use FZF in order to select a target for project.\n - **`:FZFCMakeSelectBuildType`** allows to use FZF in order to select a project build type.\n - **`:FZFCMakeSelectKit`** uses FZF to select a CMake kit for project.\n\n## `\u003cPlug\u003e` mappings\n\n| `\u003cPlug\u003e` mapping          | Command                   |\n|:--------------------------|:--------------------------|\n| `(CMake)`                 | `:CMake`                  |\n| `(CMakeResetAndReload)`   | `:CMakeResetAndReload`    |\n| `(CMakeReset)`            | `:CMakeReset`             |\n| `(CMakeBuild)`            | `:CMakeBuild`             |\n| `(CMakeClean)`            | `:CMakeClean`             |\n| `(CMakeInfo)`             | `:CMakeInfo`              |\n| `(CMakeRun)`              | `:CMakeRun`               |\n| `(CTest)`                 | `:CTest`                  |\n| `(CTestCurrent)`          | `:CTestCurrent`           |\n| `(CCMake)`                | `:CCMake`                 |\n| `(CMakeCompileSource)`    | `:CMakeCompileSource`     |\n\n### Variables\n\nPlugin supports special global variables which are allow to change behaviour of commands (you can change them in your **.vimrc**):\n\n#### Common\n\nThe options below allow to change plugin behavior.\n\n - **`g:cmake_executable`** the path to CMake. Default is 'cmake'.\n - **`g:cmake_reload_after_save`** if this variable is not equal 0, plugin will reload CMake project after saving CMake files. Default is 0.\n - **`g:cmake_change_build_command`** if this variable is not equal 0, plugin will change the make command. Default is 1.\n - **`g:cmake_compile_commands`** if this variable is not equal 0, plugin will generate compile commands data base. Default is 0.\n - **`g:cmake_compile_commands_link`** set the path for a link on compile_commands.json. Default is empty.\n - **`g:cmake_vimspector_support`** enables generation and modification of [Vimspector](https://github.com/puremourning/vimspector) config file. Default is 0.\n - **`g:cmake_vimspector_default_configuration`** is a default configuration for new vimspector target. Default is:\n ```\n    let g:cmake_vimspector_default_configuration = {\n                \\ 'adapter': '',\n                \\ 'configuration': {\n                    \\ 'request': 'launch',\n                    \\ 'cwd': '${workspaceRoot}',\n                    \\ 'Mimode': '',\n                    \\ 'args': [],\n                    \\ 'program': ''\n                    \\ }\n                \\ }\n ```\n - **`g:cmake_build_executor`** allows to force set the build executor. Default is empty. Available values are:\n    - 'job' uses job to asynchronous build\n    - 'term' uses terminal to asynchronous build *Experimental*\n    - 'dispatch' uses [vim-dispatch](https://github.com/tpope/vim-dispatch) plugin to asynchronous build\n    - 'system' uses synchronous build\n    - '' uses automatic detection of supported modes (the priority is `dispatch`, `job`, `term`, `system`)\n - **`g:cmake_build_executor_window_size`** defines the size of build window and quickfixlist. Default is 10.\n - **`g:cmake_build_executor_split_mode`** Allows to configure split mode for build window and quickfixlist. Avaulable values are:\n    - 'sp' enables horizontal mode. It is the default value.\n    - 'vsp' enables vertical mode.\n - **`g:cmake_build_executor_height`** defines the height (in rows) of the build window and quickfixlist window showing the results. **The option was deprecated, please use `let g:cmake_build_executor_window_size=\u003csize\u003e` instead.** Default is 10.\n\n#### Build path\n\nBelow the list of options which allow to customize the path to CMake build directory. The list order is from higher to lower priority (it means if you initialize several options plugin will use the first initialized option from the list):\n\n - **`g:cmake_build_dir`** allows to set cmake build directory.  Default is ''. If variable is empty the plugin will use the prefix plus build type.\n - **`g:cmake_build_path_pattern`** pattern for build dir, two strings that will be evaluated in a `printf`. e.g.:\n     `let g:cmake_build_path_pattern = [ \"%s/workspace/build/%s/%s/%s\", \"$HOME, fnamemodify( getcwd(), ':t' ), g:cmake_selected_kit, g:cmake_build_type\" ]`\n - **`g:cmake_build_dir_prefix`** allows to set cmake build directory prefix, in this case the plugin uses the next rule to generate build directory name: `g:cmake_build_dir_prefix` + `g:cmake_build_type`. This option is used by default, the default prefix is 'cmake-build-'.\n\n#### CMake build options\n\nThe list contains variables which allow to configure CMake build.\n\n - **`g:cmake_src_dir`** allows to set cmake source directory.  Default is '' which evaluates to the current working directory.\n - **`g:cmake_build_type`** allows to change **`-DCMAKE_BUILD_TYPE`**. Default is empty. If variable is empty, plugin tries to detect cached build type. And selects 'Release' type if cmake cache doesn't exist.\n - **`g:cmake_variants`** enables predefined cmake build variants in the form of a dictionary, e.g. `{ 'Debug' : { 'cmake_build_type' : 'Debug', 'cmake_usr_args' : { 'CONAN_PATH' : '~/.conan' } }`\n - **`g:cmake_build_target`** set the target name for build. Default is empty and default value depends on CMake Generator\n - **`g:cmake_usr_args`** allows to set user arguments for cmake. Default is empty. It can be either a string or a dictionary.\n - **`g:cmake_build_args`** allows to set custom cmake build arguments (for example `--parallel`). Default is empty.\n - **`g:make_arguments`** allows to set custom parameters for make command. Default is empty. If variable is empty, plugin launches `make` without arguments.\n - **`g:cmake_ctest_args`** enables arguments for `ctest`, e.g. `'-j8 --output-on-failure --verbose'`. Default is empty. If the user calls `:CTest \u003csome arguments\u003e`, the `g:cmake_ctest_args` are inserted directly after `ctest`, before the `\u003csome arguments\u003e` parameter.\n - **`g:cmake_kits`** enables predefined cmake kits in the form of a dictionary of dictionaries that specify a toolchain file, environment variables, cmake variables among other things\n - **`g:cmake_kits_global_path`** specifies a path to the JSON containing cmake kits. Default is empty.\n - **`g:cmake_selected_kit`** currently selected cmake kit. Default is empty.\n\n\n#### Examples\n\nCMake kits can be given in the following ways:\n - as a variable `g:cmake_kits`\n - as a JSON file in the current folder named `.cmake-kits.json`\n - as a JSON file specified by `g:cmake_kits_global_path` variable\n\nThe variable `g:cmake_kits` has the lowest, and the local `.cmake-kits.json` file has the highest priority.\n\nExample of supported functions in `CMake kits`:\n```\nlet g:cmake_kits = {\n            \\  \"android-ndk-r22\": {\n            \\    \"toolchain_file\": \"~/toolchains/android.cmake\",\n            \\    \"environment_variables\": {\n            \\      \"PATH_TO_CACHE\": \"/Users/vimmer/cache\",\n            \\      \"PATH_TO_CONFIG\": \"/Users/vimmer/config\"\n            \\    },\n            \\    \"cmake_usr_args\": {\n            \\      \"USE_BROWSER\": \"chrome\",\n            \\      \"TIMEOUT_IN_SECONDS\": \"300\"\n            \\    },\n            \\    \"generator\": \"Ninja\"\n            \\  } }\nlet g:cmake_kits = {\n            \\  \"gcc\": {\n            \\    \"compilers\": {\n            \\        \"C\": \"/usr/bin/gcc\",\n            \\        \"CXX\": \"/usr/bin/g++\"\n            \\  } }\n```\n\nIf you specify both `toolchain_file` and `compilers`, the `toolchain_file` takes precedence and `compilers` are ignored.\n\nExample of a `.cmake-kits.json` file:\n```json\n{ \"gcc\": {\n  \"compilers\" : {\n      \"C\": \"/usr/bin/gcc\",\n      \"CXX\": \"/usr/bin/g++\"\n} } }\n```\n\n### Jump to\n\nPlugin is closely integrated with quickfix list and allows to use quickfix features to jump between error or warning messages.\n\n - **:cp[revious]** command jumps to previous error/warning message\n - **:cn[ext]**     command jumps to next     error/warning message\n\n## Demos\n\n* CMakeInfo window:\n![CMakeInfo](doc/CMakeInfo.png)\n* Select build type\n![select build type](doc/select_build_type.gif)\n* Jump to cmake error:\n![cmake error](doc/cmake_error.gif)\n* Ninja compilation error\n![ninja error](doc/error_ninja.gif)\n\n## Contributing\n\nBug reports, feedback, feature and other pull requests are appreciated. Check the [Contributing Guidelines](CONTRIBUTING.md) for how to\ncreate a feature request, submit a pull request or post an issue.\n\n## Tips and tricks\n\n### Open shell in the build directory\n\n```\nnnoremap \u003cexpr\u003e \u003cleader\u003edb printf(\":bo new\\\u003cCR\u003e:lcd %s\\\u003cCR\u003e:res 15\\\u003cCR\u003e:term ++curwin\\\u003cCR\u003e\", utils#cmake#getBuildDir() )\n```\n\n### YouCompleteMe\n\nIf you're using `YouCompleteMe` and want `clangd-completer` to work with different compilers, you could pass `clangd` a `-query-driver` argument.\n\nE.g. for developing `emscripten`, you could pass `em++` to `clangd` via `g:ycm_clangd_args`.\n\nYou could add such entries to your `g:cmake_kits` and override `CMakeSelectKit` and `FZFCMakeSelectKit`.\n\nAdd this to the `after` directory, e.g. `~/.vim/after/plugin/cmake.vim`:\n```\nfunction! s:customSelectKit(name) abort\n    let l:loaded_kits = utils#cmake#kits#getCMakeKits()\n    if !has_key( l:loaded_kits, a:name )\n        call utils#common#Warning(printf(\"CMake kit '%s' not found\", a:name))\n        return\n    endif\n\n    call cmake4vim#SelectKit(a:name)\n\n    let l:cmake_kit = l:loaded_kits[ g:cmake_selected_kit ]\n    let g:ycm_clangd_args = filter( g:ycm_clangd_args, \"v:val !~# 'query-driver'\" )\n    if has_key( l:cmake_kit, 'query_driver' )\n        let g:ycm_clangd_args += [ printf( '-query-driver=%s', l:cmake_kit[ 'query_driver' ] ) ]\n        YcmRestartServer\n    endif\nendfunction\n\nfunction! s:FZFSelectKit() abort\n    if exists(':FZF')\n        return fzf#run({\n                    \\ 'source': sort( keys( utils#cmake#kits#getCMakeKits() ), 'i' ),\n                    \\ 'options': '+m -n 1 --prompt CMakeKit\\\u003e\\ ',\n                    \\ 'down':    '30%',\n                    \\ 'sink':    function('s:customSelectKit')})\n    endif\nendfunction\n\ncommand! -nargs=1 -complete=custom,cmake4vim#CompleteKit CMakeSelectKit    call s:customSelectKit(\u003cf-args\u003e)\ncommand!                                                 FZFCMakeSelectKit call s:FZFSelectKit()\n```\n\n## Supported CMake version\n\nThe plugin supports all CMake versions since 2.8.\n\nSince the CMake 3.14 version the plugin uses file API, this feature helps to have more information about CMake project and implement a smart\ndetection of executable files for `:CMakeRun` command.\n\n## References\n\n### Author\n\nIlya Churaev ilyachur@gmail.com\n\n### Licence\n\nMIT\n","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyachur%2Fcmake4vim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filyachur%2Fcmake4vim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyachur%2Fcmake4vim/lists"}