Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Vim from indenting line when typing a colon (:) in Python

Tags:

python

vim

vi

Whenever I append a : character in Vim in Python mode, it either:

  • indents the line
  • dedents the line
  • does nothing

What is it even trying to do, and how do I get rid of this behavior?

like image 619
Vladimir Keleshev Avatar asked Oct 11 '13 14:10

Vladimir Keleshev


People also ask

How do I stop Vim from auto tabbing?

Globally Disable Auto-Indentation by Disabling the Filevim files (eg. sh. vim ) who set indentexpr option (eg to GetShIndent() ).

How do I change the indentation in Vim?

Fix indentation in the whole fileStart in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.

How do I paste into format in Vim?

Paste toggleStart insert mode. Press F2 (toggles the 'paste' option on). Use your terminal to paste text from the clipboard. Press F2 (toggles the 'paste' option off).


1 Answers

Certain keys, when pressed, will trigger Vim's indent feature, which will attempt to set the correct amount of indentation on the current line. (You can manually trigger this by typing == in normal mode.)

You can change which keys trigger this behavior, but first you need to know what indenting mode is being used.

First, execute :set indentexpr?. If it is nonempty (I would expect this for Python), then indentexpr mode is being used. In this case, executing :set indentkeys? gives you the list of trigger keys. To remove the colon, execute :setlocal indentkeys-=:.

If indentexpr is empty, then you are probably using cindent mode, and :set cindent? will tell you that cindent is set. In this case, do the same as before, but using cinkeys instead of indentkeys. (Note that indentexpr mode takes precedence over cindent mode.)

like image 71
Nathan Grigg Avatar answered Sep 27 '22 20:09

Nathan Grigg