跳转到内容

Edit code

此内容尚不支持你的语言。

The editor’s commands work on lines, on syntax and on several places at once. Every command acts on every caret and is a single undo step. Editing commands, multiple carets and column selection: Works.

  • Add the next occurrence. Put the caret on a word and choose Edit › Add Selection for Next Occurrence (⌃G on macOS, AltJ on Linux). The first press selects the word, each further press adds the next whole-word occurrence. With text selected, it adds the next place with exactly that text. Unselect Occurrence takes the last one back.
  • Select all occurrences with Edit › Select All Occurrences, and type.
  • Click to add carets: ⌥⇧-click (AltShift-click) adds or removes a caret.
  • Carets above and below: press ⌥ (Ctrl on Linux) twice and keep it held, then press ↑ or ↓ to add a caret per press.
  • Ends of lines: select some lines and choose Edit › Add Carets to Ends of Selected Lines.
  • Column selection: ⌥-drag (Alt-drag) selects a rectangle. Edit › Column Selection Mode makes every click and drag do that; the status bar shows Column while it is on, and a click there turns it off. A column may reach past the end of short lines.

Completion accepted with several carets goes in at every caret. Pasting as many lines as there are carets puts one line at each caret. Esc goes back to one caret.

Command Menu What it does
Duplicate Line Edit › Duplicate Line copies the line, or the selection, below; the copy stays selected
Delete Line Edit › Delete Line deletes the lines of the carets
Move Line Up / Down Code › Move Line Up, Move Line Down moves lines past their neighbors
Move Statement Up / Down Code › Move Statement Up, Move Statement Down moves a whole statement or block, into and out of blocks, never out of its function
Move Element Left / Right (shortcut only) swaps an argument, parameter or list item with its neighbor
Join Lines Edit › Join Lines joins the next line, with one space where it belongs and none after ( or before ), , or ;
Comment with Line Comment Code › Comment with Line Comment comments or uncomments the lines; in Markdown, HTML and XML it uses <!-- -->
Comment with Block Comment Code › Comment with Block Comment wraps the selection in /* */ or <!-- -->, or unwraps it
Complete Current Statement Code › Complete Current Statement closes brackets and strings, adds the ;, the {} or the : the language needs
Unwrap/Remove… Code › Unwrap/Remove… removes an enclosing if, loop or block and keeps its body (languages with braces)

Typing an opening bracket or quote adds the closing one; Tab steps over it, and ⌫ in an empty pair deletes both. ↩ keeps the indentation and indents once more after {, (, [ or :. Pasting several lines into source code re-indents them.

Edit › Extend Selection (⌥↑, CtrlW) grows the selection step by step along the syntax tree: the word, the expression, the string’s content, the statement, whole lines, the block, the whole file. Shrink Selection goes back one step.

In the Edit menu:

  • Sort Lines and Reverse Lines for the selected lines, or the whole file. Sorting compares character codes: capitals before lower case, no numeric order.
  • Transpose swaps the characters around the caret; with several selections it rotates them.
  • Toggle Case lower-cases a selection with a capital letter in it and upper-cases any other.
  • Convert Indents › To Spaces or To Tabs, with the tab width of the file’s .editorconfig or code style.
  • Paste from History… offers the last 30 things you copied.
  • Copy Path/Reference… copies the absolute path, the file name, the path with line number, the path from the project or source root, or a reference such as shop.cart.Cart.total (Python), crate::cart::Cart::total (Rust) or shop.Cart#total (Java and Kotlin).

Code › Surround With… wraps the selection in if, while, for, try / catch and other statements in Java files only. Code › Surround with Live Template… offers two folding-region comments in any language.

⌘Z (CtrlZ) undoes one command or one run of typing, and restores every caret and selection as it was. Saving ends an undo step. A refactoring that changed several files is undone as one, from any of them: Refactor code.

Keyboard of
ActionShortcut
Code › Comment with Block Comment⌥⌘/ or ⌥⌘Numpad / or ⌃⇧/ or ⌃⇧Numpad / or ⇧⌘/ or ⇧⌘Numpad / or ⇧⌘Numpad /CtrlShift/ or CtrlShiftNumpad /
Code › Comment with Line Comment⌘/ or ⌘Numpad /Ctrl/ or CtrlNumpad /
Code › Complete Current Statement⇧⌘↩CtrlShiftEnter
Code › Move Line Down⌥⇧↓AltShift↓
Code › Move Line Up⌥⇧↑AltShift↑
Code › Move Statement Down⇧⌘↓CtrlShift↓
Code › Move Statement Up⇧⌘↑CtrlShift↑
Code › Surround With⌥⌘TCtrlAltT
Code › Unwrap/Remove⇧⌘⌦CtrlShiftDelete
Copy referenceCopyReference⌥⇧⌘CCtrlAltShiftC
Edit › Add Selection for Next Occurrence⌃GAltJ
Edit › Column Selection Mode⇧⌘8AltShiftInsert
Edit › Delete Line⌘⌫CtrlY
Edit › Duplicate Line⌘DCtrlD
Edit › Extend Selection⌥↑CtrlW
Edit › Join Lines⌃⇧JCtrlShiftJ
Edit › Paste from History⇧⌘V or ⇧⌘InsertCtrlShiftV or CtrlShiftInsert
Edit › Select All Occurrences⌃⌘GCtrlAltShiftJ
Edit › Shrink Selection⌥↓CtrlShiftW
Edit › Toggle Case⇧⌘UCtrlShiftU
Edit › Unselect Occurrence⌃⇧GAltShiftJ
Editor add caret per selected lineEditorAddCaretPerSelectedLine⌥⇧GShiftAltG
Editor match braceEditorMatchBrace⌃MCtrlShiftM
Hippie completionHippieCompletion⌥/Alt/
Move element leftMoveElementLeft⌥⇧⌘←CtrlAltShift←
Move element rightMoveElementRight⌥⇧⌘→CtrlAltShift→

editor_action and editor_keystrokes apply these commands to a copy of a file and return the result, which lets an agent see what a command would do; they write nothing.

  • editor_actionreadsPreview an editor action (see action) on a workspace file at the given carets, as the editor does it.
  • editor_keystrokesreadsPress keystrokes in an editor on a workspace file, as the editor view does: each keystroke (keymap notation such as meta shift UP, alt UP, BACK_SPACE) is looked up in the bundled default or macOS keymap and the first editor command bound to it is carried out (Editor… actions first, as in a focused editor) (caret motion, smart Home, page moves, selection stages, copy/cut/paste with whole lines, indentation, line commands, undo/redo); a step with text types it.
  • paste_historyreadsTexts copied, cut or pasted in the running Ferris IDEA window, newest first (at most 30), as Paste from History (Cmd+Shift+V / Ctrl+Shift+V) offers them: each with its number, the text and the row the popup shows.
  • preview_column_editreadsPreview a column (block) edit as an ⌥-drag selection does it: the rectangle between two corners (0-based line and column) selects the same columns on every line, lines shorter than that get a caret at their end, and the replacement is typed into each.
  • preview_multi_caret_editreadsPreview a multi-caret edit: put a caret on every occurrence of a text in a workspace file (as 'select all occurrences' does) and type the replacement at all of them.
  • surround_withchangesdry run by defaultwriteSurround With for Java: wraps whole statement lines start_line..end_line (1-based, inclusive) of a workspace .java file in kind (if, if_else, while, do_while, for, try_catch, try_finally, try_catch_finally, synchronized, runnable, braces), indenting them one step.