16

I am using MonoDevelop on Mac to write MonoTouch apps. Automatica code indenting/formatting works great while I am typing.

The problem is that when I copy and paste code snippets, in many cases I lose the formatting and lines are combined together, indenting is lost, and it is a huge pain to implement the tabs, spacing, and line breaks manually. Is there anyway I can use a command in monoDevelop to automatically indent and apply the formatting to existing code.

I thought maybe Edit|Format|Format Document/Selection would work, but these commands don't have any affect on the code at all.

Any help?

user1060500
  • 1,505
  • 1
  • 21
  • 40
  • Change your formatting settings so that the code is formatted how you like it. Right now, it's formatting your code automatically in the default fashion. – Ry- May 04 '12 at 23:12
  • user1060500, if my answer helped, perhaps you could accept the answer and/or upvote it? :-D – Jason Hartley Feb 27 '14 at 22:39

3 Answers3

29

To format the entire document in one keystroke: control-I

To format a selection: Edit->Format->Format Selection

To customize the formatting: MonoDevelop->Preferences->Source Code->Code Formatting

Jason Hartley
  • 2,459
  • 1
  • 31
  • 40
  • 3
    keystroke was not set in my case, but added it to key Bindings ­­`Tools->Options->Key Binding` then searched `format`. Thanks! – GabLeRoux Mar 08 '14 at 02:59
  • Funny as I was struggling to understand the shortcut shown as "^ l" on the menu item. Tried `CTRL`+ all the vertical bar characters I could think of, but did not think about the small cap 'i'... Thanks! – Attila Mar 23 '18 at 00:05
4

You actually need to select all your text, and then go to Edit->Format->Format Document. It doesn't seem to work otherwise.

Erik Asmussen
  • 231
  • 2
  • 5
2

For me on macOS, the shortcut for "auto-format" is CTRL + i.

You can change the shortcut if you want. To change it, go to Preferences -> Key Bindings, then type "format" in the search box and edit the "Format Document" shortcut/key binding.

tedi
  • 6,350
  • 5
  • 52
  • 67