Skip to content

Instantly share code, notes, and snippets.

@do3cc
Last active April 14, 2016 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save do3cc/4de070dfa15e945a21ea4e54c6247790 to your computer and use it in GitHub Desktop.
Save do3cc/4de070dfa15e945a21ea4e54c6247790 to your computer and use it in GitHub Desktop.
How to run isort only for specific projects
# ~/.vimrc
" Allow project specific vimrc files
set exrc
set secure " Prevent potentially malicious vimrc files from breaking stuff
" Isort
function! Isort()
let cursor_pos = getpos('.')
%!isort -
call setpos('.', cursor_pos)
endfunction
command! -range=% Isort :<line1>,<line2>! :Isort()
...
# ~/projects/some_project/.vimrc
" This project has an ISort configuration
" So automatically sort imports according to its config
autocmd FileType python autocmd BufWritePre <buffer> :call Isort()
#################################
# Bonus for better buildout files
#################################
# ~/.vimrc
" Allow project specific vimrc files
set exrc
set secure " Prevent potentially malicious vimrc files from breaking stuff
" normalize buildout
function Normalizebuildout()
let cursor_pos = getpos('.')
%!normalize_buildout -
call setpos('.', cursor_pos)
endfunction
command! -range=% Normalizebuildout :Normalizebuildout()
$ cd $project
$ source bin/activate
$ pip install buildout_helpers
# ~/projects/some_project/.vimrc
" This project has an ISort configuration
" So automatically sort imports according to its config
autocmd BufWritePre *.cfg :call Normalizebuildout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment