VNarasimhaM
VNarasimhaM

Reputation: 1560

Moving a block of code by a tabspace

I am currently visually selecting the code and typing ">" which moves the code by 2 tabs. But I only want to move it by one tab.

Is there any alternate command in VIM to move the code by a tabspace. Ideally I would like to put a marker and then move the whole code block by a tabspace. Thanks

Upvotes: 1

Views: 695

Answers (3)

Stephan202
Stephan202

Reputation: 61499

There are easier ways to do what you want, as others have pointed out, but the following is of more general use:

  • You can select a column by pressing ctrl+v and then using the up and down keys (or j and k).
  • Next press I to go to insert mode. Now you can type anthing you like. In your case, type a single tab.
  • Finish by pressing esc, and see how your edit is applied to all lines.

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328594

> moves the code by one shiftwidth. So you need to set that option correctly.

Upvotes: 2

Marcin
Marcin

Reputation: 12590

This will set your shifting width to four spaces (default tab size):

:set sw=4

You can also change the size of the tab stop itself (X is any value you like):

:set ts=X

And if you like to use spaces instead of tab characters, use this:

:set expandtab

If you use the same settings in many files, you can put these in your .vimrc.

Upvotes: 3

Related Questions