VIM 配置及内核代码编译

1. 编译安装python

  1.1 下载 python 源代码

$wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
$tar -zxvf Python-3.6.5.tgz; cd Python-3.6.5/

  1.2 安装 zlib 相关依赖

$sudo yum -y install zlib*

  1.3 配置生成 makefile

$./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" --enable-unicode=ucs4 --enable-optimizations

  1.4 编译安装 python

$make
$sudo make altinstall 
$sudo ln -sv /usr/local/bin/python3.6 /usr/local/bin/python
$sudo unlink /usr/bin/python; sudo ln -sv /usr/local/bin/python /usr/bin/python
$sudo unlink /home/tops/bin/python; sudo ln -sv /usr/local/bin/python /home/tops/bin/python

  升级 python 之后可能会因为语法不一致导致依赖于旧版本 python 的软件工作不正常
  例如运行 yum 可能会出现如下错误

$ yum 
File "/usr/bin/yum", line 30 
except KeyboardInterrupt, e:                                         
SyntaxError: invalid syntax

  解决的办法:
  1. 升级 yum
  2. 或者修改 yum 使用的语法解释器
      修改 #!/usr/bin/python 为 #!/usr/bin/python2.7
  3. 在编译VIM之后把 /home/tops/bin/python 软连接回 python2.7

#Sctipt to switch to python 3
$cat ~/rain/p3.sh

sudo unlink /home/tops/bin/python
sudo ln -sv /usr/local/bin/python /home/tops/bin/python
ls -al /home/tops/bin/python

sudo unlink /usr/bin/python•
sudo ln -sv /usr/local/bin/python /usr/bin/python•
ls -al /usr/bin/python

#################################

#Sctipt to switch to python 2
$cat ~/rain/p2.sh

sudo mv /home/tops/bin/python /home/tops/bin/python-bak
sudo ln -sv /home/tops/bin/python2 /home/tops/bin/python
ls -al /home/tops/bin/python

sudo mv /usr/bin/python /usr/bin/python-bak•
sudo ln -sv /usr/bin/python2 /usr/bin/python•
ls -al /usr/bin/python

2. 编译安装VIM

  2.1 安装相关依赖,如果可以直接安装 python可以省去前面编译过程

$sudo yum install lua lua-devel –y
$sudo yum install ncurses-devel
$sudo yum install -y ruby ruby-devel lua lua-devel luajit uajit-devel ctags git python python-devel python3 python3-devel tcl-devel perl perl-devel perl-ExtUtils-ParseXS perl-ExtUtils-XSpp perl-ExtUtils-CBuilder perl-ExtUtils-Embed

  2.2 删除存在的 VIM

sudo yum remove vim vim-runtime gvim

  2.3 克隆 VIM 源代码

$git clone https://github.com/vim/vim.git; cd vim

  2.4 配置生成 makefile

$./configure --enable-multibyte --enable-perlinterp=yes --enable-rubyinterp=yes --enable-python3interp=yes --enable-luainterp=yes --enable-gui=auto --enable-cscope --disable-selinux --with-features=huge --prefix=/usr/local

  如果编译之后的 VIM 版本信息里面不包含 +python3,可以尝试添加 Python3 配置路径 

--with-python3-config-dir=/usr/local/lib/python3.6/config-3.6m-x86_64-linux-gnu

  python路径需要改成实际路径

  2.5 编译安装VIM 到 /usr/local/share/vim/vim80

make VIMRUNTIMEDIR=/usr/local/share/vim/vim80
sudo make install

