vim 使用小结

安装插件管理工具,参考这里

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

配置文件$HOME/.vimrc

" =================
" ===   start   ===
" =================

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=ucs-bom,utf-8,latin1
endif

if &term=="xterm"
  set t_Co=8
  set t_Sb=m
  set t_Sf=m
endif


" ==================
" ===   Plugin   ===
" ==================
call plug#begin('~/.vim/plugged')
  " surround the words
  Plug 'tpope/vim-surround' "refer https://github.com/tpope/vim-surround
  Plug 'justinmk/vim-sneak' "refer https://github.com/justinmk/vim-sneak
  " status bar
  Plug 'vim-airline/vim-airline'
  Plug 'vim-airline/vim-airline-themes'
  Plug 'lfv89/vim-interestingwords'
  Plug 'farmergreg/vim-lastplace'
  Plug 'kien/rainbow_parentheses.vim'
  Plug 'connorholyday/vim-snazzy'
  Plug 'elzr/vim-json'
  Plug 'jiangmiao/auto-pairs'
  Plug 'nathanaelkane/vim-indent-guides'
  Plug 'w0ng/vim-hybrid'

  "" python sytanx highlight and completion, to slow
  "Plug 'davidhalter/jedi-vim'
  "let g:jedi#completions_command = '<C-n>'
  "" golang
  "Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
call plug#end()


" =================
" ===   basic   ===
" =================
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
set backspace=indent,eol,start
set laststatus=2
set autochdir
au BufReadPost * if line("'"") > 1 && line("'"") <= line("$") | exe "normal! g'"" | endif
let &t_ut=''
set list
set listchars=tab:▸ ,trail:▫
set mouse=r
syntax on
set nocompatible               " Use Vim defaults (much better!)
set bs=indent,eol,start        " allow backspacing over everything in insert mode
set history=50                 " keep 50 lines of command line history
set ruler                      " show the cursor position all the time
set hlsearch
set fencs=utf8,gbk,gb2312,gb18030
set termencoding=utf-8
set encoding=utf-8
set enc=utf8
set incsearch      " 边输入边搜索
set autoindent     " 换行自动缩进
set shiftwidth=4   " 自动缩进时的宽度
set tabstop=4      " tabstop的宽度
set expandtab      " tab换成空格
set softtabstop=4  " 退格键
set ignorecase     " 搜索忽略大小写
set smartcase      " 智能大小写搜索
"set paste          " 粘贴时不自动换行
set number
set relativenumber
"set norelativenumber
set cursorline
set wrap
set showcmd
set wildmenu

"" theme
let g:hybrid_custom_term_colors = 1
let g:hybrid_reduced_contrast = 1 " Remove this line if using the default palette.
colorscheme hybrid
colorscheme snazzy

" highlight space at end of line
highlight ExtraWhitespace ctermbg=red guibg=darkgreen
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /s+$| +ze	/
highlight BadWhitespace guifg=gray guibg=red ctermfg=gray ctermbg=red
autocmd BufRead,BufNewFile *.py,*.pyw,*.c,*.h,*.go match BadWhitespace /s+$/

" ========================
" ===   Key binginds   ===
" ========================
"" key map
let mapleader=" "
let g:mapleader=" "

"" delete current line
imap <C-d> <Esc>ddi
nmap <C-d> dd
" reload vim config
"cnoreabbrev source source $MYVIMRC
map R :source $MYVIMRC<CR>
"" pess jj into normal
inoremap jj <Esc>`^

" split
map sl :set splitright<CR>:vsplit<CR>
map sh :set nosplitright<CR>:vsplit<CR>
map sk :set nosplitbelow<CR>:split<CR>
map sj :set splitbelow<CR>:split<CR>
" move
" map <LEADER>h <C-w>h
" map <LEADER>j <C-w>j
" map <LEADER>k <C-w>k
" map <LEADER>l <C-w>l
" resize
map <LEADER><up> :res +5<CR>
map <LEADER><down> :res -5<CR>
map <LEADER><left> :vertical resize-5<CR>
map <LEADER><right> :vertical resize+5<CR>

" tabe
map tu :tabe<CR>
map tn :-tabnext<CR>
map tp :+tabnext<CR>

安装插件

在vim命令模式下,执行

:PlugInstall

功能

  • jj 进入命令模式

  • R 重载vim配置文件

  • 高亮单词

    • 高亮 <Leader>k
    • 高亮单词跳转 n and N
    • 清除高亮 <Leader>K
  • 小写v 大写V C-v可视化模式

其他

:r !cat test.txt 在当前位置读取文件内容
:w test.txt 将选中的内容保存到新文件,可以用行选择或者块选择
原文地址:https://www.cnblogs.com/hiyang/p/13636349.html