当前位置:网站首页>Vim: use tags file to extend the automatic code completion function of YCM for the third-party library of C language
Vim: use tags file to extend the automatic code completion function of YCM for the third-party library of C language
2022-07-24 09:08:00 【This person's surname is Yu and his name is Meng bailing】
Preface
In many Vim Editor's auto completion plug-in ,YouCompleteMe(YCM) It is definitely one of the best plug-ins , But the configuration process is often prohibitive for beginners . After years of tossing by the author , So far, it has basically reached the level of daily use .
If the reader is right YouCompleteMe This plug-in is unfamiliar , It is suggested to first refer to the author's blog Vim: To configure Python and C++ Common plug-ins .
For a better understanding of this article , Readers are advised to read my last blog first Vim: Expand YCM Yes C Semantic analysis function of third-party library of family language . In this blog , We solved YCM Error in semantic analysis of , But the improvement of automatic completion function is limited .
In the use of Vim+YCM when ,YCM It is usually not possible to directly access third-party software libraries ( If in c++ Mode of OpenCV) Automatically complete the functions and definitions in . So , This article mainly introduces how to use ctags Generate tags file , Further improve on the basis of the previous blog YCM Automatic completion kinetic energy in third-party software library .
The configuration process
This article takes opencv For example , Describes how to generate tags File to expand YCM Automatic completion function of .
Tags File generation
1 install ctags
sudo apt-get install ctags
Be careful , according to YCM The requirements of , To be installed exuberant-ctags Can only be [ 1 ] ^{[1]} [1]. Fortunately, , The above command will be installed by default exuberant-ctags. You can verify with the following command ctags Version of :
ctags --versionMy output here is as follows :
Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert Addresses: <[email protected]>, http://ctags.sourceforge.net Optional compiled features: +wildcards, +regex
2 Generate Tags file
This article takes opencv For example , First download opencv Source code , And then in moudles Execute the following command under the path :
# Be careful =+l Middle is lowercase L, instead of 1.
ctags -R --fields=+l *
Be careful ,'–fields=+l’c++ Required parameters , If you need to use c Language , I need to add
--langmap=c:.c.hParameters
Then a... Will appear under the current folder tags file , Let's take a look Tags Part of the document , as follows :
imread imgcodecs/src/loadsave.cpp /^Mat imread( const String& filename, int flags )$/;" f language:C++ namespace:cv
imread_ imgcodecs/src/loadsave.cpp /^imread_( const String& filename, int flags, Mat& mat )$/;" f language:C++ namespace:cv
imreadmulti imgcodecs/src/loadsave.cpp /^bool imreadmulti(const String& filename, std::vector<Mat>& mats, int flags)$/;" f language:C++ namespace:cv
imreadmulti imgcodecs/src/loadsave.cpp /^bool imreadmulti(const String& filename, std::vector<Mat>& mats, int start, int count, int flags)$/;" f language:C++ namespace:cv
imreadmulti_ imgcodecs/src/loadsave.cpp /^imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats, int start, int count)$/;" f language:C++ namespace:cv
imshow highgui/misc/java/src/java/highgui+HighGui.java /^ public static void imshow(String winname, Mat img) {$/;" m language:Java class:HighGui
imshow highgui/src/window.cpp /^void cv::imshow( const String& winname, InputArray _img )$/;" f language:C++ class:cv
imshow highgui/src/window.cpp /^void cv::imshow(const String& winname, const ogl::Texture2D& _tex)$/;" f language:C++ class:cv
imshow videoio/src/cap_winrt_bridge.cpp /^void VideoioBridge::imshow()$/;" f language:C++ class:VideoioBridge
imwrite imgcodecs/src/loadsave.cpp /^bool imwrite( const String& filename, InputArray _img,$/;" f language:C++ namespace:cv
imwrite_ imgcodecs/src/loadsave.cpp /^static bool imwrite_( const String& filename, const std::vector<Mat>& img_vec,$/;" f language:C++ namespace:cv
imwritemulti imgcodecs/include/opencv2/imgcodecs.hpp /^bool imwritemulti(const String& filename, InputArrayOfArrays img,$/;" f language:C++ namespace:cv
You can see ,tags The file contains function names and basic definitions , And in which file ,YCM They can be well parsed .
3. To configure tags File path
This step , Only required :
take tags Move the file to a customized location
stay vimrc Point to it in the file
for example , I will just generate tags The file has changed its name , And put it in the following position : ~/.vim/tagfiles/opencv.tags, And then in vimrc Add the following settings :
# Choose one of the following
set tags=opencv.tags # The relative position , Need to put tags Put the document under the current project
set tags+=~/.vim/tagfiles/opencv.tags # Absolute position ,tags The files are right there `~/.vim/tagfiles` Inside
YCM To configure
To configure
stay vimrc Add the following configuration :
let g:ycm_collect_identifiers_from_tags_files = 1
such ,YCM It will look up automatically vimrc As defined in tags file , And analyze it . Can be in vim Run the following command to view YCM Which is loaded in the current buffer tags file :
:echo tagfiles()
My computer runs as follows :
['/home/xuyangcao/.vim/tagfiles/opencv.tags']
matters needing attention
according to YCM Documents , It is found that clangd completer Than libclang completer Be smarter , analysis tags The document is more comprehensive .Clangd completer See resources for specific advantages [3], There is not much here .
therefore , Compiling YCM In the process , It is recommended to use --clanged-completer Parameters .
summary
This article takes opencv For example , Describes how to generate tags File to expand YCM Automatic completion function and syntax highlighting function .
Reference material
1 YCM does not read identifiers from my tags files
边栏推荐
- 脉脉网友出了道 Go 面试题,你能答对吗?
- Android系统安全 — 5.3-APK V2签名介绍
- 链表——24. 两两交换链表中的节点
- Unity C#工具类 ArrayHelper
- [assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)
- Practice 4-6 number guessing game (15 points)
- Redis learning - Introduction to redis and NiO principles
- pip3 带源安装大全
- 如何将CAD文件导入图新地球中,与影像地形倾斜模型准确叠加
- Assignment operator (geritilent software - Jiuye training)
猜你喜欢

来阿里一年后我迎来了第一次工作变动....

Open source summer interview | learn with problems, Apache dolphin scheduler, Wang Fuzheng

xtrabackup 实现mysql的全量备份与增量备份

Account 1-2

Why is TCP a triple handshake

Leetcode94-二叉树的中序遍历详解

Nuxt 路由切换后 asyncData 跨域报错
![[FFH] websocket practice of real-time chat room](/img/9a/ffd31fe8783804d40edeca515cc96c.png)
[FFH] websocket practice of real-time chat room

【基于ROS的URDF练习实例】四轮机器人与摄像头的使用
![[FFH] openharmony gnawing paper growth plan -- Application of cjson in traditional c/s model](/img/a5/a8f4371a83fbd38c40aa7ba56a36d3.png)
[FFH] openharmony gnawing paper growth plan -- Application of cjson in traditional c/s model
随机推荐
Three tips for finding the latest trends on tiktok
链表——24. 两两交换链表中的节点
[example of URDF exercise based on ROS] use of four wheeled robot and camera
Why is TCP a triple handshake
OpenCV中文文档4.0.0学习笔记(更新中……)
JUC强大的辅助类
Android系统安全 — 5.2-APK V1签名介绍
Tiktok 16 popular categories, tiktok popular products to see which one you are suitable for?
SDUT compilation principle experimental code
Replace the function of pow with two-dimensional array (solve the time overrun caused by POW)
Leetcode94 detailed explanation of middle order traversal of binary tree
VGA character display based on FPGA
UE5影视动画渲染MRQ分层学习笔记
Assignment operator (geritilent software - Jiuye training)
[the first anniversary of my creation] love needs to be commemorated, so does creation
JS built-in method
Office fallback version, from 2021 to 2019
Tang Yudi opencv background modeling
Some mistakes that Xiaobai often makes (update from time to time, and promise not to make them again next time)
Wildcards in MySQL like statements: percent, underscore, and escape