Chinaunix首页 | 论坛 | 博客
  • 博客访问: 166947
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 425
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-13 17:05
文章分类

全部博文(31)

文章存档

2016年(11)

2015年(20)

我的朋友

分类: Python/Ruby

2016-01-23 12:28:24


和大多数人一样,选择了语言然后该轮到选择操作系统,选完操作系统又开始纠结ide。人生啊。

选来选去,最后还是觉得用linux并使用vim来编写python,毕竟这样让我感觉高效一点。win写python总有点不伦不类的感觉。

下面就是我对vim一些基本的配置,日常够用就好。

1、补全功能(这个功能真是重中之重)。

安装配置:

  1. wget https://github.com/rkulla/pydiction/archive/master.zip
  2. unzip -q master
  3. mv pydiction-master pydiction
  4. mkdir -p ~/.vim/tools/pydiction
  5. cp -r pydiction/after ~/.vim
  6. cp pydiction/complete-dict ~/.vim/tools/pydiction

上面地址不存在可以在 下载  密码:dp4e
确保文件结构如下:

# tree ~/.vim
/root/.vim
├── after
│   └── ftplugin
│       └── python_pydiction.vim
└── tools
    └── pydiction
        └── complete-dict

创建~/.vimrc,确保其中内容如下:

  1. # cat ~/.vimrc
  2. filetype plugin on
  3. let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'

OK 这样就好了。


2、针对python开发对Vim的一些简单配置

  1. filetype plugin on
  2. let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'
  3. "set number "显示行号
  4. syntax on "语法高亮
  5. set smartindent "智能缩进
  6. "set autoindent "ai 自动缩进
  7. set incsearch "设置快速搜索
  8. set foldenable "开启代码折叠
  9. set foldmethod=syntax "自动语法折叠
  10. set modeline "自动载入模式行
  11. "自动插入modeline
  12. func! AppendModeline()
  13. let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d :",
  14. \ &tabstop, &shiftwidth, &textwidth)
  15. let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
  16. call append(line("$"), l:modeline)
  17. endfunc
  18. "按\ml,自动插入modeline
  19. nnoremap <silent> <Leader>ml :call AppendModeline()<CR>
  20. "空格展开折叠
  21. nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')
  22. "set tabstop=4
  23. "set shiftwidth=4
  24. set ts=4
  25. set sw=4
  26. set expandtab
  27. "自动tab
  28. if has("autocmd")
  29. filetype plugin indent on
  30. endif
  31. autocmd filetype python setlocal et sta sw=4 sts=4
  32. "根据文件类型自动插入文件头
  33. autocmd BufNewFile *.py,*.sh exec ":call SetTitle()"
  34. func SetTitle()
  35. if &filetype == 'sh'
  36. call setline(1, "\#!/bin/bash")
  37. call append(line("."), "\# Author:zhangsan")
  38. call append(line(".")+1, "")
  39. else
  40. call setline(1, "\#!/bin/env python")
  41. call append(line("."), "\#coding:utf-8")
  42. call append(line(".")+1, "\#Author:zhangsan")
  43. call append(line(".")+2, "")
  44. endif
  45. endfunc
  46. "新建文件后自动定位至文件末尾
  47. autocmd BufNewFile * normal G
  48. ""F2去空行
  49. nnoremap <F2> :g/^\s*$/d<CR>


这样就实现了缩进,自动补全,补充头文件等功能,这些都是从网上总结出来的。真实可用。这样就不用在为vim烦恼,可以专心搬砖了。

阅读(2041) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~