Clighter(C Lighter) is a vim plugin that integrates libclang to improve development environment for c-family programming. Clighter provides following features currently:
- Syntax(semantic) highlighting
- Cursor word highlighting
- Customizable color of highlighting
- Experimental function to for rename-refactoring
Clighter requires the following:
- Vim version 7.4+ with python2.x enabled
- libclang(3.5 is recommended)
- Clighter has been tested in linux platform only.
- Vundle Install:
Bundle 'bbchung/clighter'
- Manuall Install
Untar the clighter.tar.gz to your vim path.
Clighter automatically start while g:clighter_autostart == 1
.
Default: 1
let g:clighter_autostart = 0
The compiler options for Clang. Clighter will pass these options to libclang to parse the code. Notice that bad options will cause clighter not working even crashing. For convenience, you can use vim session to remember this option.
Default: '["-Iinclude"]'
let g:ClighterCompileArgs = '["-x", "c++", "-std=c++", "-DLinux"]'
Clighter try to find libclang-3.5 in your system automatically, if clighter doesn't find the libclang or other version of libclang is used, you need set this path.
Default: ''
let g:clighter_libclang_file = '/usr/lib/libclang.so'
Do syntax highlighting in realtime. Turn off this option may improve the performance.
Default: 1
let g:clighter_realtime = 1
The prompt level of rename refactoring.
0
: no prompt
1
: prompt while do cross buffer renaming
2
: prompt of each word that going to be replaced
Default: 1
let g:clighter_rename_prompt_level = 1
0
: disable
1
: enable
Default: 1
let g:clighter_enable_cross_rename = 1
Define the token type of syntax to highlight.
Default:
['clighterMacroInstantiation', 'clighterStructDecl', 'clighterClassDecl', 'clighterEnumDecl', 'clighterEnumConstantDecl', 'clighterTypeRef', 'clighterDeclRefExprEnum']
Enable cursor highlight by default
Default: 1
let g:clighter_cursor_hl_default = 0
Clighter provides these commands and functions.
-
Enable Clighter
ClighterEnable
-
Disable Clighter
ClighterDisable
-
Toggle cursor highlighting
ClighterToggleCursorHL
-
Rename-refactor
- It's a experimental function, and it's maybe not reliable.
- It's not project scoped(the scope is opend vim buffer list).
- Strongly recommend that backing up all files before calling this function.
clighter#Rename()
For convenience, you can add key mapping in your vimrc:
nmap <silent> <Leader>r :call clighter#Rename()<CR>
-
Set clang compile args in runtime
call clighter#SetCompileArgs()
Clighter defines these syntax groups corresponding to CursorKind of libclang.
-
clighterMacroInstantiation
hi link clighterMacroInstantiation Constant
-
clighterTypeRef
hi link clighterTypeRef Identifier
-
clighterStructDecl
hi link clighterStructDecl Type
-
clighterClassDecl
hi link clighterClassDecl Type
-
clighterEnumDecl
hi link clighterEnumDecl Type
-
clighterEnumConstantDecl
hi link clighterEnumConstantDecl Identifier
-
clighterDeclRefExprEnum
hi link clighterDeclRefExprEnum Identifier
-
clighterCursorDefRef
hi link clighterCursorDefRef IncSearch
-
clighterFunctionDecl
hi link clighterFunctionDecl None
-
clighterDeclRefExprCall
hi link clighterDeclRefExprCall None
-
clighterMemberRefExpr
hi link clighterMemberRefExpr None
-
clighterNamespace
hi link clighterNamespace None
You can customize these colors in your colorscheme, for example:
hi clighterTypeRef term=NONE cterm=NONE ctermbg=232 ctermfg=255 gui=NONE
hi clighterClassDecl term=NONE cterm=NONE ctermbg=255 ctermfg=232 gui=NONE
Vim version 7.4+ with python2.x is required, and make sure libclang(3.5 is recommended) is installed correctly and set g:clighter_libclang_file if need.
Even though libclang provides many useful informations, it's not enough to do cross file rename-refactoring, so Clighter needs to use its own way way to 'guess' what should be renamed. Clighter can't gurantee the result of rename-factoring result is perfect.