Skip to content

Instantly share code, notes, and snippets.

@keepzero
Last active June 30, 2017 11:41
Show Gist options
  • Save keepzero/8f14cb7090f5640b41be68bf45a14be0 to your computer and use it in GitHub Desktop.
Save keepzero/8f14cb7090f5640b41be68bf45a14be0 to your computer and use it in GitHub Desktop.
vimrc minimal
set nocompatible
" set encodings
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
" few options just make things better
set scrolloff=3
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set noerrorbells
set cursorline
set ttyfast
set ruler
set laststatus=2
" split window shortcut
nnoremap <C-w>- <C-w>s<C-w>j
nnoremap <C-w>\| <C-w>v<C-w>l
noremap <C-J> <C-W>j
noremap <C-K> <C-W>k
noremap <C-H> <C-W>h
noremap <C-L> <C-W>l
" Emacs bind
inoremap <C-a> <Home>
inoremap <C-e> <End>
inoremap <C-b> <Left>
inoremap <C-f> <Right>
"inoremap <C-w> <Esc>dbcl
inoremap <C-d> <C-o>s
"inoremap <C-u> <Esc>d0cl
inoremap <C-k> <C-o>C
" tabs
set autoindent
set backspace=indent,eol,start
set complete-=i
set smarttab
" filetype detect
if has('autocmd')
filetype plugin indent on
autocmd FileType python set ts=4 sw=4 et sts=4
autocmd BufRead,BufNewFile *.json set ft=javascript
autocmd BufRead,BufNewFile */etc/nginx/* set ft=nginx
autocmd BufRead,BufNewFile */etc/init.d/* set ft=sh
autocmd BufRead,BufNewFile *.sls set ft=yaml
endif
" syntax on
if has('syntax') && !exists('g:syntax_on')
syntax enable
endif
" searching and moving
set magic
nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set incsearch
set showmatch
set hlsearch
" handle long lines
set wrap
set formatoptions=qrn1
" autoread when file changed out vim
set autoread
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" force to use hjkl
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
@keepzero
Copy link
Author

keepzero commented May 24, 2017

dotVimrc

参考 vim-sensible 插件和 Coming Home to Vim

  1. 支持古董级 vim 7.2
  2. 不修改 vim 默认的键绑定
  3. 无需安装插件让 vim 更好用

更人性化的分隔窗口快捷键

  • Ctrl-w + - 分成上下
  • Ctrl-w + | 分成左右
  • normal 模式下 Ctrl-h/j/k/l 跳转到窗口

更好用的搜索

  • incsearch: 增量搜索
  • smartcase: 默认忽略大小写搜索,如果我们在搜索字符中有一个大写字符,则进行精确查找

插入模式下 Emacs 键绑定

支持在插入模式 (insert mode) 下使用部分 Emacs/bash 键绑定

  • ctrl-a 跳到行首
  • ctrl-e 跳到行尾
  • ctrl-b Left
  • ctrl-f Right
  • ctrl-u 删除到行首
  • ctrl-k 删除到行尾
  • and so on

载入内置的 matchit 插件

在编程语言的括号或者 html 标签上按 % 即可跳转到成对的括号或标签

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment