vim的配置_vim全局配置

2022-11-14 09:49:07 浏览数 (2)

大家好,又见面了,我是你们的朋友全栈君。

vim 全家桶配置指南(持续更新)

简介
代码语言:javascript复制
本教程适用前后端。

因为写了一段时间前端,一直在考虑vim是否能够替代前端无敌编辑器vscode,最后发现只能高仿,自己配置的性能跟vscode下的vim模式差不多,灵活性更高点,喜欢折腾的朋友可以试试,否则用vscode vim模式吧,已经神一般的完美了(不是高级黑-。-)。 这套插件目前包含了代码自动补全,目录树,js/jsx eslint自动格式化,小黑屋模式, 文件搜索ctrlp,快速检索ack,emmet,函数工具条还有各种奇奇插插的主题配置而成, 别想歪。这里我做了一堆的配置,大家可以根据个人喜好,配置任意的快捷键。我是一边做一边写的文章,有些东西可能没考虑到,有问题可以给我留言。

最终结果预览图
安装
预安装python3
代码语言:javascript复制
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
./configure --enable-python3interp=yes --enable-shared --prefix=/usr    (关键要开启python api注入,enable-share
开启让YCM能读库)
--with-openssl=$(brew --prefix openssl) # macos用户需要增加额外参数, prefix改成/usr/local(高版本osx系统因为usr目录没权限)
make && make install
预安装vim8
代码语言:javascript复制
(1)不要在aws ec2执行,会卸载sudo(yum remove `yum list|grep -E '^vim.*'|awk -F" " '{print $1}'` -y)
(2)git clone https://github.com/vim/vim.git
(3)cd vim/src
(4)git checkout v8.2.0368
常用依赖装下<<<yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel>>>
### pythoninterp, python3interp为了是vim支持python python3的解释器注入
(5)./configure 
  --disable-nls 
  --enable-cscope 
  --enable-gui=no 
  --enable-multibyte  
  --enable-python3interp 
(6) make && make install
1.vundle vi包管理工具
代码语言:javascript复制
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
2.vimrc配置

更新日志: 2019年03月04日:终端支持256色,代码可视化缩进块,ctags自动更新脚本,一些小配置的demo 2020年01月19日:增加scala支持,可以用来简单编辑,没有idea顺畅

