3

I know how to use back-tick to create a multi-line command in the script pane or in a PowerShell script. This is not a question about that. If I am in vanilla PowerShell (not ISE) and I want to type this command at the prompt:

Get-Command `
| Sort Name `
| Select -First 10

How do I move to the next line after Get-Command without executing it?

Jason Boyd
  • 6,839
  • 4
  • 29
  • 47
  • have you tried a backslash(\\)? not sure if it'd work, but usually a backslash is used to break a continuous line. – Shiping Jan 26 '17 at 18:06
  • `.{ <# multiple lines here #> }` – user4003407 Jan 26 '17 at 18:19
  • [This answer in particular in the linked duplicate](http://stackoverflow.com/a/35180380/3905079) explains how to use `SHIFT ENTER`. – briantist Jan 26 '17 at 18:35
  • If you put a backtick at the end of the line, PowerShell prompts for more input. What specifically isn't working? – Bill_Stewart Jan 26 '17 at 18:36
  • @Bill_Stewart So that was actually the first thing I tried but I tried it at the command prompt in ISE and it did not work. I just assumed it would not work in vanilla PowerShell but apparently it does. Too bad the behavior is not consistent between the two. – Jason Boyd Jan 26 '17 at 18:46
  • @briantist I did see that question but felt that it was slightly different from what I am asking. The OP in that question is specifically asking for a charter to allow you perform line continuations. I know the character, I am looking for a key-combination to move to the next line without executing what is at the command prompt. The selected answer did not address that either. I did not read the other answers below the selected answer to find the answer you mentioned. – Jason Boyd Jan 26 '17 at 18:50
  • @JasonBoyd I see the difference in the original question, but the answer to your question can still be found there, and it's highly related. – briantist Jan 26 '17 at 19:08
  • @briantist - Actually, I was thinking about opening something on meta about this. I think my question really needs to be restated as I led people astray with this: 'vanilla PowerShell (not ISE)'. The fact is I was at the console in ISE which apparently behaves differently than vanilla PowerShell. The question should really be about moving the cursor to the next line when at the console in ISE (only shift+enter works in that case). That is different from the other question. But changing the question now would mean many of these comments would no longer make sense in the new context. – Jason Boyd Jan 26 '17 at 19:17
  • @JasonBoyd I would say just edit the question. As it happens, the answer I linked to has had some comments and it seems it applies only the ISE console anyway (or console host with PSReadLine), so it's actually still appropriate for your intended question. – briantist Jan 26 '17 at 19:44

2 Answers2

9

In Powershell, SHIFT + ENTER takes you to the new line.

Hope this helps.

Michal Cumpl
  • 997
  • 7
  • 12
  • In the ISE, try putting the `|` at the end of the line before you press `Shift+Enter`. – Bill_Stewart Jan 26 '17 at 19:20
  • @Bill_Stewart It appears that only works in vanilla PowerShell. Shift+Enter seems to be the only thing that works at the console in ISE. – Jason Boyd Jan 26 '17 at 19:26
  • You don't need the backtick in the ISE for line continuation since it supports multi-line input with `Shift+Enter`. But to keep from confusing the parser, you need to break the line in semantically sensible places (i.e., after a `|`). – Bill_Stewart Jan 26 '17 at 19:29
0

I think it is very similar to how you tried it:

Get-Command |`
Sort Name |`
Select -First 10
Narcis
  • 141
  • 6
  • 1
    No need to use backticks in this case, see [How to enter a multi-line command?](//stackoverflow.com/a/3235993) – wOxxOm Jan 26 '17 at 18:33