How Can I Check Python Indentation in VIM?

How Can I Check Python Indentation in VIM? thumbnail
Minor source code errors cause programmers no end of frustration.

In Python, as in any operating system, properly indenting your code is key. This is how the interpreter knows which lines of code belong to which class, which method and which statement. Making a mistake in your indentation can cause your Python source code to fail to execute or malfunction in the middle of its execution. In lengthy source code, indentation can be hard to spot with the naked eye, but simply moving your cursor down a column in VIM gives you a reliable way to catch indentation errors.

Instructions

    • 1

      Open a command prompt by clicking on the "Start" menu in the lower left-hand corner of the screen; type "cmd" into the search bar, and click on the command line menu entry.

    • 2

      Type "cd" followed by the address to the directory in which you saved your Python source code.

    • 3

      Type "gvim MySource.py" where "MySource" is the name of your python source code file. This will cause the source code to open in the VIM editor.

    • 4

      Use the arrow keys to scroll down to each function and statement. Place the cursor over the first letter of the function name, and press the down button. Each line that belongs to that function should be indented at least one space in from the function name, so each line should start immediately after your cursor. If you see one that is out of line, move it over accordingly.

    • 5

      Type "ESC" followed by "w" to save any changes you made, then "ESC" followed by "q" to exit VIM.

Related Searches:

References

  • Photo Credit Digital Vision./Digital Vision/Getty Images

Comments

Related Ads

Featured