Vim Configuration for CMake

In order to edit CMakeLists.txt file more smoothly, Vim needs additional configurations to add some features as follows:

1. syntax support: Hightlight keywords
2. keyword completion: Write cmakelist.txt more smoothly
3. keyword help: Consult cmake keyword easily

So, let’s go and implement above.

1. Syntax support

Please install vim-cmake-syntax plugin for vim.

2. Keyword Completion

  1. First, add addtional vim dictionary directory, add follow lines in ~/.vimrc file:
    au FileType * execute 'setlocal dict+=~/.vim/dict/'.&filetype.'.vimdict'
    

    This allow you to create a dictionary file ~/.vim/dict/cmake.vimdict for cmake type files. More Reading: Dictionary completions

  2. Then, you should generate the dictionary for cmake. Run command as follow:

    $ cmake --help-command-list > ~/.vim/dict/cmake.vimdict
    $ cmake --help-variable >> ~/.vim/dict/cmake.vimdict
    $ cmake --help-module >> ~/.vim/dict/cmake.vimdict
    $ cmake --help-property >> ~/.vim/dict/cmake.vimdict
    
  3. Enjoy keyword completion

3. Keyword help

Add such line in ~/.vimrc:

au FileType cmake set keywordprg=cmake\ --help-command

locate the cursor under the cmake keywords and press K(shift+k), you could get the help information.

However, the setting can only support the cmake command, as for other, we need create a shell script named /home/usename/cmake-help:

#! /usr/bin/env bash
cmake --help-command $1 ||\
cmake --help-variable $1 ||\
cmake --help-module $1 ||\
cmake --help-property $1

And then add the executable permission for the scripts:

$ chmod +x /home/usrname/cmake-help

Change the keywordprg setting in ~/.vimrc to:

au FileType cmake set keywordprg=/home/usrname/cmake-help
此条目发表在LINUX, 软件安装分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。