Vim Configuration for CMake

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

[code lang=text]
1. syntax support: Hightlight keywords
2. keyword completion: Write cmakelist.txt more smoothly
3. keyword help: Consult cmake keyword easily
[/code]

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:

    [code lang=text]
    au FileType * execute 'setlocal dict+=~/.vim/dict/'.&filetype.'.vimdict'
    [/code]

    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:

    [code lang=bash]
    $ 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
    [/code]

  3. Enjoy keyword completion

3. Keyword help

Add such line in ~/.vimrc:

[code lang=text]
au FileType cmake set keywordprg=cmake\ –help-command
[/code]

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:

[code lang=text]
#! /usr/bin/env bash
cmake –help-command $1 ||\
cmake –help-variable $1 ||\
cmake –help-module $1 ||\
cmake –help-property $1
[/code]

And then add the executable permission for the scripts:

[code lang=bash]
$ chmod +x /home/usrname/cmake-help
[/code]

Change the keywordprg setting in ~/.vimrc to:

[code lang=text]
au FileType cmake set keywordprg=/home/usrname/cmake-help
[/code]

此条目发表在LINUX, 软件安装分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

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

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据