일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- virtual
- gfortran
- c++
- mpi4py
- hyperref
- cython
- GSL
- h5py
- Anaconda
- portforwarding
- vi
- arXiver
- Visual Studio
- datascience
- HDF5
- MAC
- LaTeX
- Windows
- tab space
- Matplotlib
- python
- jupyter
- intel compiler
- conda
- vim
- SSH
- HFS+
- polyglot
- openmp
- cygwin
- Today
- Total
Astro Coke
[Python] Vim: Fix python indentation Error 본문
source: https://iqbalnaved.wordpress.com/2013/12/09/vim-tip-how-to-fix-python-exception-indentationerror/
When it has an error due to the indentation (see following message)
>> TabError: inconsistent use of tabs and spaces in indentation <<
it can be resolved in vim editor by the following steps.
The problem is usually with mixup in tabs and spaces –
Solution 1
1. Apply following command in Vim to highlight tabs, spaces and other whitespace differently.
> :set listchars=tab:>-,trail:-,eol:$ list
2. Apply the following to set correct width
> :set shiftwidth=4 tabstop=4 expandtab
3. running
> :retab
Solution 2
1. set ‘list’, so that you can see the whitespace and change.
Have the following mapping in .vimrc for this:
nnoremap <F2> :<C-U>setlocal lcs=tab:>-,trail:-,eol:$ list! list? <CR>
2. Ensure ‘expandtab’ is reset, check using following command –
:verbose set ts? et?
3. To expand all leading spaces (wider than ‘tabstop’), use retab.
retab takes a range, so specify % to mean “the whole file”.
:set tabstop=4 " To match the python file
:set noexpandtab " Use tabs, not spaces
:%retab! " Retabulate the whole file
'Computer Setup' 카테고리의 다른 글
[Cygwin] Import User Path Variable in Windows when access with SSH (0) | 2019.04.04 |
---|---|
[Cygwin] Using Tex Live in Cygwin (0) | 2019.04.04 |
[Python] inline backend 와 matplotlibrc 의 충돌 (0) | 2019.04.03 |
[Cython&openmp] omp.h file not found (0) | 2019.03.28 |
[Python] Switching between python 2.x and 3.x (0) | 2019.03.28 |