IceGuye Blog

Some simple settings on vim when code Python

Some simple settings on vim when code Python

To code python, we need some simple settings on vim, because python is a very special programming language that requires indentation. It requires 4 spaces before each logical block. If we use default settings, the click-click-click-click is the most thing you do in coding, and it is awful.

Actually we only need add 4 lines in vim's configure file, so let's open it:

$ vim ~./vimrc

and then, add these 4 lines:

syntax on set tabstop=4 set shiftwidth=4 set expandtab

It is simple right, but what are the means of the 4 lines?

  1. "syntax on" is to turn on the programming highlight. Your editor will display different colors based on your programming logic.

  2. "set tabstop=4" is to change each tab from 8 spaces width(default) to 4 spaces width.

  3. "set shiftwidth=4" is to change each indenting command from 8 spaces width(default) to 4 spaces width.

  4. "set expandtab" is to change every TAB to space characters.

There is also a tip when you are coding. If you need to indent more then one line, for example, to indent 42 lines, you can use this command:

42>>

There is elementary school math tip: you do not need to count every single line in a block. You can do it like this: Bottom line number - top line number + 1 = total line number of a block.

All right, that's it, have fun, be free.




Back to Blog's index