32

How do I shift a block of text to the left or right with Sublime Text 2?

erikvold
  • 3,977
  • 18
  • 51
  • 63

7 Answers7

50

You can use ctrl+ ] to indent a line (or highlighted block), and ctrl + [ to unindent.

On OSX this is cmd + ]/[.

You can also use tab/shift+tab, but these will start from wherever the cursor is currently, while ctrl+[/] will move the whole line/block

Ben McCormick
  • 791
  • 6
  • 7
  • 3
    at least on the mac version tab & shift-tab work on whole lines and the position of the cursor has no influence on it. – yamm May 08 '15 at 08:12
18

Check out colinta's SublimeMoveText. Install as a normal plugin (It's called "MoveText" by the Package Manager), but keybindings have to be set up manually. Here is what I did:

// MoveText
// move_text_left: Moves the selected text one character to the left
// move_text_right: Moves the selected text one character to the right
// move_text_up: Moves the selected text one line up
// move_text_down: Moves the selected text one line down
{ "keys": ["ctrl+shift+n"], "command": "move_text_left" },
{ "keys": ["ctrl+shift+m"], "command": "move_text_right" },

Highlight what you want to move. If it is more than one line, use column selection as @Jivings suggested (shift+right-click on Win/Linux, option+mouse on OSX). Then use the keybinding to move text left/right. You can also set up keybindings to move the selected up/down a line.

d_rail
  • 2,969
  • 1
  • 18
  • 21
  • 3
    Some people use this package with `super+ctrl+left/right` key bindings instead. Also, MoveText **moves text by character position, not by word,** which would have been handier for general text editing purposes. – Serge Stroobandt Aug 26 '14 at 12:11
3

Use column selection and then insert or delete spaces or tabs.

Or highlight a selection of text and press tab to move it right or shift+tab to move it left.

Jivings
  • 101
  • 13
1
  1. Select lines of code and press "tab" key but it works just to indent to right
  2. For moving piece of code back and forth (left or right) use key combination: 'CTRL' + '[' and/or 'CTRL' + ']'
zinturis
  • 11
  • 1
0
  1. Go to find replace (Ctrl + H)
  2. Select "Regular Expressions" and "In Selection" options.
  3. Select the block where you want to insert space.
  4. Replace all "^" with " "
Kapil
  • 1
0

To move lines left and right use :

⌘ + ] or ⌘ + [

To move lines up and down use :

⌘ + ctrl + upArrow or downArrow

0

It can be done with this command

in windows & linux

shift+tab

Netwons
  • 101
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 19 '21 at 14:21