├── .gitignore ├── .vimrc ├── README.md ├── __init__.py ├── demo.py ├── test.py ├── utils.py └── vim-as-a-python-ide.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.ropeproject 3 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " Sample .vimrc file by Martin Brochhaus 2 | " Presented at PyCon APAC 2012 3 | 4 | 5 | " ============================================ 6 | " Note to myself: 7 | " DO NOT USE FOR SAVING WHEN PRESENTING! 8 | " ============================================ 9 | 10 | 11 | " Automatic reloading of .vimrc 12 | "" autocmd! bufwritepost .vimrc source % 13 | 14 | 15 | " Better copy & paste 16 | " When you want to paste large blocks of code into vim, press F2 before you 17 | " paste. At the bottom you should see ``-- INSERT (paste) --``. 18 | 19 | "" set pastetoggle= 20 | "" set clipboard=unnamed 21 | 22 | 23 | " Mouse and backspace 24 | "" set mouse=a " on OSX press ALT and click 25 | "" set bs=2 " make backspace behave like normal again 26 | 27 | 28 | " Rebind key 29 | " I like to have it here becuase it is easier to reach than the default and 30 | " it is next to ``m`` and ``n`` which I use for navigating between tabs. 31 | "" let mapleader = "," 32 | 33 | 34 | " Bind nohl 35 | " Removes highlight of your last search 36 | " ```` stands for ``CTRL`` and therefore ```` stands for ``CTRL+n`` 37 | "" noremap :nohl 38 | "" vnoremap :nohl 39 | "" inoremap :nohl 40 | 41 | 42 | " Quicksave command 43 | "" noremap :update 44 | "" vnoremap :update 45 | "" inoremap :update 46 | 47 | 48 | " Quick quit command 49 | "" noremap e :quit " Quit current window 50 | "" noremap E :qa! " Quit all windows 51 | 52 | 53 | " bind Ctrl+ keys to move around the windows, instead of using Ctrl+w + 54 | " Every unnecessary keystroke that can be saved is good for your health :) 55 | "" map j 56 | "" map k 57 | "" map l 58 | "" map h 59 | 60 | 61 | " easier moving between tabs 62 | "" map n :tabprevious 63 | "" map m :tabnext 64 | 65 | 66 | " map sort function to a key 67 | "" vnoremap s :sort 68 | 69 | 70 | " easier moving of code blocks 71 | " Try to go into visual mode (v), thenselect several lines of code here and 72 | " then press ``>`` several times. 73 | "" vnoremap < >gv " better indentation 75 | 76 | 77 | " Show whitespace 78 | " MUST be inserted BEFORE the colorscheme command 79 | "" autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red 80 | "" au InsertLeave * match ExtraWhitespace /\s\+$/ 81 | 82 | 83 | " Color scheme 84 | " mkdir -p ~/.vim/colors && cd ~/.vim/colors 85 | " wget -O wombat256mod.vim http://www.vim.org/scripts/download_script.php?src_id=13400 86 | "" set t_Co=256 87 | "" color wombat256mod 88 | 89 | 90 | " Enable syntax highlighting 91 | " You need to reload this file for the change to apply 92 | "" filetype off 93 | "" filetype plugin indent on 94 | "" syntax on 95 | 96 | 97 | " Showing line numbers and length 98 | "" set number " show line numbers 99 | "" set tw=79 " width of document (used by gd) 100 | "" set nowrap " don't automatically wrap on load 101 | "" set fo-=t " don't automatically wrap text when typing 102 | "" set colorcolumn=80 103 | "" highlight ColorColumn ctermbg=233 104 | 105 | 106 | " easier formatting of paragraphs 107 | "" vmap Q gq 108 | "" nmap Q gqap 109 | 110 | 111 | " Useful settings 112 | "" set history=700 113 | "" set undolevels=700 114 | 115 | 116 | " Real programmers don't use TABs but spaces 117 | "" set tabstop=4 118 | "" set softtabstop=4 119 | "" set shiftwidth=4 120 | "" set shiftround 121 | "" set expandtab 122 | 123 | 124 | " Make search case insensitive 125 | "" set hlsearch 126 | "" set incsearch 127 | "" set ignorecase 128 | "" set smartcase 129 | 130 | 131 | " Disable stupid backup and swap files - they trigger too many events 132 | " for file system watchers 133 | "" set nobackup 134 | "" set nowritebackup 135 | "" set noswapfile 136 | 137 | 138 | " Setup Pathogen to manage your plugins 139 | " mkdir -p ~/.vim/autoload ~/.vim/bundle 140 | " curl -so ~/.vim/autoload/pathogen.vim https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim 141 | " Now you can install any plugin into a .vim/bundle/plugin-name/ folder 142 | "" call pathogen#infect() 143 | 144 | 145 | " ============================================================================ 146 | " Python IDE Setup 147 | " ============================================================================ 148 | 149 | 150 | " Settings for vim-powerline 151 | " cd ~/.vim/bundle 152 | " git clone git://github.com/Lokaltog/vim-powerline.git 153 | "" set laststatus=2 154 | 155 | 156 | " Settings for ctrlp 157 | " cd ~/.vim/bundle 158 | " git clone https://github.com/kien/ctrlp.vim.git 159 | "" let g:ctrlp_max_height = 30 160 | "" set wildignore+=*.pyc 161 | "" set wildignore+=*_build/* 162 | "" set wildignore+=*/coverage/* 163 | 164 | 165 | " Settings for python-mode 166 | " Note: I'm no longer using this. Leave this commented out 167 | " and uncomment the part about jedi-vim instead 168 | " cd ~/.vim/bundle 169 | " git clone https://github.com/klen/python-mode 170 | "" map g :call RopeGotoDefinition() 171 | "" let ropevim_enable_shortcuts = 1 172 | "" let g:pymode_rope_goto_def_newwin = "vnew" 173 | "" let g:pymode_rope_extended_complete = 1 174 | "" let g:pymode_breakpoint = 0 175 | "" let g:pymode_syntax = 1 176 | "" let g:pymode_syntax_builtin_objs = 0 177 | "" let g:pymode_syntax_builtin_funcs = 0 178 | "" map b Oimport ipdb; ipdb.set_trace() # BREAKPOINT 179 | 180 | " Settings for jedi-vim 181 | " cd ~/.vim/bundle 182 | " git clone git://github.com/davidhalter/jedi-vim.git 183 | "" let g:jedi#usages_command = "z" 184 | "" let g:jedi#popup_on_dot = 0 185 | "" let g:jedi#popup_select_first = 0 186 | "" map b Oimport ipdb; ipdb.set_trace() # BREAKPOINT 187 | 188 | " Better navigating through omnicomplete option list 189 | " See http://stackoverflow.com/questions/2170023/how-to-map-keys-for-popup-menu-in-vim 190 | "" set completeopt=longest,menuone 191 | "" function! OmniPopup(action) 192 | "" if pumvisible() 193 | "" if a:action == 'j' 194 | "" return "\" 195 | "" elseif a:action == 'k' 196 | "" return "\" 197 | "" endif 198 | "" endif 199 | "" return a:action 200 | "" endfunction 201 | 202 | "" inoremap =OmniPopup('j') 203 | "" inoremap =OmniPopup('k') 204 | 205 | 206 | " Python folding 207 | " mkdir -p ~/.vim/ftplugin 208 | " wget -O ~/.vim/ftplugin/python_editing.vim http://www.vim.org/scripts/download_script.php?src_id=5492 209 | "" set nofoldenable 210 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vim as a Python IDE 2 | 3 | This is the code for my PyCon APAC 2012 talk about Vim as Python IDE. 4 | 5 | Video: https://www.youtube.com/watch?v=YhqsjUUHj6g 6 | Slides: https://speakerdeck.com/u/mbrochh/p/vim-as-a-python-ide 7 | 8 | You can also find the slides as a PDF in this repository. 9 | 10 | If you want to start using Vim for the first time, have a look at the 11 | ``.vimrc`` file in this repository and gradually uncomment everything. 12 | 13 | Then install the plugins mentionned at the bottom of the file and you should 14 | be good to go. 15 | 16 | Please note that I am no longer using the [python-mode](https://github.com/klen/python-mode) 17 | plugin. Instead I am now using the [jedi-vim](https://github.com/davidhalter/jedi-vim/) 18 | plugin, which I find a bit easier to configure and it seems to have better 19 | auto-completion features. 20 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbrochh/vim-as-a-python-ide/541b97e59fe8add8b786d77058d6d20de3f50643/__init__.py -------------------------------------------------------------------------------- /demo.py: -------------------------------------------------------------------------------- 1 | """Module for testing some python-mode features.""" 2 | # import os 3 | 4 | from utils import set_breakpoint 5 | 6 | 7 | def main(*args, **kwargs): 8 | """See? We got nice syntax highting.""" 9 | print 'Hello world' 10 | set_breakpoint(42, 42, data={'key': 'value', }) 11 | 12 | 13 | def fold_this(): 14 | """We can fold and unfold code blocks by pressing ``f``.""" 15 | print 'Fold it.' 16 | 17 | 18 | def fold_all(): 19 | """We can fold and unfold everything by pressing ``F``.""" 20 | print 'Fold all.' 21 | 22 | 23 | def create_ropeproject(): 24 | """We would create a ropeproject by executing ``:RopeOpenProject``.""" 25 | print 'Now add your venv to ``.ropeproject/config.py``!' 26 | 27 | 28 | def life_syntax_checking(): 29 | """Pylint checks our code on each save.""" 30 | # Try to uncomment this and save. 31 | # Try to uncomment the os import and save. 32 | # abc = 5 # Try to uncomment this line and save. 33 | 34 | # Now fix all reported issues! 35 | # You can move down into the Quickfix window witch ```` 36 | # You can navigate up and down in that window with ``j`` and ``k`` 37 | 38 | # When you press enter, you will get back into this window at the correct 39 | # line 40 | 41 | 42 | def code_completion(): 43 | """Code completion makes life easy.""" 44 | # Try to call one of our methods here. 45 | # i.e.: Type ``li`` and then press ```` 46 | # You can navigate between then found choices by holding ``CTRL`` and using 47 | # ``j`` and ``k`` 48 | 49 | # Try to import something from utils 50 | # i.e. Type ``from utils import`` and then press ```` 51 | 52 | 53 | def open_utils_py(): 54 | """We can use Ctlp to open files in our project.""" 55 | print 'Open ``utils.py`` in a new vertical split via ``ut``' 56 | print 'Now open ``utils.py`` in a new tab via ``ut``.' 57 | 58 | 59 | if __name__ == '__main__': 60 | main() 61 | -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | """Another file in our package.""" 2 | from urlparse import urljoin 3 | 4 | 5 | def print_twitter_url(): 6 | """We can lookup the urljoin method via ``g``.""" 7 | print urljoin('http://www.twitter.com', 'mbrochh') 8 | 9 | 10 | def try_to_import_from_demo_py(): 11 | """Code completion makes importing easy!""" 12 | print 'Try to import that method which starts with ``open_``.' 13 | 14 | 15 | def set_breakpoint(arg1, arg2, data=None): 16 | """ 17 | We can set breakpoints via ``b``. 18 | 19 | Make sure you have ipython and ipdb installed:: 20 | 21 | pip install ipython 22 | pip install ipdb 23 | 24 | Then run your program from a new terminal window like so: 25 | 26 | python demo.py 27 | 28 | Use ``?`` to show all available commands and ``? `` to show help 29 | for a certain command. 30 | 31 | """ 32 | foo = 'bar' 33 | result = arg1 + arg2 34 | import ipdb; ipdb.set_trace() # BREAKPOINT 35 | print 'Try to set a breakpoint before this statement.' 36 | print 'Then run ``python demo.py``.' 37 | import ipdb; ipdb.set_trace() # BREAKPOINT 38 | print 'Good bye!' 39 | 40 | # Nice commands to try in ipdb: 41 | # ? 42 | # help a 43 | # a 44 | # l 45 | # next 46 | # inspect data 47 | # bt 48 | # u 49 | # s 50 | # c 51 | # exit 52 | -------------------------------------------------------------------------------- /vim-as-a-python-ide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbrochh/vim-as-a-python-ide/541b97e59fe8add8b786d77058d6d20de3f50643/vim-as-a-python-ide.pdf --------------------------------------------------------------------------------