Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "un-tab" sequence in (g)Vim?

This is an annoyance I've had for a long time.

(Nitpicky section: I prefer 4 space characters to tab characters. It's a lot easier to type "tab" instead of explaining that. When I say "tab", I mean "the action that happens when you press the tab key" which is probably more simply stated as "increase indentation".)

I'm using smartindent while editing a document where indentation has some significance. In "dumb" windows text editors I can press Shift+Tab to remove a tab or, more appropriately, decrease the indentation level of the current line. I can't figure out how to do this from edit mode in Vim; Shift+Tab seems to count just the same as Tab.

I know in Command mode << will decrease indentation. I want the equivalent in edit mode. These are the solutions I've found so far and why I don't like them, one in particular may be the key to the answer.

  1. Use Notepad++ or some other dumb editor. I've done this for a couple of years but I really miss Vim.
  2. Exit edit mode, use <<, enter edit mode. This just puts the cursor at column 0; if I wanted this I wouldn't have tried smartindent.
  3. Stop using smartindent. I don't decrease indent as often as I need to keep the same indent level; this would be a loss of productivity.
  4. The left arrow key seems to decrease the indent by one level. I'd rather something I can do without leaving the home row. This is the most promising choice.

Maybe there's an option I can set? Maybe I can rebind left arrow to something? (If it requires rebinding please explain in detail; I've never delved into reconfiguring (g)Vim.

like image 253
OwenP Avatar asked May 20 '10 14:05

OwenP


People also ask

How do I delete a tab in Vim?

In edit mode: One more level, press tab. Going back one level, press backspace.

How do I indent in vim normal mode?

In normal mode, press Tab or Shift-Tab to adjust the indent on the current line and position the cursor on the first nonblank character; in insert mode, press Shift-Tab to unindent; in visual mode, press Tab or Shift-Tab to adjust the indent on selected lines.

How do I indent multiple times in Vim?

Select what you want (typically with v or Shift + v ) then type 5> . If you need to fix or repeat the same selection, use gv . Show activity on this post. You can select the current line by pressing v , and then type 5> to indent the current line 5 times, the equivalent of pressing > 10 times.


1 Answers

You can use Ctrl+D to back up one tab stop. This actually moves the whole line to the left one tab stop; Ctrl+T does the same thing to the right.

Note that these keystrokes only work in Insert mode (use << and >> for the equivalent in Command mode).

like image 193
giftederic Avatar answered Sep 23 '22 08:09

giftederic