1. 先安裝Vim-plug,這是一個vim插件的管理器,可以快速安裝,升級插件
照着官方文檔安裝即可,mac一行命令搞定
https://github.com/junegunn/vim-plug
2. 配置~/.vimrc文件
我的配置文件:可以復制直接用,也可以網上找,需要了解配置文件的規則
"*****************************用戶自定義設置*******************************" " <C-P> --單詞補全 " u [小寫] --單步復原 [非插入模式] " U [大寫] --整行復原 [非插入模式] " :set syntax=cpp --手動選擇語法高亮 [或 :set filetype=cpp] " :%!xxd --轉儲二進制文件,以十六進制形式顯示 " :%!xxd -r --還原二進制文件 "********************************設置快捷鍵*******************************" " Ctrl+D 刪除當前行 map <c-d> dda imap <c-d> <ESC>dda " Ctrl+N 顯示緩沖區的下個文件並留在插入模式[插入模式] map <c-n> :confirm bnext<CR>A imap <c-n> <ESC>:confirm bnext<CR>A "********************************設置編碼*******************************" "設置換行編碼 :set fileformats=unix,dos,mac "設置Vim 內部使用的字符編碼方式,包括 Vim 的 buffer (緩沖區)、菜單文本、消息文本等 set encoding=utf-8 "設置文件編碼 if has("win32") set fileencoding=chinese else set fileencoding=utf-8 endif "Vim 啟動時會按照它所列出的字符編碼方式逐一探測即將打開的文件的字符編碼方式 "並把fileencoding設置為探測出的編碼方式 set fileencodings=ucs-bom,utf-8,chines " 解決菜單亂碼 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim " 解決consle輸出亂碼 language messages zh_CN.utf-8 "********************************基本設置******************************" colorscheme desert " 着色模式:灰色背景 set guifont=Monaco:h14 set tabstop=4 " 設置tab鍵的寬度 set shiftwidth=4 " 換行時行間交錯使用4個空格 set autoindent " 自動對齊 set backspace=2 " 設置退格鍵可用 set cindent shiftwidth=4 " 自動縮進4空格 set smartindent " 智能自動縮進 set ai! " 設置自動縮進 set nu! " 顯示行號 set showmatch " 顯示括號配對情況 set mouse=a " 啟用鼠標 set ruler " 右下角顯示光標位置的狀態行 set incsearch " 查找book時,當輸入/b時會自動找到 set hlsearch " 開啟高亮顯示結果 set incsearch " 開啟實時搜索功能 set nowrapscan " 搜索到文件兩端時不重新搜索 set nocompatible " 關閉兼容模式 set cursorline " 突出顯示當前行 set hidden " 允許在有未保存的修改時切換緩沖區 set list " 顯示Tab符,使用一高亮豎線代替 set listchars=tab:\|\ " 顯示Tab符,使用一高亮豎線代替 set noswapfile " 設置無交換區文件" set writebackup " 設置無備份文件 set nobackup " 設置無備份文件 set autochdir " 設定文件瀏覽器目錄為當前目錄 set foldmethod=syntax " 選擇代碼折疊類型 set foldlevel=100 " 禁止自動折疊 set laststatus=2 " 開啟狀態欄信息 set cmdheight=2 " 命令行的高度,默認為1,這里設為2 set showtabline=2 " 設置默認顯示標簽 set clipboard+=unnamed " 與系統公用剪貼板 set autoread " 當文件在外部被修改,自動更新該文件 set scrolloff=5 " 設定光標離窗口上下邊界 5 行時窗口自動滾動 set guioptions-=T " 去掉上方工具欄 set autochdir " 自動切換到當前目錄" set autoread " 自動檢測並加載外部對文件的修改" set autowrite " 自動檢測並加載外部對文件的修改" set showcmd " 命令欄顯示命令 " set ignorecase smartcase " 搜索時智能忽略大小寫 syntax enable " 打開語法高亮 syntax on " 開啟文件類型偵測 if has("gui_running") "winpos 20 20 " 指定窗口出現的位置,坐標原點在屏幕左上角 "set lines=20 columns=90 " 指定窗口大小,lines為高度,columns為寬度 "set guioptions-=m " 隱藏菜單欄 "set guioptions-=T " 隱藏工具欄 "set guioptions-=L " 隱藏左側滾動條 "set guioptions-=r " 隱藏右側滾動條 set guioptions+=b " 顯示底部滾動條 set nowrap " 設置不自動換行 endif "*****************************設置狀態欄*************************************" let &statusline=' %t %{&mod?(&ro?"*":"+"):(&ro?"=":" ")} %1*|%* %{&ft==""?"any":&ft} %1*|%* %{&ff} %1*|%* %{(&fenc=="")?&enc:&fenc}%{(&bomb?",BOM":"")} %1*|%* %=%1*|%* 0x%B %1*|%* (%l,%c%V) %1*|%* %L %1*|%* %P' "******************************* 引號 && 括號自動匹配*******************************" :inoremap ( ()<ESC>i :inoremap ) <c-r>=ClosePair(')')<CR> :inoremap { {}<ESC>i :inoremap } <c-r>=ClosePair('}')<CR> :inoremap [ []<ESC>i :inoremap ] <c-r>=ClosePair(']')<CR> :inoremap < <><ESC>i :inoremap > <c-r>=ClosePair('>')<CR> :inoremap " ""<ESC>i :inoremap ' ''<ESC>i :inoremap ` ``<ESC>i function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf call plug#begin() " The default plugin directory will be as follows: " - Vim (Linux/macOS): '~/.vim/plugged' " - Vim (Windows): '~/vimfiles/plugged' " - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged' " You can specify a custom plugin directory by passing it as the argument " - e.g. `call plug#begin('~/.vim/plugged')` " - Avoid using standard Vim directory names like 'plugin' " Make sure you use single quotes " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align Plug 'junegunn/vim-easy-align' " Any valid git URL is allowed Plug 'https://github.com/junegunn/vim-github-dashboard.git' " Multiple Plug commands can be written in a single line using | separators Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' " On-demand loading Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } Plug 'tpope/vim-fireplace', { 'for': 'clojure' } " Using a non-default branch Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } " Using a tagged release; wildcard allowed (requires git 1.9.2 or above) Plug 'fatih/vim-go', { 'tag': '*' } " Plugin options Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' } " Plugin outside ~/.vim/plugged with post-update hook Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } "********************************前端插件:react,html等*******************************" Plug 'pangloss/vim-javascript' Plug 'leafgarland/typescript-vim' Plug 'peitalin/vim-jsx-typescript' Plug 'styled-components/vim-styled-components', { 'branch': 'main' } Plug 'jparise/vim-graphql' " Initialize plugin system call plug#end()
查看插件狀態
:PlugStatus
安裝未安裝的插件:
:PlugInstall
進入項目文件:my-app
輸入vim,然后輸入:NERDTree。就可以快速查看代碼,不用用idea打開了,配合iterm2非常方便省內存
3. 參考文檔
vim 插件管理:
https://github.com/junegunn/vim-plug
vim插件nerdtree。其他插件直接GitHub搜名字就可以了。nerdtree還可以配置啟動vim就可以直接打開側邊欄,配置命令見文檔。
https://github.com/preservim/nerdtree