问题:打开.py文档,插入模式下键入:出现
=swap()
E117:unknow function:swap
vimrc如下:
" * CreateDate : Apr 22,2010
" * LastModified :
"保存.vimrc文件后会自动调用新的.vimrc
autocmd! bufwritepost .vimrc source ~/_vimrc
" 设定主题
colo molokai
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" 设置不兼容模式
set nocp
" 设定默认解码
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
" 设置显示字体
if has("win32")
set guifont=XHei\ mono:h12
endif
ab xmain int main(int argc, char *argv[])<cr>{<cr>}<up><cr>return
" 窗口最大化
autocmd GUIEnter * simalt ~x
" 载入文件类型插件
filetype plugin on
" 侦测文件类型
filetype on
" 开启插件
filetype plugin indent on
" 自动格式化设置
" 允许使用ftplugin目录下的文件类型特定脚本
filetype indent on
set autoindent
set smartindent
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=indent,eol,start
" browsedir设置
set browsedir=buffer
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 设置鼠标支持
set mouse=a
" 语法高亮
syntax on
" 不要备份文件(根据自己需要取舍)
set nobackup
" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
" 增强模式中的命令行自动完成操作
set wildmenu
"pydiction自动补全
filetype plugin on
let g:pydiction_location = 'D:\Program Files\Vim\vimfiles\ftplugin\complete-dict'
"defalut g:pydiction_menu_height == 15
let g:pydiction_menu_height = 10
" 自动补全括号,包括大括号
: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>
" 隐藏掉菜单和工具条。
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>
" 标签页设置
if has("gui_running")
set showtabline=2
map! tn tabnew
nmap <C-c> :tabclose<CR>
endif
" 标签页只显示文件名
function ShortTabLabel ()
let bufnrlist = tabpagebuflist (v:lnum)
let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
let filename = fnamemodify (label, ':t')
return filename
endfunction
set guitablabel=%{ShortTabLabel()}
" 显示未完成命令
set showcmd
" 显示行号
set number
" 保存文件格式
set fileformats=unix,dos
" 用浅色高亮当前行
if has("gui_running")
autocmd InsertLeave * se nocul
autocmd InsertEnter * se cul
endif
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=3
" 在搜索的时候忽略大小写
set ignorecase
" 不要高亮被搜索的句子(phrases)
" set nohlsearch
" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
" 输入:set list命令是应该显示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
" Tab补全时忽略这些忽略这些
set wildignore=*.o,*.obj,*.bak,*.exe
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
"搜索出之后高亮关键词
set hlsearch
nmap <silent> <leader><cr> :noh<cr>
"设置= + - * 前后自动空格
"设置,后面自动添加空格
au FileType python inoremap <buffer>= <c-r>=EqualSign('=')<CR>
au FileType python inoremap <buffer>+ <c-r>=EqualSign('+')<CR>
au FileType python inoremap <buffer>- <c-r>=EqualSign('-')<CR>
au FileType python inoremap <buffer>* <c-r>=EqualSign('*')<CR>
au FileType python inoremap <buffer>/ <c-r>=EqualSign('/')<CR>
au FileType python inoremap <buffer>> <c-r>=EqualSign('>')<CR>
au FileType python inoremap <buffer>< <c-r>=EqualSign('<')<CR>
au FileType python inoremap <buffer>: <c-r>=Swap()<CR>
au FileType python inoremap <buffer>, ,<space>
"实现+-*/前后自动添加空格,逗号后面自动添加空格,适用python
"支持+= -+ *= /+格式
function! EqualSign(char)
if a:char =~ '=' && getline('.') =~ ".*("
return a:char
endif
let ex1 = getline('.')[col('.') - 3]
let ex2 = getline('.')[col('.') - 2]
if ex1 =~ "[-=+><>\/\*]"
if ex2 !~ "\s"
return "\<ESC>i".a:char."\<SPACE>"
else
return "\<ESC>xa".a:char."\<SPACE>"
endif
else
if ex2 !~ "\s"
return "\<SPACE>".a:char."\<SPACE>\<ESC>a"
else
return a:char."\<SPACE>\<ESC>a"
endif
endif
endf
"实现括号的自动配对后防止重复输入),适用python
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
" 自动完成的缩进。
if has("autocmd")
if has("gui")
autocmd WinLeave * set nocursorline nocursorcolumn
autocmd WinEnter * set cursorline cursorcolumn
else
autocmd WinLeave * set nocursorline nocursorcolumn
autocmd WinEnter * set cursorline nocursorcolumn
endif
" Enable file type detection.
" load view saved by the mkview command
autocmd FileType * loadview
autocmd FileType * set noexpandtab
autocmd BufWinEnter * loadview
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" In text files, always limit the width of text to 78 characters
autocmd FileType text set textwidth=78 expandtab softtabstop=4
autocmd FileType sh set shiftwidth=4 expandtab softtabstop=4
autocmd FileType php set shiftwidth=4 expandtab softtabstop=4
autocmd FileType html set shiftwidth=4 expandtab softtabstop=4
autocmd FileType javascript set shiftwidth=4 expandtab softtabstop=4
autocmd FileType python set shiftwidth=4 expandtab softtabstop=4
autocmd FileType ruby set shiftwidth=4 expandtab softtabstop=4
autocmd FileType eruby set shiftwidth=4 expandtab softtabstop=4
autocmd FileType sql set shiftwidth=4 expandtab softtabstop=4
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute "normal g`\"" |
\ endif
augroup prog
" Remove all cprog autocommands
autocmd!
" When starting to edit a file:
" For C and C++ files set formatting of comments and set C-indenting on.
" For other files switch it off.
" Don't change the order, it's important that the line with * comes first.
autocmd FileType * set formatoptions=tcoql nocindent comments&
autocmd BufWinLeave *.sh,*.c,*.cpp,*.perl,*.py mkview
autocmd BufWinEnter *.sh,*.c,*.cpp,*.perl,*.py silent loadview
function! CleverTab()
if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-N>"
endfunction
autocmd FileType c,cpp noremap! <S-Tab> <C-R>=CleverTab()<CR>
autocmd FileType c,cpp noremap! <C-]> <C-X><C-]>
autocmd FileType c,cpp noremap! <C-F> <C-X><C-F>
autocmd FileType c,cpp noremap! <C-D> <C-X><C-D>
autocmd FileType c,cpp noremap! <C-L> <C-X><C-L>
autocmd FileType c,cpp,sh,perl,python set fileformat=unix
autocmd FileType sh set formatoptions=croql cindent comments=b:#
autocmd FileType c,cpp set expandtab shiftwidth=4 softtabstop=4
augroup END
endif " has("autocmd")
" 打开文件时,总是跳到退出之前的光标处
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" 更改Leader为","
let g:C_MapLeader = ','
" 不要闪烁
set novisualbell
"Python 文件的一般设置,比如不要 tab 等
"设置自动缩进为4,插入模式里: 插入 <Tab> 时使用合适数量的空格。
"要插入实际的制表,可用 CTRL-V<Tab>
autocmd FileType python setlocal expandtab | setlocal shiftwidth=4 |
\setlocal softtabstop=4 | setlocal textwidth=76 |
\tabstop=4