Python

From Teknologisk videncenter
Revision as of 09:42, 3 December 2023 by Heth (talk | contribs) (Vim setting for python)
Jump to: navigation, search


Programming style

  • Recomended indent - 4 spaces
pip install reindent  # Pyhon reindent script
reindent my_script.py

Vim setting for python

add following lines in ~/.vimrc

"Python Settings
autocmd FileType python set softtabstop=4
autocmd FileType python set tabstop=4
autocmd FileType python set autoindent
autocmd FileType python set expandtab
autocmd FileType python set textwidth=80
autocmd FileType python set smartindent
autocmd FileType python set shiftwidth=4
" Map <F2> to write file and execute script in both command- and insert mode
autocmd FileType python map <buffer> <F2> :w<CR>:exec '! python' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F2> <esc>:w<CR>:exec '! python' shellescape(@%, 1)<CR>