代码语言:javascript复制
(1) vim ~/.vimrc
(2) 把下配置文件复制进去
代码语言:javascript复制
set nocompatible
filetype off
set rtp =~/.vim/bundle/Vundle.vim
call vundle#begin()
"文件检索ctrl p
Plugin 'ctrlp.vim'
"vim包管理工具
Plugin 'gmarik/Vundle.vim'
"vim自动格式化(配合命令行eslint phplint xxxx等使用)
Plugin 'Chiel92/vim-autoformat'
"文件目录分屏
Bundle 'scrooloose/nerdtree'
"文件目录增加git 状态
Plugin 'Xuyuanp/nerdtree-git-plugin'
"文件函数/类名提取分屏
Bundle 'majutsushi/tagbar'
"小黑屋模式
Bundle 'junegunn/goyo.vim'
"tab智能补全
Plugin 'ervandew/supertab'
"函数快速检索(前端开发可以不配置)
Plugin 'tacahiroy/ctrlp-funky'
"js 全家桶
Plugin 'mxw/vim-jsx'
Plugin 'isRuslan/vim-es6'
Plugin 'pangloss/vim-javascript'
"语法检测
Plugin 'scrooloose/syntastic'
"html emmet
Plugin 'mattn/emmet-vim'
"代码折叠
Plugin 'tmhedberg/SimpylFold'
"自动补全(vim难装插件之一)
Plugin 'Valloric/YouCompleteMe'
"vim底层命令行git美化
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
"vim主题(vscode主题,可以不装)
Plugin 'tomasiser/vim-code-dark'
"ack命令在vim中的快速检索
Plugin 'mileszs/ack.vim'
"https://beyondgrep.com/ack-2.24-single-file > /usr/local/bin/ack
"代码可视化缩进块
Plugin 'nathanaelkane/vim-indent-guides'
"彩虹括号
Plugin 'kien/rainbow_parentheses.vim'
"搜索快乐就完事了
Bundle 'Lokaltog/vim-easymotion'
"youcomplateme 通过 jedi补全python
Bundle "davidhalter/jedi"
"括号自动匹配
Plugin 'jiangmiao/auto-pairs'
"真彩色
Plugin 'tpope/vim-sensible'
"git左边栏增删改提示
Plugin 'airblade/vim-gitgutter'
" tmux Status Line, 依赖 powerline,tmux组件
Plugin 'edkolev/tmuxline.vim'
" 只有mac能用,依赖mac必须装dash APP, 用法 Dash xxx javascript
" 非mac,可以用https://github.com/KabbAmine/zeavim.vim
Plugin 'rizzatti/dash.vim'
"scala 语法解析
Plugin 'derekwyatt/vim-scala'
"PEP8 python格式化pip3 install --upgrade autopep8
Plugin 'tell-k/vim-autopep8'
filetype plugin indent on
call vundle#end()
set runtimepath^=~/.vim/bundle/ctrlp.vim
"""tagbar相关配置(ctags可执行文件不能是mac只带的ctags,mac用户需要brew install
"""ctags 并且软连接 ctags
"""为当前环境变量的ctags,然后利用ctags生成tags文件给vim函数分屏读取
"""
"let g:tagbar_ctags_bin='/usr/local/Cellar/ctags/5.8_1/bin/ctags'
let g:tagbar_right=1
set tags=tags;
set autochdir
"ctrl m开启文件tagbar(就是函数提示分屏)
map <C-m> :TagbarToggle<CR>
"""
"文件目录树分屏ctrl n
map <C-n> :NERDTreeToggle<CR>
"显示行号
set nu
"高亮搜索
set hlsearch
set ruler
set showmode
syntax on
"使用空格代替缩进.tab默认2个(前端),后端默认4个是吧
set tabstop=4
set shiftwidth=4
set expandtab
"文件编码模式指定utf
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
"""ctrlp 文件检索配置ctrl   p
nmap <F12> <ESC>:.cc<CR><C-W>p
set runtimepath^=~/.vim/bundle/ctrlp.vim
let g:ctrlp_cache_dir = $HOME.'/.cache/ctrlp'
let g:ctrlp_open_multiple_files = 'ij'
let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript', 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
let g:ctrlp_working_path_mode = 'ra'
set wildignore =*/tmp/*,*/node_modules/*,*.so,*.swp,*.zip
let g:ctrlp_custom_ignore = {'dir':  'v[/].(git|hg|svn)$', 'file': 'v.(exe|so|dll)$'}
let g:SuperTabDefaultCompletionType = 'context'
"""
syntax enable
"主题色配置
colorscheme onedark 
set nocompatible
"设置不产生swp文件
set nobackup
set autochdir
"字体配置
set guifont=Consolas:h17
set laststatus=2
set backspace=2
"一些vim内置高亮覆盖,参考highlight
"highlight LineNr cterm=bold ctermfg=242 
"hi Search cterm=NONE ctermfg=blue ctermbg=black cterm=reverse
"highlight Directory ctermfg=blue
set cursorline
"""jsx配置(一定要保证你eslint是全局的啊,软链接到/usr/local/bin/下面)
"let g:jsx_ext_required = 1 " Allow JSX in normal JS files
"js AutoFormat配置
"eslint 建议用项目里面的node_modules里的eslint.js bin 文件 sudo ln -s /Users/fdd/work/agent-activity-website/node_modules/eslint/bin/eslint.js /usr/local/bin/eslint
"let g:syntastic_javascript_checkers = ['eslint']
"eslint保存检测太卡了(太吃配置,改成被动模式)
let g:syntastic_enable_signs=1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list=1
let g:syntastic_enable_highlighting = 1
let g:syntastic_echo_current_error = 1
let g:syntastic_auto_jump = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1
"let g:syntastic_mode_map={'mode': 'passive'}
let g:syntastic_error_symbol = "u2717"
let g:syntastic_warning_symbol = "u26A0"
"let g:formatdef_eslint = '"SRC=eslint-temp-${RANDOM}.js; cat - >$SRC; eslint --fix $SRC >/dev/null 2>&1; cat $SRC | perl -pe "chomp if eof"; rm -f $SRC"'
"let g:formatters_javascript = ['eslint']
highlight SyntasticError ctermfg=240 ctermbg=204
set statusline =%#warningmsg#
set statusline =%{SyntasticStatuslineFlag()}
set statusline =%*
"-->  上面定义的 formatter 做了这些事情:
"-->  1将标准输入写到临时文件eslint-temp-xxx.js
"-->  2调用 eslint --fix 来修复它
"-->  3将 eslint-temp-xxx.js 输出到标准输出。
"-->  4截掉文件尾的换行(n)
"-->  5删掉临时文件
"-->  临时文件放在当前目录而非/tmp。否则 eslint 会根据 /tmp/eslint-temp-xxx.js 路径来读取配置文件。
"-->  临时文件不命名为隐藏文件。否则 eslint 会忽略它。
"-->  干掉文件尾的换行。这是因为 Vim 读入文件尾的换行后,会再来一个换行产生两个n。
"-->  autoformat 触发
"F3快捷键开始自动格式化(eslint自动格式化)
noremap <F3> :Autoformat<CR>:w<CR>
"""html emmet(输入 tr>td*3 然后在插入模式下 ctrl y ,(逗号)  开启emmet补全)
let g:user_emmet_mode='a'    "enable all function in all mode.
let g:user_emmet_install_global = 1
autocmd FileType jsx,html,css,js EmmetInstall
set directory=$HOME/.vim/swapfiles//
"""
"代码折叠
set foldmethod=indent
augroup AutoSaveFolds
autocmd!
au BufWinLeave ?* mkview 1
au BufWinEnter ?* silent loadview 1
augroup END
"用空格来切换折叠状态
nnoremap <space> za             
"""---这条配置仅使用mac用户!!!就是你想要的vim的快捷键复制,直接在外面的qq能够黏贴出来!!!(不再需要什么tmux,xclip中转了)
set clipboard=unnamed
"""底层命令行美化,好像可以不装字体
"先安装字体 git clone https://github.com/powerline/fonts.git --depth=1 
"./install.sh
"""powerline配置
let g:Powerline_symbols = 'fancy'
set t_Co=256
set fillchars =stl: ,stlnc:
set term=xterm-256color
""" you complate me 配置 
""" 安装
"  --> 装好后去bundle里面编译,最好看文档
"  --> https://github.com/Valloric/YouCompleteMe#mac-os-x
"  --> install
"  --> cd ~/.vim/bundle/YouCompleteMe
"  --> ./install.py --clang-completer
" 2个字符之后自动补全
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_min_num_identifier_candidate_chars = 4
let g:ycm_enable_diagnostic_highlighting = 0
" ycm预览窗口不显示
set completeopt-=preview
" 补全之后自动关闭预览窗口
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_add_preview_to_completeopt = 0
" 设置默认预览窗口在下面
set splitbelow
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1
" 在注释输入中也能补全
let g:ycm_complete_in_comments = 1
" 在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 传说中的vim8   ycm异步补全, 2个字符后开始补全
if !exists('g:ycm_semantic_triggers')
let g:ycm_semantic_triggers = {}
endif
let g:ycm_semantic_triggers.python = ['re!(?=[a-zA-Z_]{2})']
" F1 手动开启函数文档
noremap <F1> :YcmCompleter GetDoc<CR>
"""
"""
"ctags配置热键自动更新
"""
function! UpdateCtags()
let curdir=getcwd()
while !filereadable("./tags")
cd ..
if getcwd() == "/"
break
endif
endwhile
if filewritable("./tags")
!ctags -R --file-scope=yes --langmap=c: .h --languages=python,php,javascript --links=yes --fields= iaS --extra= q
endif
execute ":cd " . curdir
endfunction
nmap <F5> :call UpdateCtags()<CR>
"智能缩进,当匹配到func main() {}
"当在大括号中间回车的时候,他会智能缩进,因为他知道括号中间要缩进
set smartindent
"自动缩进,当你第一行敲 tab   文字 回车后 下一行自动给你加个 tab 
set autoindent
"自定义map示例,CR(cr)代表回车,空格可以直接用Space或者一个空白符代替
map <F9> i### 作者: 张昱升<Space>  DEV<CR>### 参数:<CR>### 含义:<CR><ESC>
"自定义mapleader 前缀按键申明, 按 逗号   w键
"可以写入并且保存(相当于底层命令行模式执行了 w!)
let mapleader=","
map <leader>w :w!<CR>
"支持光标快速移动,就是支持鼠标滚轮啦,如果用的item2,如果你滚轮,它会提示你要不要开启滚轮上拉,如果开启就不需要开启这个配置,开启这个模式复制的话要按住option键
"set mouse=a
"代码缩进块显示   奇偶行缩进颜色配置   缩进块宽度
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_guide_size = 1
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  ctermbg=237
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=236
let g:indent_guides_exclude_filetypes = ['help', 'nerdtree']
let g:indent_guides_color_change_percent = 1
"彩虹括号
let g:rbpt_colorpairs = [
 ['brown',       'RoyalBlue3'],
 ['Darkblue',    'SeaGreen3'],
 ['darkgray',    'DarkOrchid3'],
 ['darkgreen',   'firebrick3'],
 ['darkcyan',    'RoyalBlue3'],
 ['darkred',     'SeaGreen3'],
 ['darkmagenta', 'DarkOrchid3'],
 ['brown',       'firebrick3'],
 ['gray',        'RoyalBlue3'],
 ['black',       'SeaGreen3'],
 ['darkmagenta', 'DarkOrchid3'],
 ['Darkblue',    'firebrick3'],
 ['darkgreen',   'RoyalBlue3'],
 ['darkcyan',    'SeaGreen3'],
 ['darkred',     'DarkOrchid3'],
 ['red',         'firebrick3'],
 ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
"""搜索快乐就完事了
let g:EasyMotion_smartcase = 1
map <Leader><leader>h <Plug>(easymotion-linebackward)
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
map <Leader><leader>l <Plug>(easymotion-lineforward)
" 重复上一次操作, 类似repeat插件, 很强大
map <Leader><leader>. <Plug>(easymotion-repeat)
"""
"因为Python已经有pylint来检查, 而且syntastic检查Python会在保存时有很长时间的卡顿, 所以禁用它对Python文件的检查
let g:syntastic_ignore_files=[".*.py$"]
"let g:syntastic_python_python_exe = 'python3'
"let g:syntastic_python_pylint_post_args =     '--msg-template="{path}:{line}:{column}:{C}: [{symbol} {msg_id}] {msg} <---------->"'
"nerdTree 忽略pyc文件
let NERDTreeIgnore = ['.pyc$']
"""VimScript教程
"启动加载echom 打入vim启动日志,命令 messages
echom "Never Give Up Your Dream!!! >^.^<"
"空格选中整个单词,覆盖折叠folder的插件快捷键
map <space> viw
" -键 作为删除一行
map - dd
"上移一行
map _ k
"nmap -> normalmap
"vmap -> visualmap
"imap -> insertmap
"n   nore(不解释映射对象)   map
"v   nore(不解释映射对象)   map
"i   nore(不解释映射对象)   map
" 在通用模式下删除一行 
"nmap  -
nnoremap  dd
" U 在可视化模式下大写选中单词
vnoremap  U
" ctrl d 插入模式下删除一行,ecs回到普通模式,i再回到插入模式
inoremap <c-d> <esc>ddi
" ctrl u 插入模式转换当前单词为大写
inoremap <c-u> <esc>viwUi
"映射按键序列
nnoremap -d dd
nnoremap -c dd0
"leader 前缀使用, 关联233行
nnoremap <leader>d dd
"重读我的vimrc文件
nnoremap <leader>sv :source $MYVIMRC<cr>
"打开我的vimrc配置文件
nnoremap <leader>ev :vsp $MYVIMRC<cr>
"nnoremap <leader>zb :term zsh<cr>mpv "https://www.youtube.com/watch?v=OQZQ-VGbZAY" -vo tct<cr>
"nnoremap <leader>zb :vsp<cr>:sp<cr>:resize 20<cr>:vertical res 50<cr>
nnoremap <leader>zb :vsp<cr>:term zsh<cr>mpv "http://www.youtube.com/watch?v=OQZQ-VGbZAY" -vo tct<cr>
"利用hl.py脚本高亮py脚本编译的结果,提供舒适的可视化输出
nnoremap <leader>r :! python3 %|/Users/tap/zys/study/py_fluent/hl.py<cr>
" * 注意映射可以死循环
" nmap dd O<esc>jddk   dd 嵌套 dd命令,会无限死循环
"# abbreviations 缩略语
iabbrev adn and
"普通模式下,双引号包括当前单词
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
"插入模式下,jk退出插入模式,顺便提下 <c-[>也是可以退出插入模式
inoremap jk <esc>
"强制干掉esc,让自己用j k退出插入模式
"inoremap <esc> <nop>
"""
""" json 格式化   转utf8
"noremap <leader>json :%!python -m json.tool && native2ascii -encoding UTF-8 -reverse % %<CR>
noremap <leader>json :%!python -m json.tool<CR>
"这样选中你要运行的代码<leader>te 就会发到python shell里
nnoremap <leader>te V:call SendToTerminal()<CR>$
vnoremap <leader>te <Esc>:call SendToTerminal()<CR>
function! SendToTerminal()
let buff_n = term_list()
if len(buff_n) > 0
let buff_n = buff_n[0] " sends to most recently opened terminal
let lines = getline(getpos("'<")[1], getpos("'>")[1])
let indent = match(lines[0], '[^ t]') " check for removing unnecessary indent
for l in lines
let new_indent = match(l, '[^ t]')
if new_indent == 0
call term_sendkeys(buff_n, l. "<CR>")
else
call term_sendkeys(buff_n, l[indent:]. "<CR>")
endif
sleep 10m
endfor
endif
endfunction
""" 真彩色 -测试脚本 https://github.com/JohnMorales/dotfiles/blob/master/colors/24-bit-color.sh
"curl -s https://raw.githubusercontent.com/JohnMorales/dotfiles/master/colors/24-bit-color.sh | bash
set termguicolors
if &term =~# '^screen'
let &t_8f = "<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "<Esc>[48;2;%lu;%lu;%lum"
endif
" '<-1d | '> 1d  删除块的前一行,和后一行
"""  git左边状态插件配置
" 检查修改间隔时间 ms
set updatetime=100
" 高亮,仿git diff
highlight GitGutterAdd    guifg=#009900 ctermfg=2 ctermbg=39
highlight GitGutterChange guifg=#bbbb00 ctermfg=3 ctermbg=204
highlight GitGutterDelete guifg=#ff2222 ctermfg=1 ctermbg=59
" vim tmux 居中展示风格
let g:tmuxline_preset = 'full'
" 检查tmux环境变量,如果有,就改变vim的底部powerline样式 
if $TMUX != ""
autocmd VimEnter * Tmuxline powerline
endif
" scala 缩进
let g:scala_scaladoc_indent = 1
# py_fluent/hl.py 代码,作用: 在py脚本按键 “,r” 触发运行脚本(可选)
代码语言:javascript复制
#!/usr/bin/env python3
#源代码来自http://code.activestate.com/recipes/578178/
#Created by Raymond Hettinger on Sat, 30 Jun 2012 (MIT)
#改造代码,张昱升 2019年01月31日
'''Add syntax highlighting to Python source code'''
__author__ = 'Raymond Hettinger'
import keyword, tokenize, cgi, re, functools, sys
try:
import builtins
except ImportError:
import __builtin__ as builtins
#### Analyze Python Source #################################
def is_builtin(s):
'Return True if s is the name of a builtin'
return hasattr(builtins, s)
def combine_range(lines, start, end):
'Join content from a range of lines between start and end'
(srow, scol), (erow, ecol) = start, end
if srow == erow:
return lines[srow-1][scol:ecol], end
rows = [lines[srow-1][scol:]]   lines[srow: erow-1]   [lines[erow-1][:ecol]]
return ''.join(rows), end
def analyze_python(source):
'''Generate and classify chunks of Python for syntax highlighting.
Yields tuples in the form: (category, categorized_text).
'''
lines = source.splitlines(True)
lines.append('')
readline = functools.partial(next, iter(lines), '')
kind = tok_str = ''
tok_type = tokenize.COMMENT
written = (1, 0)
for tok in tokenize.generate_tokens(readline):
prev_tok_type, prev_tok_str = tok_type, tok_str
tok_type, tok_str, (srow, scol), (erow, ecol), logical_lineno = tok
kind = ''
if tok_type == tokenize.COMMENT:
kind = 'comment'
elif tok_type == tokenize.OP and tok_str[:1] not in '{}[](),.:;@':
kind = 'operator'
elif tok_type == tokenize.STRING:
kind = 'string'
if prev_tok_type == tokenize.INDENT or scol==0:
kind = 'docstring'
elif tok_type == tokenize.NAME:
if tok_str in ('def', 'class', 'import', 'from'):
kind = 'definition'
elif prev_tok_str in ('def', 'class'):
kind = 'defname'
elif keyword.iskeyword(tok_str):
kind = 'keyword'
elif is_builtin(tok_str) and prev_tok_str != '.':
kind = 'builtin'
if kind:
if written != (srow, scol):
text, written = combine_range(lines, written, (srow, scol))
yield '', text
text, written = tok_str, (erow, ecol)
yield kind, text
line_upto_token, written = combine_range(lines, written, (erow, ecol))
yield '', line_upto_token
#### Raw Output  ###########################################
def raw_highlight(classified_text):
'Straight text display of text classifications'
result = []
for kind, text in classified_text:
result.append('s:  %rn' % (kind or 'plain', text))
return ''.join(result)
#### ANSI Output ###########################################
default_ansi = {
'comment': ('33[0;31m', '33[0m'),
'string': ('33[0;32m', '33[0m'),
'docstring': ('33[0;32m', '33[0m'),
'keyword': ('33[0;33m', '33[0m'),
'builtin': ('33[0;35m', '33[0m'),
'definition': ('33[0;33m', '33[0m'),
'defname': ('33[0;34m', '33[0m'),
'operator': ('33[0;33m', '33[0m'),
}
def ansi_highlight(classified_text, colors=default_ansi):
'Add syntax highlighting to source code using ANSI escape sequences'
# http://en.wikipedia.org/wiki/ANSI_escape_code
result = []
for kind, text in classified_text:
opener, closer = colors.get(kind, ('', ''))
result  = [opener, text, closer]
return ''.join(result)
#### HTML Output ###########################################
def html_highlight(classified_text,opener='<pre class="python">n', closer='</pre>n'):
'Convert classified text to an HTML fragment'
result = [opener]
for kind, text in classified_text:
if kind:
result.append('<span class="%s">' % kind)
result.append(cgi.escape(text))
if kind:
result.append('</span>')
result.append(closer)
return ''.join(result)
default_css = {
'.comment': '{color: crimson;}',
'.string':  '{color: forestgreen;}',
'.docstring': '{color: forestgreen; font-style:italic;}',
'.keyword': '{color: darkorange;}',
'.builtin': '{color: purple;}',
'.definition': '{color: darkorange; font-weight:bold;}',
'.defname': '{color: blue;}',
'.operator': '{color: brown;}',
}
default_html = '''
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title> {title} </title>
<style type="text/css">
{css}
</style>
</head>
<body>
{body}
</body>
</html>
'''
def build_html_page(classified_text, title='python',
css=default_css, html=default_html):
'Create a complete HTML page with colorized source code'
css_str = 'n'.join(['%s %s' % item for item in css.items()])
result = html_highlight(classified_text)
title = cgi.escape(title)
return html.format(title=title, css=css_str, body=result)
#### LaTeX Output ##########################################
default_latex_commands = {
'comment': '{color{red}#1}',
'string': '{color{ForestGreen}#1}',
'docstring': '{emph{color{ForestGreen}#1}}',
'keyword': '{color{orange}#1}',
'builtin': '{color{purple}#1}',
'definition': '{color{orange}#1}',
'defname': '{color{blue}#1}',
'operator': '{color{brown}#1}',
}
default_latex_document = r'''
documentclass{article}
usepackage{alltt}
usepackage{upquote}
usepackage{color}
usepackage[usenames,dvipsnames]{xcolor}
usepackage[cm]{fullpage}
%(macros)s
begin{document}
center{LARGE{%(title)s}}
begin{alltt}
%(body)s
end{alltt}
end{document}
'''
def alltt_escape(s):
'Replace backslash and braces with their escaped equivalents'
xlat = {'{': r'{', '}': r'}', '\': r'textbackslash{}'}
return re.sub(r'[\{}]', lambda mo: xlat[mo.group()], s)
def latex_highlight(classified_text, title = 'python',
commands = default_latex_commands,
document = default_latex_document):
'Create a complete LaTeX document with colorized source code'
macros = 'n'.join(r'newcommand{py%s}[1]{%s}' % c for c in commands.items())
result = []
for kind, text in classified_text:
if kind:
result.append(r'py%s{' % kind)
result.append(alltt_escape(text))
if kind:
result.append('}')
return default_latex_document % dict(title=title, macros=macros, body=''.join(result))
if __name__ == '__main__':
import sys, argparse, webbrowser, os, textwrap
### debug
source = sys.stdin.read()
classified_text = analyze_python(source)
encoded = ansi_highlight(classified_text)
sys.stdout.write(encoded)
3.在vi 底层命令行模式

:PluginInstall 安装你的插件(youcompleteme很大,装的很慢,耐心等待)

4.把剩余的插件补全(光是vundle装是不够的,有些主题,插件还需要配置),一个一个来.

装完后执行下vim果然发现报错,先把主题颜色搞定把,推荐onedark(atom党的最爱),

主题安装教程链接

主题装完启动vim,发现又报错,反正就是类似的错误,看起来像是youcompleteme没装完,先配置这个把

YouCompleteMe安装

代码语言:javascript复制
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer --ts-completer (需要装npm)
python3 install.py --clang-completer (仅需要c家族支持,建议指定python3)
题外话:
--clang-completer 是c语言家族的解析器,c语言家族包括php,javascript,等等语言, ts支持es6
如果是用"python3"的补全,请使用python3 install.py安装!!
(1)如果报错,说明你没gcc的编译器,这玩意要编译c  代码
ERROR: Unable to find executable 'cmake'. CMake is required to build ycmd
执行
brew install cmake
(ubuntu: apt install cmake,centos: yum install cmake)
(2)报错:python3: error while loading shared libraries: libpython3.7m.so.1.0
echo  '/usr/local/share/python3/lib'  /etc/ld.so.conf.d/py37.conf     (whereis python3 找lib包路径)
ldconfig
(注意这里的python路径要是你的lib包的准确路径)
(3)报错 ... --enable-shared  ....
你应该重新编译python
./configure prefix=/usr/local/share/python3 --with-ssl --enable-shared

结果报错了 CMake Error at ycm/CMakeLists.txt:108

代码语言:javascript复制
A方案
执行这条命令
./install.py --clang-completer --system-libclang
B方案(推荐)
开vpn执行这个./install命令 ,因为下载被墙了
C方案
如果还是报错 google一下 

看到这个就说明YoucompleteMe装好了哦

神马?还是报错,google了一下 执行

代码语言:javascript复制
mkdir -p $HOME/.vim/swapfiles/
mkdir -p ~/.cache/ctrlp

到这里所有的报错都已经解决了,接下来解决下js跳函数文件的问题。

代码语言:javascript复制
 brew install ctags  
(可选)装好后软连接到/usr/local/bin/ctags覆盖mac的ctags,因为mac的ctags是低配版的,用不了
(或者你在开一个终端让环境变量生效,which ctags可以看到目前用的是系统的还是新装的)

[jsCtags]补充安装参考(支持js跳文件哦,就是在vim里面往函数里面跳)(https://blog.csdn.net/ghostyusheng/article/details/82747386)

补充下在powerline有一些?的符号是字体没装,powerline字体安装下.
代码语言:javascript复制
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh

然后在iterm2的设置里面改变字体(神马?不是mac环境,你自己研究下)

注意事项

eslint: 如果你用npm全局装的eslint,在按F3自动格式化的时候可能会没用,请卸载全局的eslint(npm uninstall eslint -g),然后用软链接把项目依赖的eslint -> /usr/local/bin/eslint (ln -s …/node_modules/eslint/bin/eslint.js /usr/local/bin/eslint),这样F3才能启用eslint自动格式化。 如果你想动态监测eslint报错,请在vimrc中把监测模式中的passive消极模式配置注释掉(有点耗性能)。

ack: 请执行如下命令保证你的命令行ack命令能够被vim ACK组件使用。 wget -O- https://beyondgrep.com/ack-2.24-single-file > /usr/local/bin/ack && chmod 755 /usr/local/bin/ack

到此全部配置完毕,有问题请给我留言,谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/187395.html原文链接:https://javaforall.cn

0 人点赞