3 配置 VIM

  3.1 安装配置 spf13 (refer to https://github.com/spf13/spf13-vim)

curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh

  安装后会创建 ~/.spf13-vim-3 目录,对于 VIM 的配置基本上只需要涉及如下文件
  1. ~/.vimrc.before.local 自定义配置,spf13 加载 .vimrc 之后被读取
  2. ~/.vimrc.bundles.local 自定义安装插件配置

  如果前面安装的时候没有指定 VIM 的运行时路径可以在 ~/.vimrc.before.local 里面添加

let $VIMRUNTIME=”/usr/local/share/vim/vim80”


  解决拼写错误  Warning: Cannot find word list "en.utf-8.spl" or "en.ascii.spl"
  运行 VIM 并执行 :echo substitute(&rtp, ',', '\n', 'g') 来检查 $VIMRUNTIME 是不是存在,    如果不存在于上述命令的结果,在 ~/.vimrc.before 里面添加

set rtp^=$VIMRUNTIME


  设置拷贝内容到系统剪切板,在 ~/.vimrc.before 里面添加

set copy to clipboard
set clipboard=unnamedplus


  设置 VIM 配色主题,在 ~/.vimrc.before.local 或者 ~/.vimrc.local 里面添加

"colorscheme desert
"colorscheme gruvbox
"colorscheme molokai
"colorscheme solarized
"目前喜欢这个主题
colorscheme ron

  3.2 安装基于语义的自动补全插件 YouCompleteMe (refer to https://github.com/Valloric/YouCompleteMe)

  用 VIM 打开 ~/.vimrc.before.local 并添加

let g:spf13_bundle_groups=['general', 'programming', 'misc', 'scala', 'youcompleteme']

 
  在打开的VIM里执行命令更新插件,会自动安装YouCompleteMe

:w
:RundleInstall
:wq

    3.2.1 Troubleshooting

    YouCompleteMe unavailable no module named frozendict( or future)。
  【原因】
    YCM 依赖的安装包没有成功安装,一般是网速不佳,下载出错,或者中途人为退出。
  【解决方法】
    手工安装。 例如

$sudo pip3 install future

    或者通过 GIT 重新克隆依赖的库之后再安装

$cd ~/.vim/bundle/YouCompleteMe/; git submodule update --init --recursive; vim +BundleInstall

   3.2.2 安装 cmake

  YouCompleteMe 用 cmake 编译代码来分析依赖关系,并提示可能的语法错误

yum install cmake

  或者下载源代码编译安装
  https://www.atatech.org/articles/105727

  3.2.3 编译YouCompleteMe,相当于生成符号的数据库 ycm_core.so

$cd ~/.vim/bundle/YouCompleteMe; ./install.py --clang-completer --enable-coverage --enable-debug

  3.2.4 配置对 C/C++ (clang) 代码的自动补全

  设置代码补全的搜索路径,可以添加其他目录

$sudo mkdir -p -m 777 ~/.vim/data/ycm
$cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~/.vim/data/ycm/
$vim ~/.vim/data/ycm/.ycm_extra_conf.py
# [Rain] Additional include path
'-isystem', '/usr/include',
'-isystem', '/usr/local/include',
'-isystem', '/usr/include/c++/4.8.5',
'-I', '/usr/src/kernels/3.10.0-327.ali2010.alios7.x86_64/include'

  3.2.5 启动 VIM 时自动加载 YCM,在 ~/.vimrc.before.local 里添加

let g:acp_enableAtStartup = 1

  3.2.6 设置额外查找路径的 python 脚本路径

" global conf which is needed to resolve name in system include
" file or other  third-part include file
let g:ycm_global_ycm_extra_conf='~/.vim/data/ycm/.ycm_extra_conf.py'

  3.2.7 允许使用tags来进行补全

"enable completion from tags
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_cache_omnifunc=0
let g:ycm_key_invoke_completion = '<C-;>'

  3.2.8 Troubleshooting 

  •   Can't jump to definition
    在 VIM 里执行命令
    : YcmDiag​

    把提示的头文件的目录添加到~/.vim/data/ycm/.ycm_extra_conf.py 

  3.4 配置 VIM-Airline

  3.4.1 MaxOS 安装 PowerLine 字体,否则状态栏会出现乱码

# Install powerline font on MaxOS
$cd ~/.vim/bundle/fonts; ./install.sh

  3.4.2 更改 iterm2 文本字体

  通过快捷键Command+, 或者菜单(iterm2 -> Preferences)打开首选项->profile->text->Change Fonts,选择以 for powerline 结尾的字体。

VIM 配置及内核代码编译

  3.4 设置快捷键

  设置快捷键 F5 更新依赖关系,也就是用cmake编译代码

nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>

 
  设置快捷键 F12 跳转声明和定义以及打开包含的头文件

nnoremap <F12> :YcmCompleter GoToDefinitionElseDeclaration<CR>

  3.10 安装、删除插件

echo Bundle \'Plugin Name\' >> ~/.vimrc.bundles.local

 
  例如安装vim官网的 grep 插件,我们可以使用

echo Bundle \‘vim-scripts/grep.vim\'  >> ~/.vimrc.bundles.local

 
  添加之后使用如下命令来安装

vim +BundleInstall! +BundleClean +q

 
  如果已经打开了 VIM 可以直接执行命令

:BundleInstall

 
  删除已经安装的插件

echo UnBundle \'Plugin Name\' >> ~/.vimrc.bundles.local


  执行删除插件的命令

vim +BundleClean +q


  如果已经打开了 VIM 可以直接执行命令

:BundleClean


  例如删除 vim官网的 grep 插件,我们可以使用

echo UnBundle \‘vim-scripts/grep.vim\'  >> ~/.vimrc.bundles.local

  3.11 自定义 VIM 颜色主题

  可以访问 http://bytefluent.com/vivify/
VIM 配置及内核代码编译

  保存颜色主题文件到本地之后拷贝到 VIM 颜色主题目录,然后更改 ~\.vimrc.local

$cp rain.vim to ~\.vim\colors
$echo colorscheme rain >> ~\.vimrc.local


  设置对.vimrc的更改立即生效

echo autocmd BufWritePost $MYVIMRC source $MYVIMRC >> .vimrc.before.local

  3.12 VIM 效果
VIM 配置及内核代码编译

  3.13 我使用的几个配置

  .vimrc.before.local 内容

let g:airline_powerline_fonts=1
let $VIMRUNTIME="/usr/local/share/vim/vim80"
set rtp^=$VIMRUNTIME
set clipboard=unnamedplus
let g:spf13_bundle_groups=['general', 'programming', 'misc', 'scala', 'youcompleteme', 'neocomplete' ]
let g:acp_enableAtStartup = 1

" configuration file for YCM to find include files
let g:ycm_global_ycm_extra_conf = '~/.vim/data/ycm/.ycm_extra_conf.py'

" enable completion from tags
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_cache_omnifunc = 1
let g:ycm_key_invoke_completion = '<C-K>'
let g:ycm_show_diagnostics_ui = 1
let g:ycm_always_populate_location_list = 1

" Disable highlight error/warning detected by syntastic
let g:syntastic_enable_highlighting = 0
let g:ycm_enable_diagnostic_highlighting = 0
" let g:syntastic_cpp_compiler = 'clang++'

" Enable code style check by cpplint
let g:syntastic_cpp_cpplint_exec = 'cpplint'
let g:syntastic_cpp_checkers = ['cpplint', 'gcc']
let g:syntastic_cpp_cpplint_thres = 1

" Set syntastic symbol icon
let g:syntastic_error_symbol = ""
let g:syntastic_warning_symbol = ""
let g:syntastic_style_error_symbol = '!'
let g:syntastic_style_warning_symbol = '?'

" Let syntax check and code style check show together
let syntastic_aggregate_errors = 1

autocmd BufWritePost $MYVIMRC source $MYVIMRC
set t_Co=256
set cursorline cursorcolumn
highlight CursorLine guibg=lightblue ctermbg=darkgray

" Setting for airline
" Airline theme
let g:airline_theme="luna"

" Enable powerline font to show arrow correctly
let g:airline_powerline_fonts = 1

" Enable tabline, show buffers in same tab
let g:airline#extensions#tabline#enabled = 1
" Show full path of current file in tab
let g:airline#extensions#tabline#fnamemod = ':p:~'
" Just show file name of current file in tab
"let g:airline#extensions#tabline#fnamemod = ':p:.'
" if show exact file path or collapsed path
let g:airline#extensions#tabline#fnamecollapse = 0
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#show_tab_nr = 1
" Show full path of current file in status bar
let g:airline_section_c = '%F'


 " Set hotkey to switch buffer
noremap <F1> :bn<CR>
noremap <F2> :bp<CR>

" hotkey for Grep.vim
noremap <F3> :Grep<CR>
noremap <F4> :Rgrep<CR>

" Setting for Tagbar
noremap <F5> :TagbarToggle<CR>
let g:tagbar_ctags_bin = 'ctags'
let g:tagbar_left = 0
let g:tagbar_width = 30
let g:tagbar_autofocus = 1
let g:tagbar_sort = 0

" Setting for NERDTree
noremap <F6> :NERDTreeToggle<CR>
let NERDTreeWinSize=32
let NERDTreeWinPos="left"
let NERDTreeShowHidden=1
let NERDTreeMinimalUI=1
let NERDTreeAutoDeleteBuffer=1

" Hotkey to switch header and source file
noremap <F7> :call CurtineIncSw()<CR>

set tags=tags
"noremap <F8> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.ctags/tags .<CR>

" Control vim to allow copy by xterm2
set number
set mouse=a
let g:Xterm2Copy=1
function! AllowXterm2Copy()
    if g:Xterm2Copy==0
        set number
        set mouse=a
        let g:Xterm2Copy=1
    else
        set nonumber
        set mouse-=a
        let g:Xterm2Copy=0
    endif
endfunction
noremap <F8> :call AllowXterm2Copy() <CR>

"noremap <F9> :YcmCompleter GetType<CR>

" Spell Check
setlocal nospell
let g:SpellChecking=0
function! SpellCheck()
    if g:SpellChecking==0
        setlocal spell spelllang=en_us
        echo "Spell checking based on en_us"
        let g:SpellChecking=1
    else
        setlocal nospell
        echo "Disable spell checking"
        let g:SpellChecking=0
    endif
endfunction


noremap <silent> <F9> :call SpellCheck()<CR>

" Map F10 to Control-O for run command in normal mode once  in only in insert mode
inoremap <F10> <C-O>

noremap <F11> :YcmDiags<CR>
"noremap <F11> :YcmForceCompileAndDiagnostics<CR>
noremap <F12> :YcmCompleter GoToDefinitionElseDeclaration<CR>

noremap <C-A> :cn<CR>
" Map ctrl-D to switch vim and shell
noremap <C-D> :sh<CR>


  .vimrc.bundles.local 内容

Bundle 'vim-scripts/conque-gdb'
Bundle 'vim-scripts/cscope.vim'
Bundle 'yegappan/grep'
Bundle 'neovim/neovim'
Bundle 'ericcurtin/CurtineIncSw.vim'


  .vimrc.local 内容

"colorscheme gruvbox
colorscheme ron

4 下载编译Linux 内核

  4.1 克隆master代码

$mkdir –m 777 kernelsrc; cd kernelsrc
$git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

  4.2 更新到特定版本快照

git tag -l | grep v3.10.*
git checkout v3.10

  4.3 创建系统内核包含文件到我们下载的代码

$sudo unlink /usr/src/linux; ln -sv ~/rain/kernelsrc/linux-stable/ /usr/src/linux

  4.4 创建软连接来解决编译错误 “missing files in asm folder”

$sudo ln -vs /usr/src/linux/arch/arm64/include/asm/ /usr/src/linux/include/asm

  4.5 拷贝内核配置文件及选择启用的系统模块

$cp /boot/config-3.10.0-327.el7.x86_64 .config
Or 
$zcat /proc/config.gz > .config

#Load kernel configuration from .config and ask confirm for other modules, then save original .config to .config.old
make menuconfig

#Set kernel name, not use empty character to avoid following trouble
General setup -> Local version

  4.6 创建虚拟窗口防止SSH终端断开连接影响编译

yum install screen
#List all allocated virtual windows
screen –ls
#Exit virtual window
screen –X quit

  4.7 编译内核

#Compile using 2 jobs
make –j2

#Install new kernel
make modules_install install

#[Troubleshooting]Make install error “Missing file: Debug, You need to run "make" before "make install"
make modules
make install

#Clean kernel build

#Remove most intermediate files except config file
make clean

#Remove intermediate files and config file
make mrproper

#Remove manually
remove modules not needed from /lib/modules/
remove kernel image from /boot
remove kernel source code from /usr/src/linux

#Modify grub configuration to remove startup item
vim /etc/grub2.cfg

 

 

 

 

 

 

上一篇:centos vim配置高亮语法和格式化粘贴


下一篇:C++程序设计师生互动(2012年春第6周)