390 lines
16 KiB
VimL
390 lines
16 KiB
VimL
" File : .vimrc
|
|
" Project : Your Project
|
|
" License : MIT
|
|
" Author : Feng Bohan <1953356163@qq.com>
|
|
" Date : 2025-04-18 08:39:57
|
|
" Last Modified Date: 2025-04-22 10:19:39
|
|
" Last Modified By : Feng Bohan <1953356163@qq.com>
|
|
" Copyright © 2025 Shanghai Fudan Microelectronics Group Co.,Ltd. All Rights Reserved.
|
|
|
|
" 环境检测
|
|
function! IsAtCompany()
|
|
" 检查 baidu.com 是否能解析
|
|
let l:cmd = 'curl -s -o /dev/null -m 2 -w "%{http_code}" https://baidu.com'
|
|
let l:http_code = system(l:cmd)
|
|
|
|
if match(l:http_code, '^[23][0-9][0-9]$') == -1
|
|
return 1 " 不能解析,在公司
|
|
else
|
|
return 0 " 能解析,不在公司
|
|
endif
|
|
endfunction
|
|
" 只在 Vim 启动时检测一次
|
|
if !exists('g:is_at_company')
|
|
let g:is_at_company = IsAtCompany()
|
|
endif
|
|
|
|
" 使用时直接判断
|
|
if g:is_at_company
|
|
" 公司配置
|
|
echo "🏢 公司模式已开启"
|
|
else
|
|
" 个人配置
|
|
echo "🏠 个人模式已开启"
|
|
endif
|
|
command! RefreshNetworkStatus let g:is_at_company = IsAtCompany() |
|
|
\ echo (g:is_at_company ? '🏢 切换到公司配置' : '🏠 切换到个人配置')
|
|
|
|
" 基础配置
|
|
let mapleader = ','
|
|
let maplocalleader = ',,'
|
|
set number " 显示行号
|
|
set relativenumber " 显示相对行号
|
|
set incsearch " 实时开启搜索高亮
|
|
set hlsearch " 搜索结果高亮
|
|
set autoindent " 自动缩进
|
|
set nosmartindent " 关闭智能缩进
|
|
set tabstop=4 " 设置tab制表符号所占宽度为4
|
|
set softtabstop=4 " 设置按tab时缩进宽度为4
|
|
set shiftwidth=4 " 设置自动缩进宽度为4
|
|
set expandtab " 缩进时将tab制表服转为空格
|
|
set smartcase " 开启智能大小写查找
|
|
set encoding=utf-8 " Use UTF-8.
|
|
set showcmd " Display incomplete commands.
|
|
set clipboard=unnamedplus " 开启系统剪切板
|
|
set cursorline " 高亮当前行
|
|
set ignorecase " 设置忽略大小写
|
|
set smartcase " 设置智能大小写
|
|
set ruler " 设置显示当前位置
|
|
" set autoread
|
|
filetype on " 开启文件类型检测
|
|
filetype plugin indent on " 开启文件类型插件检测
|
|
syntax on " 开启语法高亮
|
|
|
|
"外观设置
|
|
set guifont=JetBrainsMono\ Nerd\ Font\ Bold\ 16
|
|
"set guifont=FiraCode\ Nerd\ Font\ Mono\ Bold\ 16
|
|
set backspace=2 " 允许退格删除缩进、换行符和插入模式前的字符 "
|
|
set laststatus=2 " 启动显示状态行
|
|
set t_Co=256 " 开启256色支持
|
|
highlight Function cterm=bold,underline ctermbg=red ctermfg=green "color set
|
|
|
|
"屏蔽相关功能设置
|
|
set nocompatible " 不兼容vi
|
|
set noerrorbells " 不让vim发出讨厌的滴滴声
|
|
set shortmess=ati " 启动的时候不显示那个援助索马里儿童的提示
|
|
set novisualbell " 不要闪烁
|
|
" 关闭各种按键叮叮声音和闪屏
|
|
set vb t_vb=
|
|
au GuiEnter * set t_vb=
|
|
|
|
"禁止相关文件的产生
|
|
set noundofile " 禁止un~文件
|
|
set nobackup " 禁止~文件
|
|
set noswapfile " 禁止swp文件
|
|
" 按键映射
|
|
inoremap jk <ESC>g,
|
|
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
|
|
nnoremap <leader>sv :source $MYVIMRC<cr>
|
|
"设置bffer的切换 使用 Ctrl J、K、H切换或者删除{{{
|
|
"切换buffer以及删除buffer
|
|
nnoremap <C-j> :bn<CR>
|
|
nnoremap <C-k> :bp<CR>
|
|
nnoremap <C-h> :bwipe<CR>
|
|
map <C-L> <Esc>:set guifont=Monospace\ 16<Enter>
|
|
map <C-M> <Esc>:set guifont=Monospace\ 14<Enter>
|
|
nnoremap <Leader>t :below terminal<CR>
|
|
nnoremap <C-s> :w<CR>
|
|
nnoremap <Leader>tt :TagbarToggle<CR>
|
|
|
|
" 特殊配置
|
|
let g:polyglot_disabled = ['verilog_systemverilog']
|
|
|
|
" 插件管理
|
|
call plug#begin()
|
|
Plug 'vhda/verilog_systemverilog.vim'
|
|
Plug 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' }
|
|
if has('nvim')
|
|
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
|
|
else
|
|
Plug 'Shougo/deoplete.nvim'
|
|
Plug 'roxma/nvim-yarp'
|
|
Plug 'roxma/vim-hug-neovim-rpc'
|
|
endif
|
|
Plug 'preservim/nerdtree'
|
|
Plug 'xuyuanp/nerdtree-git-plugin'
|
|
Plug 'ryanoasis/vim-devicons'
|
|
Plug 'Yggdroot/indentLine'
|
|
Plug 'luochen1990/rainbow'
|
|
Plug 'dense-analysis/ale'
|
|
Plug 'godlygeek/tabular'
|
|
Plug 'itchyny/vim-cursorword'
|
|
Plug 'vim-airline/vim-airline'
|
|
Plug 'vim-airline/vim-airline-themes'
|
|
Plug 'mhinz/vim-startify'
|
|
Plug 'HonkW93/automatic-verilog'
|
|
Plug 'preservim/nerdcommenter'
|
|
Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
|
|
Plug 'tomasr/molokai'
|
|
Plug 'w0ng/vim-hybrid'
|
|
Plug 'joshdick/onedark.vim'
|
|
Plug 'jiangmiao/auto-pairs'
|
|
Plug 'tpope/vim-endwise'
|
|
Plug 'kshenoy/vim-signature'
|
|
Plug 'SirVer/ultisnips'
|
|
Plug 'keelii/vim-snippets'
|
|
Plug 'junegunn/vim-easy-align'
|
|
Plug 'tpope/vim-surround'
|
|
Plug 'sheerun/vim-polyglot'
|
|
Plug 'tpope/vim-repeat'
|
|
Plug 'alpertuna/vim-header'
|
|
Plug 'airblade/vim-gitgutter'
|
|
Plug 'tpope/vim-fugitive'
|
|
Plug 'preservim/tagbar'
|
|
call plug#end()
|
|
|
|
"=============================================================================
|
|
" configure for verilog_systemverilog
|
|
"=============================================================================
|
|
"Syntax folding
|
|
"To enable syntax folding set the following option:
|
|
"set foldmethod=syntax
|
|
|
|
"This plugin includes the errorformat configurations for the following Verilog tools:
|
|
" Synopsys VCS (vcs)
|
|
" Mentor Modelsim (msim)
|
|
" Icarus Verilog (iverilog)
|
|
" GPL Cver (cver)
|
|
" Synopsys Leda (leda)
|
|
" Verilator (verilator)
|
|
" Cadence NCVerilog (ncverilog)
|
|
"the second argument disables the detection of lint messages.
|
|
" 1:All messages are detected.
|
|
" 2:Ignore lint messages.
|
|
" 3:Ignore lint and warning messages.
|
|
autocmd FileType verilog_systemverilog silent :VerilogErrorFormat vcs 2
|
|
autocmd FileType verilog_systemverilog let &makeprg='vlogan +v2k -full64 +vcs+flush+all +lint=all -sverilog +libext+.v+.sv -q %'
|
|
autocmd BufWritePost * if &filetype == "verilog_systemverilog" | exec ":make" | endif
|
|
|
|
"Following an Instance
|
|
"A framework is provided to follow a module instance to its module declaration as long as its respective entry exists in the tags file. To do so simply execute within the instance to follow it to its declaration.:VerilogFollowInstance
|
|
"Alternatively, if the cursor is placed over a port of the instance the command can be used to navigate to the module declaration and immediately searching for that port.:VerilogFollowPort
|
|
nnoremap <leader>i :VerilogFollowInstance<CR>
|
|
nnoremap <leader>I :VerilogFollowPort<CR>
|
|
|
|
"Jump to start of current instance
|
|
"The command is provided to move the cursor to the start of the first module instantiation that precedes the current cursor location.:VerilogGotoInstanceStart
|
|
nnoremap <leader>u :VerilogGotoInstanceStart<CR>
|
|
|
|
"=============================================================================
|
|
" configure for deoplete
|
|
"=============================================================================
|
|
let g:deoplete#enable_at_startup = 1
|
|
" 选择方法:
|
|
"<Up> / <Down> 或 <C-p> / <C-n>:上下移动选择候选项目
|
|
"<C-y>:确认选中当前高亮的候选项
|
|
"<C-e>:关闭补全菜单而不选择
|
|
|
|
"=============================================================================
|
|
" configure for nerdtree
|
|
"=============================================================================
|
|
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
|
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
|
|
" Close the tab if NERDTree is the only window remaining in it.
|
|
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
|
|
|
|
nnoremap <leader>n :NERDTreeFocus<CR>
|
|
nnoremap <C-n> :NERDTree<CR>
|
|
nnoremap <C-t> :NERDTreeToggle<CR>
|
|
nnoremap <C-f> :NERDTreeFind<CR>
|
|
|
|
let g:NERDTreeFileLines = 1 " 显示行号
|
|
let NERDTreeShowHidden=1 " 设置显示隐藏文件
|
|
" 设置忽略的文件
|
|
let NERDTreeIgnore=[
|
|
\ '\.git$','\.svn$','\.DS_Store$'
|
|
\ ]
|
|
|
|
"=============================================================================
|
|
" configure for indentLine
|
|
"=============================================================================
|
|
let g:vim_json_conceal=0
|
|
let g:markdown_syntax_conceal=0
|
|
|
|
"=============================================================================
|
|
" configure for rainbow
|
|
"=============================================================================
|
|
"0 if you want to enable it later via :RainbowToggle"
|
|
let g:rainbow_active = 1
|
|
let g:rainbow_conf = {
|
|
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
|
|
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
|
|
\ 'guis': [''],
|
|
\ 'cterms': [''],
|
|
\ 'operators': '_,_',
|
|
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
|
|
\ 'separately': {
|
|
\ '*': {},
|
|
\ 'markdown': {
|
|
\ 'parentheses_options': 'containedin=markdownCode contained',
|
|
\ },
|
|
\ 'lisp': {
|
|
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
|
|
\ },
|
|
\ 'haskell': {
|
|
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\v\{\ze[^-]/ end=/}/ fold'],
|
|
\ },
|
|
\ 'vim': {
|
|
\ 'parentheses_options': 'containedin=vimFuncBody',
|
|
\ },
|
|
\ 'perl': {
|
|
\ 'syn_name_prefix': 'perlBlockFoldRainbow',
|
|
\ },
|
|
\ 'stylus': {
|
|
\ 'parentheses': ['start=/{/ end=/}/ fold contains=@colorableGroup'],
|
|
\ },
|
|
\ 'css': 0,
|
|
\ 'nerdtree': 0,
|
|
\ }
|
|
\}
|
|
|
|
"=============================================================================
|
|
" configure for ale
|
|
"=============================================================================
|
|
let g:ale_cache_executable_check_failures=1
|
|
" ==================== ALE 异步语法检查配置 ====================
|
|
" 1. 基础设置
|
|
let g:ale_enabled = 1 " 启用ALE
|
|
let g:ale_lint_on_enter = 1 " 打开文件时立即检查
|
|
let g:ale_lint_on_save = 1 " 保存时检查
|
|
let g:ale_lint_on_text_changed = 'normal' " 普通模式下文本改变时检查
|
|
let g:ale_open_quickfix = 0 " 不自动打开quickfix窗口
|
|
|
|
" 2. 错误提示样式
|
|
let g:ale_sign_error = '>>' " 错误标志
|
|
let g:ale_sign_warning = '--' " 警告标志
|
|
highlight link ALEErrorSign Error " 错误标志颜色
|
|
highlight link ALEWarningSign WarningMsg " 警告标志颜色
|
|
|
|
" 3. 状态栏集成 (Airline/lightline)
|
|
let g:airline#extensions#ale#enabled = 1 " 启用Airline集成
|
|
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok'] " 自定义状态栏显示
|
|
|
|
" 4. 针对Verilog/SystemVerilog的特定配置
|
|
let b:ale_linters = ['xvlog', 'iverilog', 'verilator'] " 推荐添加verilator
|
|
let b:ale_verilog_iverilog_options = '-g2012' " 设置IEEE 1800-2012标准
|
|
|
|
" 5. 快速修复配置
|
|
let g:ale_set_quickfix = 1 " 使用quickfix列表
|
|
let g:ale_set_loclist = 0 " 禁用loclist
|
|
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]' " 消息格式
|
|
|
|
" 6. 自定义状态栏函数 (更简洁的实现)
|
|
function! LinterStatus() abort
|
|
let l:counts = ale#statusline#Count(bufnr(''))
|
|
return l:counts.total == 0 ? '✓' : printf('%d⚠ %d⨉', l:counts.warning + l:counts.style_warning, l:counts.error)
|
|
endfunction
|
|
set statusline+=%{LinterStatus()} " 添加到状态栏
|
|
|
|
" 快速跳转错误
|
|
nmap <silent> <Leader>e <Plug>(ale_next_wrap)
|
|
nmap <silent> <Leader>E <Plug>(ale_previous_wrap)
|
|
" 查看错误详情
|
|
nnoremap <Leader>d :ALEDetail<CR>
|
|
|
|
" 为了优化性能
|
|
let g:ale_pattern_options = {
|
|
\ '\.v$': {'ale_enabled': 1},
|
|
\ '\.sv$': {'ale_enabled': 1},
|
|
\ '.*': {'ale_enabled': 0}
|
|
\ }
|
|
|
|
"=============================================================================
|
|
" configure for tabular
|
|
"=============================================================================
|
|
vnoremap <C-w> :Tab /
|
|
|
|
"=============================================================================
|
|
" configure for airline
|
|
"=============================================================================
|
|
let g:airline#extensions#tabline#enabled = 1 " 设置开启tab样式
|
|
let g:airline#extensions#tabline#formatter = 'jsformatter' " 设置默认tab栏样式
|
|
let g:airline#extensions#tabline#buffer_idx_mode = 1 " 显示buffer number "
|
|
let g:airline#extensions#whitespace#enabled = 0 " 清楚traling的警告 "
|
|
|
|
let g:airline_left_sep = '►'
|
|
let g:airline_left_alt_sep = '>'
|
|
let g:airline_right_sep = '◄'
|
|
let g:airline_right_alt_sep = '<'
|
|
|
|
" airline-theme
|
|
let g:airline_theme='solarized'
|
|
|
|
"=============================================================================
|
|
" configure for NERDCommenterToggle
|
|
"=============================================================================
|
|
nmap <BS> <plug>NERDCommenterToggle
|
|
vmap <BS> <plug>NERDCommenterToggle
|
|
|
|
"=============================================================================
|
|
" configure for theme
|
|
"=============================================================================
|
|
"colorscheme hybrid
|
|
"colorscheme molokai
|
|
colorscheme onedark
|
|
set background=dark
|
|
|
|
"=============================================================================
|
|
" configure for ultisnips
|
|
"=============================================================================
|
|
" Trigger configuration. You need to change this to something other than <tab> if you use one of the following:
|
|
let g:UltiSnipsExpandTrigger="<tab>"
|
|
let g:UltiSnipsJumpForwardTrigger="<c-b>"
|
|
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
|
|
|
|
" If you want :UltiSnipsEdit to split your window.
|
|
let g:UltiSnipsEditSplit="vertical"
|
|
|
|
"=============================================================================
|
|
" configure for EasyAlign
|
|
"=============================================================================
|
|
" Start interactive EasyAlign in visual mode (e.g. vipga)
|
|
xmap ga <Plug>(EasyAlign)
|
|
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
|
|
nmap ga <Plug>(EasyAlign)
|
|
cnoremap <C-a> EasyAlign
|
|
|
|
"=============================================================================
|
|
" configure for repeat
|
|
"=============================================================================
|
|
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
|
|
|
|
"=============================================================================
|
|
" configure for vim-header
|
|
"=============================================================================
|
|
" 启用自动插入(新建文件时)
|
|
let g:header_auto_add_header = 1
|
|
let g:header_auto_update_header = 1
|
|
"let g:header_field_project = 'Your Project'
|
|
let g:header_field_filename_path = 0
|
|
let g:header_field_last_separator = 1
|
|
" 文件类型黑名单(不自动插入的文件类型)
|
|
let g:header_field_autocmd_blacklist = ['markdown', 'json']
|
|
|
|
let g:header_field_author = 'Feng Bohan'
|
|
let g:header_field_timestamp_format = '%Y-%m-%d %H:%M:%S'
|
|
if g:is_at_company
|
|
let g:header_field_author_email = 'fengbohan@fmsh.com.cn'
|
|
let g:header_field_company = 'Shanghai Fudan Microelectronics Group Co.,Ltd' " 新增公司字段
|
|
let g:header_field_copyright = 'Copyright © '.strftime('%Y').' '.g:header_field_company.'. All Rights Reserved.'
|
|
else
|
|
let g:header_field_author_email = '1953356163@qq.com'
|
|
let g:header_field_license_id = 'MIT'
|
|
let g:header_field_copyright = 'Copyright © '.strftime('%Y').' '.g:header_field_author.'. All Rights Reserved.'
|
|
endif
|
|
map <F4> :AddHeader<CR>
|
|
|
|
"=============================================================================
|
|
" other configure
|
|
"=============================================================================
|