编辑文件~/.vimrc
更多的信息请参考vim :help auto-setting 和:help modeline
# 显示行号
set number
# 使用空格代替tab
set expandtab
# or set et
# 将tab替换成4个空格
set tabstop=4
# or set ts=4
# 设置文件编码
set encode=utf-8
# 语法高亮
systax on
# 激活鼠标
set mouse = a
# 多窗口
vim -o file1 file2
vim -O file1 file2
Ctrl+w+w 窗口切换
# 多窗口同步滚动
set scb
set nocompatible "关闭vi兼容
set encode=utf-8
set number "显示行号
filetype plugin on "文件类型
set history=500 "历史命令
syntax on "语法高亮
set autoindent "自动缩进
set smartindent "智能缩进
set showmatch "括号匹配
set ruler "右下角显示光标状态行
set nohls "关闭匹配的高亮显示
set incsearch "设置快速搜索
set foldenable "开启代码折叠
"set fdm=manual "手动折叠
set foldmethod=syntax "自动语法折叠
set modeline "自动载入模式行
"自动插入modeline
func! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d :",
\ &tabstop, &shiftwidth, &textwidth)
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), l:modeline)
endfunc
"按\ml,自动插入modeline
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>
"空格展开折叠
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
"set tabstop=4
"set shiftwidth=4
set ts=4
set sw=4
set expandtab
"自动tab
if has("autocmd")
filetype plugin indent on
endif
autocmd filetype python setlocal et sta sw=4 sts=4
"根据文件类型自动插入文件头
autocmd BufNewFile *.py,*.sh exec ":call SetTitle()"
func SetTitle()
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
call append(line("."), "\# Author:itxx00@gmail.com")
call append(line(".")+1, "")
else
call setline(1, "\#!/bin/env python")
call append(line("."), "\#coding:utf-8")
call append(line(".")+1, "\#Author:itxx00@gmail.com")
call append(line(".")+2, "")
endif
endfunc
"新建文件后自动定位至文件末尾
autocmd BufNewFile * normal G
"F2去空行
nnoremap <F2> :g/^\s*$/d<CR>