VIM在CentOS7上的无root权限安装

VIM 在Centos7上的安装与配置

VIM8是目前的最新版本,它有非常多的特性可以提高我们的生产效率,所以我们这里以VIM8为例

VIM8 编译前的准备

我们需要安装两个重要的插件,一个是leaderf, 一个是coc.nvim, 前者依赖python, 后者依赖node.js. 所以我们需要先安装这两个

安装python3

源代码安装, 可以下载3.8.x或3.9.x

wget https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz
wget https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tgz
wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz

要生成动态链接库,不能开优化

./configure --prefix=/home/harriszh/.local --enable-shared --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions
make -j4
make install

/home/harriszh/.local/lib加入到LD_LIBRARY_PATH

安装gcc9

yum install centos-release-scl -y
yum clean all
yum install devtoolset-9-* -y

不建议一直开着,只在需要时source /opt/rh/devtoolset-9/enable(需要用bash或zsh)

安装node.js

需要用gcc9

下载源码:

wget https://nodejs.org/dist/v16.15.0/node-v16.15.0.tar.gz

官方要求如下:

    gcc and g++ >= 8.3 or newer
    GNU Make 3.81 or newer
    Python 3.6, 3.7, 3.8, 3.9, or 3.10 (see note above)
        For test coverage, your Python installation must include pip.

解压后

./configuration --prefix=/home/harriszh/.local
make -j4
make install

安装powerline

pip3 install --user git+https://github.com/powerline/powerline

安装vim

然后用源码装vim

git clone https://github.com/vim/vim.git
cd vim/src
./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp \
            --enable-python3interp \
            --with-python3-config-dir=/home/harriszh/.local/lib/python3.8/config-3.8m-x86_64-linux-gnu/ \
            --with-python3-command=/home/harriszh/.local/bin/python3 \
            --enable-perlinterp \
            --enable-luainterp \
            --with-lua_prefix=/home/harriszh/.local \
            --enable-gui=gtk2 --enable-cscope
make && make install

Ripgrep

先安装 RUST

curl https://sh.rustup.rs -sSf | sh

然后一路 enter 就好了

用 RUST 安装 rigpre

cargo install ripgrep

默认放在~/.cargo/bin

直接拷贝

最简单的方法是从别人那边拷贝一份rg的可执行程序

fd

cargo install fd-find

默认放在~/.cargo/bin

fzf

fzf安装

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

fzf配置

#fzf
export LD_LIBRARY_PATH=/usr/local/lib:/lib64:/usr/lib64:/usr/lib:/lib
if [ ${CURSHELL} = "bash" ]; then
    [ -f ~/.fzf.bash ] && source ~/.fzf.bash
elif [ ${CURSHELL} = "zsh" ]; then
    [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
fi
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_DEFAULT_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND='rg --sort-files --files --null 2> /dev/null | xargs -0 dirname | uniq'

#Use fd instead of the default find command for listing candidates
_fzf_compgen_path() {
    rg -g "" -- "$1"
}

# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
  fd --type d --hidden --follow --exclude ".git" . "$1"
}

# repeat history
fh() {
  eval $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}

# fd - cd to selected directory
fd() {
  local dir
  dir=$(fd ${1:-.} --type d -print 2> /dev/null | fzf +m) &&
  cd "$dir"
}

# fda - including hidden directories
fda() {
  local dir
  dir=$(fd ${1:-.} --type d 2> /dev/null | fzf +m) && cd "$dir"
}

fzfp() {
  fzf --preview '[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (rougify {}  || highlight -O ansi -l {} || coderay {} || cat {}) 2> /dev/null | head -500'
}

# click Ctrl-X+Ctrl-R to execute
fzf-history-widget-accept() {
  fzf-history-widget
  zle accept-line
}
zle    -N    fzf-history-widget-accept
bindkey '^X^R' fzf-history-widget-accept

# interactive cd
source ~/.fzf/shell/zsh-interactive-cd.zshrc

安装vim-plug

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

如果不能下载的话, 手工从https://github.com/junegunn/vim-plug里把plug.vim下载后放到~/.vim/autoload

然后在~/.vimrc加上

call plug#begin()
Plug 'junegunn/seoul256.vim'
Plug 'yianwillis/vimcdoc'
Plug 'honza/vim-snippets'
let s:my_loading_vim_snippets = 1
Plug 'zhuzhzh/verilog_emacsauto.vim'
Plug 'junegunn/fzf', { 'dir':'~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
let s:my_loading_fzf = 1
if version >= 800
    if is_win
        Plug 'liuchengxu/vim-clap', { 'do': { -> clap#installer#force_download() } }
    else
        Plug 'liuchengxu/vim-clap', { 'do': ':Clap install-binary' }
    endif
    let s:my_loading_vim_clap = 1
    Plug 'dense-analysis/ale', { 'for': ['cpp', 'c']}
    let s:my_loading_ale = 1
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    let s:my_coc_nvim = 1
    Plug 'nanotee/zoxide.vim'
    let s:my_loading_zoxide = 1
    Plug 'Yggdroot/LeaderF', {'do': ':LeaderfInstallCExtension'}
    let s:my_loading_leaderf = 1
    Plug 'skywind3000/asyncrun.vim'
    let s:my_loading_asyncrun = 1
endif
Plug 'preservim/nerdtree', {'on': 'NERDTreeToggle'}
let s:my_loading_nerdtree = 1
Plug 'junegunn/vim-easy-align'
let s:my_loading_vimeasyalign = 1
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }
call plug#end()

退出vim后, 再进入vim, 输入:PlugInstall

配置插件

powerline

if !is_win
    python3 from powerline.vim import setup as powerline_setup
    python3 powerline_setup()
    python3 del powerline_setup
endif

vim-clap

"-----------------------------------------------------------------------------
" plugin - vim-clap
"-----------------------------------------------------------------------------
if exists("s:my_loading_vim_clap")
    let g:clap_theme = 'material_design_dark'
    let g:clap_builtin_fuzzy_filter_threshold = 0
    noremap ff :Clap files
    noremap ft :Clap tags
    noremap fl :Clap lines
    noremap fm :Clap history
    noremap fb :Clap buffers
    noremap fc :Clap colors
    noremap fg :Clap grep
    noremap fj :Clap jumps
    noremap fk :Clap marks
    noremap fq :Clap quickfix
    noremap fd :Clap dumb_jump
    noremap fr :Clap filer
    noremap fo :Clap gfiles
    noremap fu :Clap git_diff_files
endif
"------------------------END vim-clap--------------------------------------

LeaderF

可选的还有fzf.vim

"----------------------------------------------------------------------------- 
" plugin - LeaderF
"----------------------------------------------------------------------------- 
if exists("s:my_loading_leaderf")
    " don't show the help in normal mode
    let g:Lf_HideHelp = 1
    let g:Lf_UseCache = 0
    let g:Lf_UseVersionControlTool = 0
    let g:Lf_IgnoreCurrentBufferName = 1
    " popup mode
    let g:Lf_WindowPosition = 'popup'
    let g:Lf_PreviewInPopup = 1
    let g:Lf_StlSeparator = { 'left': "\ue0b0", 'right': "\ue0b2", 'font': "MesloLGS Nerd Font Mono" }
    let g:Lf_PreviewResult = {'Function': 0, 'BufTag': 0 }

    let g:Lf_ShowDevIcons = 1
    let g:Lf_DevIconsFont = "MesloLGS Nerd Font Mono" 

    let g:Lf_ShortcutF = "ff"
    noremap fb :=printf("Leaderf buffer %s", "")
    noremap fm :=printf("Leaderf mru %s", "")
    noremap ft :=printf("Leaderf bufTag %s", "")
    noremap fl :=printf("Leaderf line %s", "")

    noremap fc :=printf("Leaderf! rg --current-buffer -e %s ", expand(""))
    noremap fa :=printf("Leaderf! rg -e %s ", expand(""))
    " search visually selected text literally
    xnoremap gf :=printf("Leaderf! rg -F -e %s ", leaderf#Rg#visual())
    noremap go :Leaderf! rg --recall

    " should use `Leaderf gtags --update` first
    let g:Lf_GtagsAutoGenerate = 0
    let g:Lf_Gtagslabel = 'native-pygments'
    noremap fg :=printf("Leaderf! gtags --update")
    noremap fr :=printf("Leaderf! gtags -r %s --auto-jump", expand(""))
    noremap fd :=printf("Leaderf! gtags -d %s --auto-jump", expand(""))
    noremap fo :=printf("Leaderf! gtags --recall %s", "")
    noremap fn :=printf("Leaderf gtags --next %s", "")
    noremap fp :=printf("Leaderf gtags --previous %s", "")

    let g:Lf_ShowHidden = 1

    let g:Lf_RgConfig = [
    \ "--hidden",
    \ "--no-messages",
    \ "--color never",
    \ "--no-ignore"
    \ ]

    let g:Lf_WildIgnore = {
      \ 'dir': ['.root','.svn','.git','.hg','.ccls-cache'],
      \ 'file': ['*.sw?','~$*', '*swp', '*.bak','*.exe','*.o','*.so','*.py[co]']
      \}

    let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git', '.root']
endif
"------------------------END LeaderF--------------------------------------

coc.nvim

"----------------------------------------------------------------------------- 
" plugin -coc.nvim
"----------------------------------------------------------------------------- 
if exists("s:my_coc_nvim")
    " NOTE: Use command ':verbose imap ' to make sure tab is not mapped by
    " other plugin before putting this into your config.
     inoremap  
      \ pumvisible() ? coc#_select_confirm() :
      \ coc#expandableOrJumpable() ? "\=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\" :
      \ check_back_space() ? "\" :
      \ coc#refresh()

    inoremap  pumvisible() ? "\" : "\"

    function! s:check_back_space() abort
        let col = col('.') - 1
        return !col || getline('.')[col - 1]  =~# '\s'
    endfunction

    inoremap   pumvisible() ? coc#_select_confirm()
                              \: "\u\\=coc#on_enter()\"

    "let g:coc_snippet_next = ''

    " Use  for trigger snippet expand.
    imap  (coc-snippets-expand)

    " Use  for select text for visual placeholder of snippet.
    vmap  (coc-snippets-select)

    " Use  for jump to next placeholder, it's default of coc.nvim
    let g:coc_snippet_next = ''

    " Use  for jump to previous placeholder, it's default of coc.nvim
    let g:coc_snippet_prev = ''

    " Use  for both expand and jump (make expand higher priority.)
    imap  (coc-snippets-expand-jump)

    " Use x for convert visual selected code to snippet
    xmap x  (coc-convert-snippet)

    " GoTo code navigation.
    nmap  gd (coc-definition)
    nmap  gD (coc-type-definition)
    nmap  gi (coc-implementation)
    nmap  gr (coc-references)

    " Use K to show documentation in preview window.
    nnoremap  K :call show_documentation()

    function! s:show_documentation()
      if CocAction('hasProvider', 'hover')
        call CocActionAsync('doHover')
      else
        call feedkeys('K', 'in')
      endif
    endfunction

    " Highlight the symbol and its references when holding the cursor.
    autocmd CursorHold * silent call CocActionAsync('highlight')

    " Symbol renaming.
    nmap rn (coc-rename)

    " Remap  and  for scroll float windows/popups.
    if has('nvim-0.4.0') || has('patch-8.2.0750')
      nnoremap   coc#float#has_scroll() ? coc#float#scroll(1) : "\"
      nnoremap   coc#float#has_scroll() ? coc#float#scroll(0) : "\"
      inoremap   coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\"
      inoremap   coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\"
      vnoremap   coc#float#has_scroll() ? coc#float#scroll(1) : "\"
      vnoremap   coc#float#has_scroll() ? coc#float#scroll(0) : "\"
    endif

    " Using Coc-explorer
    noremap ee :CocCommand explorer
    " Close Coc-explorer if it is the only window
    autocmd BufEnter * if (&ft == 'coc-explorer' && winnr("$") == 1) | q | endif

    autocmd CursorHold * silent call CocActionAsync('highlight')

    " Run the Code Lens action on the current line.
    nmap cl  (coc-codelens-action)
    
    " Map function and class text objects
    " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
    xmap if (coc-funcobj-i)
    omap if (coc-funcobj-i)
    xmap af (coc-funcobj-a)
    omap af (coc-funcobj-a)
    xmap ic (coc-classobj-i)
    omap ic (coc-classobj-i)
    xmap ac (coc-classobj-a)
    omap ac (coc-classobj-a)

    " Mappings for CoCList
    " Show all diagnostics.
    nnoremap  ca  :CocList diagnostics
    " Manage extensions.
    nnoremap  ce  :CocList extensions
    " Show commands.
    nnoremap  cc  :CocList commands
    " Find symbol of current document.
    nnoremap  co  :CocList outline
    " Search workspace symbols.
    nnoremap  cs  :CocList -I symbols
    " Do default action for next item.
    nnoremap  cj  :CocNext
    " Do default action for previous item.
    nnoremap  ck  :CocPrev
    " Resume latest coc list.
    nnoremap  cp  :CocListResume

    command! SvBuildIndex call CocRequest("svlangserver", 'workspace/executeCommand', {'command': 'systemverilog.build_index'})
    command! -range SvReportHierarchy call CocRequest("svlangserver", 'workspace/executeCommand', {'command': 'systemverilog.report_hierarchy', 'arguments': [input('Module/interface: ',  == 0 ? "" : expand(""))]})

endif
"----------------------END coc.nvim--------------------------------------

vista.vim

vista依赖带有json输出功能的ctags

if exists("s:my_loading_vista")
    " How each level is indented and what to prepend.
    " This could make the display more compact or more spacious.
    " e.g., more compact: ["▸ ", ""]
    " Note: this option only works for the kind renderer, not the tree renderer.
    let g:vista_icon_indent = ["╰─▸ ", "├─▸ "]
        " Executive used when opening vista sidebar without specifying it.
    " See all the avaliable executives via `:echo g:vista#executives`.
    let g:vista_default_executive = 'ctags'

    " To enable fzf's preview window set g:vista_fzf_preview.
    " The elements of g:vista_fzf_preview will be passed as arguments to fzf#vim#with_preview()
    " For example:
    let g:vista_fzf_preview = ['right:50%']

    " Ensure you have installed some decent font to show these pretty symbols, then you can enable icon for the kind.
    let g:vista#renderer#enable_icon = 1

    " The default icons can't be suitable for all the filetypes, you can extend it as you wish.
    let g:vista#renderer#icons = {
    \   "function": "\uf794",
    \   "variable": "\uf71b",
    \  }

    nnoremap vt :Vista ctags
    nnoremap vo :Vista coc
    nnoremap vft :Vista finder ctags
    nnoremap vfo :Vista finder coc
endif

你可能感兴趣的:(vimcentos7)