Difference between revisions of "Python"
From Teknologisk videncenter
m |
m (→Vim setting for python) |
||
Line 21: | Line 21: | ||
autocmd FileType python set smartindent | autocmd FileType python set smartindent | ||
autocmd FileType python set shiftwidth=4 | 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 map <buffer> <F2> :w<CR>:exec '! python' shellescape(@%, 1)<CR> | ||
autocmd FileType python imap <buffer> <F2> <esc>:w<CR>:exec '! python' shellescape(@%, 1)<CR> | autocmd FileType python imap <buffer> <F2> <esc>:w<CR>:exec '! python' shellescape(@%, 1)<CR> |
Revision as of 09:37, 3 December 2023
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>