1. Hiro Ashiya
  2. vim-python-ide


vim-python-ide / .vimrc

" JPh Thierry's .vimrc file. A personal compilation my main activities with
" vim being python code development and rst files editing.
" Thanks to Gary Bernhardt. I took most of the nice features available here
" from his config file. A bit of refactoring later and some personal additions
" like pylint, cover syntax file, etc.
" XXX list all third-party modules users will have to download
" XXX write a cheat sheet
" XXX ease access to PythonPath function
" XXX makegreen and pytest still not working properly when pythonpath is not
" properly set. Catch error if possible
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" Allow backgrounding buffers without writing them, and remember marks/undo
" for backgrounded buffers
set hidden

" Remember more commands and search history
set history=1000

" Make tab completion for files/buffers act like bash
set wildmenu

" Make searches case-sensitive only if they contain upper-case characters
set ignorecase
set smartcase

" Keep more context when scrolling off the end of a buffer
set scrolloff=3

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

set nobackup		" do not keep a backup file, use versions instead
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands

" GRB: sane editing configuration"
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
" set smartindent
set laststatus=2
set showmatch
set incsearch
" GRB: wrap lines at 78 characters
set textwidth=78

" clear the search buffer when hitting return
nnoremap <CR> :nohlsearch<CR>/<BS>

" Display linenumber
set number
set numberwidth=5

" highlight current line
set cursorline

" Set height of the command zone
set cmdheight=2

" GRB: use emacs-style tab completion when selecting files, etc
set wildmode=longest,list

set switchbuf=useopen

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
  set gfn=Bitstream\ Vera\ Sans\ Mono\ 10

" Change <leader> key to ,
let mapleader=","

" GRB: Put useful info in status line
set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red

" GRB: hide the toolbar in GUI mode
if has("gui_running")
    set guioptions-=T
    " Don't show scroll bars in the GUI
    set guioptions-=L
    set guioptions-=r
    " GRB: set window size"
    :set lines=100
    :set columns=171
    :color grb3
    :color grb4

" Generic mappings
" Don't use Ex mode, use Q for formatting
map Q gq
" Seriously, guys. It's not like :W is bound to anything anyway.
command! W :w

" Display the mini buffer explorer at the top of the screen
" And add some keyboard shorcuts
" <C-TAB> will cycle buffers; easy to change file!
let g:miniBufExplMapCTabSwitchBufs = 1
source ~/.vim/plugin/minibufexpl.vim

" Now we deal with useful settings for coding
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78

" 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("$") |
\   exe "normal g`\"" |
\ endif
augroup END

" Remap the tab key to do autocompletion or indentation depending on the
" context (from http://www.vim.org/tips/tip.php?tip_id=102)
function! InsertTabWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
        return "\<tab>"
        return "\<c-p>"
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>

" When hitting <;>, complete a snippet if there is one; else, insert an actual
" <;>
function! InsertSnippetWrapper()
    let inserted = TriggerSnippet()
    if inserted == "\<tab>"
        return ";"
        return inserted
inoremap ; <c-r>=InsertSnippetWrapper()<cr>
snor ; <esc>i<right><c-r>=TriggerSnippet()<cr>

" add personal snippets to the default ones
let g:snippets_dir = globpath(&rtp, 'snippets/') . ',' . globpath(&rtp, 'snippets/mine')

if version >= 700
    autocmd FileType python set omnifunc=pythoncomplete#Complete
    let Tlist_Ctags_Cmd='/usr/bin/ctags'

" Use <c-h> for snippets
let g:NERDSnippets_key = '<c-h>'

" Map ,e to open files in the same directory as the current file
map <leader>e :e <C-R>=expand("%:h")<cr>/

map <leader>ws :%s/ *$//g<cr><c-o><cr>

map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>

" Make <leader>' switch between ' and "
nnoremap <leader>' ""yls<c-r>={'"': "'", "'": '"'}[@"]<cr><esc>

" Python related stuff
" Pylint is the default compiler for python files
let g:pylint_onwrite = 0
au FileType python compiler pylint
" Except test files which are run using pytest.
au! BufNewFile,BufRead test_*.py compiler unit2
" and launched using vim-makegreen
map <leader>rt <Plug>MakeGreen
" Code quality
" Complexity evaluation thanks to GRB
" (https://github.com/garybernhardt/pycomplexity/blob/master/complexity.vim)
map <F5> :call ShowComplexity()<cr>
map <F6> :call Pylint(1)<cr>

let python_highlight_all = 1
let python_slow_sync = 1

" augroup mkd
"     autocmd BufRead *.mkd  set ai formatoptions=tcroqn2 comments=n:&gt;
"     autocmd BufRead *.markdown  set ai formatoptions=tcroqn2 comments=n:&gt;
" augroup END
" autocmd BufRead,BufNewFile *.feature set sw=4 sts=4 et
" autocmd BufRead,BufNewFile *.html source ~/.vim/indent/html_grb.vim
" autocmd FileType htmldjango source ~/.vim/indent/html_grb.vim
" autocmd! BufRead,BufNewFile *.sass setfiletype sass 
" augroup myfiletypes
"   "clear old autocmds in group
"   autocmd!
"   "for ruby, autoindent with two spaces, always expand tabs
"   autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass set ai sw=2 sts=2 et
" augroup END
" map <leader>f :CommandT<cr>