【VIM安装ctags cscope】

一、安装软件包

sudo passwd root
sudo apt install cmake python2-dev python3-dev build-essential cmake flex bison -y
sudo apt install universal-ctags cscope vim git -y
sudo apt install python-is-python3 -y
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev

二、下载VIM插件管理器

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

vim ~/.vimrc

" ==============vim基本配置==============
set guifont=Monospace\ 14
set nu!             " 显示行号
syntax enable
syntax on
colorscheme desert

set autowrite   " 自动保存

set foldmethod=syntax
set foldlevel=100  " 启动vim时不要自动折叠代码
set textwidth=80
set formatoptions+=t
set cindent
set smartindent
set noerrorbells
set showmatch
set nobackup 
set noswapfile
" set cursorline

" disable 
noremap  
noremap  
noremap  
noremap  

" remap control + arrow key to select windows
noremap   j
noremap     k
noremap   h
noremap  l
noremap  j
noremap  k
noremap  h
noremap  l

" ==============Vundle插件管理==============
" Vundle manage
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
" Plugin 'majutsushi/tagbar' " Tag bar"
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'vim-airline/vim-airline' | Plugin 'vim-airline/vim-airline-themes' " Status line"
Plugin 'jiangmiao/auto-pairs'
Plugin 'mbbill/undotree'
Plugin 'gdbmgr'
Plugin 'scrooloose/nerdcommenter'
Plugin 'Yggdroot/indentLine' " Indentation level"
Plugin 'bling/vim-bufferline' " Buffer line"
"Plugin 'kepbod/quick-scope' " Quick scope
Plugin 'yianwillis/vimcdoc'
Plugin 'nelstrom/vim-visual-star-search'
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'w0rp/ale'
Plugin 'mbbill/echofunc'
Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' }

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required


" ==============YCM==============
let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
  " YCM 查找定义
let mapleader=','
nnoremap gl :YcmCompleter GoToDeclaration
nnoremap gf :YcmCompleter GoToDefinition
nnoremap gg :YcmCompleter GoToDefinitionElseDeclaration
let g:ycm_collect_identifiers_from_tags_files = 1

set completeopt=menu,menuone   
let g:ycm_add_preview_to_completeopt = 0  " 关闭函数原型提示

let g:ycm_show_diagnostics_ui = 0 " 关闭诊断信息
let g:ycm_server_log_level = 'info'
let g:ycm_min_num_identifier_candidate_chars = 2  " 两个字符触发 补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 收集
let g:ycm_complete_in_strings=1

noremap  
let g:ycm_key_invoke_completion = ''   " YCM 里触发语义补全有一个快捷键
let g:ycm_max_num_candidates = 15  " 候选数量

let g:ycm_semantic_triggers =  {
			\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
			\ 'cs,lua,javascript': ['re!\w{2}'],
			\ }


" ===========gutentags=============
" 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project', '.gitignore']

" 添加ctags额外参数,会让tags文件变大
" let g:gutentags_ctags_extra_args = ['--fields=+niazlS', '--extra=+q']
 let g:gutentags_ctags_extra_args = ['--fields=+lS']
" let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
" let g:gutentags_ctags_extra_args += ['--c-kinds=+px']

if isdirectory("kernel/") && isdirectory("mm/")
	let g:gutentags_file_list_command = 'find arch/arm/ mm/ kernel/ include/ init/ lib/'
endif
	

" =======echodoc 显示函数参数===========
" ctags -R --fields=+lS .

"======= NetRedTree=========
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
let NERDTreeWinSize=20
"let NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1
let NERDTreeShowBookmarks=1

let g:winManagerWindowLayout='TagList'
nmap wm :WMToggle

" ======ALE静态语法检测========
let g:ale_sign_column_always = 1
let g:ale_sign_error = '✗'
let g:ale_sign_warning = 'w'
let g:ale_statusline_format = ['✗ %d', '⚡ %d', '✔ OK']
let g:ale_echo_msg_format = '[%linter%] %code: %%s'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
"let g:airline#extensions#ale#enabled = 1
let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
let g:ale_c_cppcheck_options = ''
let g:ale_cpp_cppcheck_options = ''

" ========airline状态栏=========  
let g:airline#extensions#tabline#enabled = 1
let g:airline_section_b = '%-0.10{getcwd()}'
let g:airline_section_c = '%t'
let g:airline#extensions#tagbar#enabled = 1
let g:airline_section_y = ''

"--------------------------------------------------------------------------------
" cscope:建立数据库:cscope -Rbq;  F5 查找c符号; F6 查找字符串;   F7 查找函数定义; F8 查找函数谁调用了,
"--------------------------------------------------------------------------------
if has("cscope")
  set csprg=/usr/bin/cscope
  set csto=1
  set cst
  set nocsverb
  " add any database in current directory
  if filereadable("cscope.out")
      cs add cscope.out
  endif
  set csverb
endif


:set cscopequickfix=s-,c-,d-,i-,t-,e-

nmap s :cs find s =expand("")
nmap g :cs find g =expand("")
nmap c :cs find c =expand("")
nmap t :cs find t =expand("")
nmap e :cs find e =expand("")
nmap f :cs find f =expand("")
nmap i :cs find i ^=expand("")$
nmap d :cs find d =expand("")


"nmap s :cs find s =expand("")
"F5 查找c符号; F6 查找字符串;   F7 查找函数定义; F8 查找函数谁调用了,
nmap   :cs find s =expand("") :botright copen 
nmap   :cs find t =expand("") :botright copen
"nmap   :cs find g =expand("") 
nmap   :cs find c =expand("") :botright copen


 "--------------------------------------------------------------------------------
"  自动加载ctags: ctags -R
if filereadable("tags")
      set tags=tags
endif

"--------------------------------------------------------------------------------
" global:建立数据库
"--------------------------------------------------------------------------------
if filereadable("GTAGS")
	set cscopetag
	set cscopeprg=gtags-cscope
	cs add GTAGS
	au BufWritePost *.c,*.cpp,*.h silent! !global -u &
endif

 使用以下命令安装

vim
:PluginInstall

三、编译安装YouCompelte

apt install build-essential cmake vim-nox python3-dev

cd ~/.vim/bundle/YouCompleteMe
编译安装YouCompelte

cd ~/.vim/bundle/YouCompleteMe
~/.vim/bundle/YouCompleteMe$ ./install.py --clang-completer

~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples$ cp .ycm_extra_conf.py ~/.vim

四、工具链

wget https://snapshots.linaro.org/gnu-toolchain/12.2-2023.04-1/aarch64-linux-gnu/gcc-linaro-12.2.1-2023.04-x86_64_aarch64-linux-gnu.tar.xz

export PATH=$PATH:/opt//opt/gcc-linaro-12.2.1-2023.04-x86_64_aarch64-linux-gnu/bin

export CROSS_COMPILE=aarch64-linux-gnu-

五:编译Linux kernel

sudo apt-get install gcc g++
sudo apt-get install libncurses5-dev 
sudo apt-get install build-essential
sudo apt-get install kernel-package 
sudo apt-get install libssl-dev
sudo apt-get install libc6-dev 
sudo apt-get install bin86
sudo apt-get install flex 
sudo apt-get install bison  
sudo apt-get install qttools5-dev  
sudo apt-get install libelf-dev

git clone https://mirrors.tuna.tsinghua.edu.cn/git/linux.git
或
git clone https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git


make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j8

ake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- tags cscope TAGS -j8

你可能感兴趣的:(X3M,精通嵌入式Linux编程笔记,RK3568平台驱动和内核讲解,vim,编辑器,linux)