Vim 是一个上古神器,刚刚接触的同学可能很难驾驭,本篇文章主要带领大家快速入门,并持续分享当前流行的一些 vim-plugin,有兴趣的同学还可以参考 to-vim-tmux-zsh 仓库继续研究 Tmux 和 Zsh。
$ vimtutor // vim 教程
创建 Vim 的配置文件 .vimrc
touch ~/.vimrc
set enc=utf-8
set noswapfile
set nobackup
set noswapfile
if has('persistent_undo')
set undofile
set undodir=~/.vim/undodir
if !isdirectory(&undodir)
call mkdir(&undodir, 'p', 0700)
endif
endif
set fileencodings=ucs-bom,utf-8,gb18030,latin1
if has('mouse')
if has('gui_running') || (&term =~ 'xterm' && !has('mac'))
set mouse=a
else
set mouse=nvi
endif
endif
set clipboard=unnamed
if has('gui_running')
let do_syntax_sel_menu = 1
let do_no_lazyload_menus = 1
endif
if !has('gui_running')
if has('wildmenu')
set wildmenu
set cpoptions-=<
set wildcharm=<C-Z>
nnoremap <F10> :emenu <C-Z>
inoremap <F10> <C-O>:emenu <C-Z>
endif
endif
set ignorecase
set smartcase
set hlsearch
set incsearch
nnoremap <silent> <F2> :nohlsearch<CR>
inoremap <silent> <F2> <C-O>:nohlsearch<CR>
set number
set shiftwidth=2
set tabstop=2
set cursorline
set nofoldenable
syntax enable
colorscheme one
set background=dark
hi Normal ctermfg=252 ctermbg=none
使用 vim-plug 管理插件
Plug 'scrooloose/nerdtree' " https://github.com/preservim/nerdtree
Plug 'Xuyuanp/nerdtree-git-plugin' " https://github.com/Xuyuanp/nerdtree-git-plugin
Plug 'ryanoasis/vim-devicons' " https://github.com/ryanoasis/vim-devicons
Plug 'tiagofumo/vim-nerdtree-syntax-highlight' " https://github.com/tiagofumo/vim-nerdtree-syntax-highlight
nnoremap dt :tabclose<CR>
nnoremap <C-n> :NERDTreeToggle<CR>
let NERDTreeMinimalUI = 1
let NERDTreeShowHidden = 1
" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
\ quit | endif
" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * silent NERDTreeMirror
" i Open selected file in a split window
" s Open selected file in a new vsplit
" t Open selected node/bookmark in a new tab
" J Jump down inside directories at the current tree depth
" K Jump up inside directories at the current tree depth
" r Recursively refresh the current directory
" R Recursively refresh the current roo
" m Display the NERDTree menu
" C Change the tree root to the selected directory
" u Move the tree root up one directory
" A Zoom (maximize/minimize) the NERDTree window
" I Toggle whether hidden files displayed
Plug 'Valloric/YouCompleteMe' " https://github.com/ycm-core/YouCompleteMe
Plug 'Raimondi/delimitMate' " https://github.com/Raimondi/delimitMate
set completeopt=longest,menuone
nnoremap <Leader>jd :YcmCompleter GoToDefinition<CR>
Plug 'sheerun/vim-polyglot' " https://github.com/sheerun/vim-polyglot
Plug 'w0rp/ale' " https://github.com/w0rp/ale
let g:ale_fix_on_save = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '●'
let g:ale_sign_warning = '▶'
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
Plug 'ctrlpvim/ctrlp.vim' " https://github.com/ctrlpvim/ctrlp.vim
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
let g:ctrlp_regexp = 1
" <c-r>: switch to regexp mode.
" <c-t>:open the selected entry in a new tab.
" <c-v>、<c-x>:open the selected entry in a new split.
" <c-z>: mark/unmark multiple files
Plug 'vim-airline/vim-airline' " https://github.com/vim-airline/vim-airline
Plug 'vim-airline/vim-airline-themes' " https://github.com/vim-airline/vim-airline-themes
let g:airline_theme='onedark'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0
let g:airline#extensions#tabline#show_tab_nr = 0
let g:airline_section_c = ''
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#nerdtree_statusline = 0
let g:airline_extensions = ['tabline', 'hunks', 'branch', "ctrlp"]
let g:airline_highlighting_cache = 1
Plug 'scrooloose/nerdcommenter' " https://github.com/preservim/nerdcommenter
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
" <leader>c<space>: toggles the comment state of the selected line(s).
" <leader>ca: Switches to the alternative set of delimiters.
" <leader>cs: Comments out the selected lines ``sexily''
" <leader>cm: Comments the given lines using only one set of multipart delimiters.
" <leader>cA: Adds comment delimiters to the end of line and goes into insert mode between them.
Plug 'airblade/vim-gitgutter' " https://github.com/airblade/vim-gitgutter
Plug 'tpope/vim-fugitive' " https://github.com/tpope/vim-fugitive
Plug 'tpope/vim-rhubarb' " https://github.com/tpope/vim-rhubarb
set updatetime=100
let g:gitgutter_max_signs = -1
" jump to next hunk: ]c
" jump to previous hunk: [c
" stage the hunk: <Leader>hs
" undo the hunk: <Leader>hu
" preview the hunk: <Leader>hp
" :G
" :Gdiffsplit
" :GBrowse
"
" s: stage (add) the file or hunk under the cursor.
" u: unstage (reset) the file or hunk under the cursor.
" X: discard the change under the cursor.
" dd: perform a |:Gdiffsplit| on the file under the cursor.
" cc: create a commit.
" ca: amend the last commit and edit the message.
" ce: amend the last commit without editing the message.
" =: toggle an inline diff of the file under the cursor.]"
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' } " https://github.com/iamcco/markdown-preview.nvim
" :MarkdownPreview
Plug 'mattn/emmet-vim' " https://github.com/mattn/emmet-vim
let g:user_emmet_leader_key='<C-Z>'
" <C-Z>,
Plug 'prettier/vim-prettier', { 'do': 'npm install' } " https://github.com/prettier/vim-prettier
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync"
Plug 'wakatime/vim-wakatime' " https://github.com/wakatime/vim-wakatime
Plug 'ntpeters/vim-better-whitespace' " https://github.com/ntpeters/vim-better-whitespace
let g:better_whitespace_enabled=1
" :StripWhitespace
最后,呈上 to-vim-tmux-zsh 仓库可供参考,顾名思义,除了 vim,还有 tmux 和 zsh 的相关内容。