Refactoring in Skink: rename, move, extract, safe delete
Press Alt+Shift+R to rename the symbol at the cursor everywhere. Any change that touches several files opens the refactor preview first, so you check it before anything is applied.
Other refactors are commands:
:mvmoves a file and updates its imports.:extract varor:extract fnpulls out the selection.:safedeleteremoves a declaration nobody uses.
Most of these use your language server. See Code intelligence for setup.
The refactor preview
Section titled “The refactor preview”The preview lists the files and hunks a change will touch, each with a checkbox, and a side-by-side diff of the selected one.
| Key | Does |
|---|---|
| ↑ / ↓ | Move between files and hunks |
| Space | Check or uncheck |
| a | Check all |
| n | Check none |
| Enter | Apply the checked changes |
| Esc | Cancel |
Applying is one undo step per file. The changed files are left unsaved, so you get a last look and save them yourself.
The same preview is used for:
- rename and multi-file code actions
- file moves
- project-wide replace (
:greprep) and structural rewrite (:srep) - edits from AI agents
Rename a symbol
Section titled “Rename a symbol”Alt+Shift+R asks for the new name. Or give it straight away:
:renamesymbol new_name:rn new_nameThe language server finds every real use, across files, so unrelated names that happen to match are left alone.
Move or rename a file
Section titled “Move or rename a file”:mv src/util/strings.rsThis moves or renames the current file, relative to the project root. Open tabs follow the file.
Running language servers are asked first (workspace/willRenameFiles). The import and module-path changes they suggest open in the preview.
Renaming in the file tree (r or F2 on a file) does the same. New folders in the path are created for you.
Extract a variable or function
Section titled “Extract a variable or function”Select an expression or some lines, then run one of:
:extract var [NAME]:extract fn [NAME]This uses the language server’s extract code action. extract var also works without a server for Rust, TypeScript/JavaScript and Python.
Safe delete
Section titled “Safe delete”Put the cursor on a function, struct or class and run :safedelete. Skink runs find-references first:
- No uses outside the declaration: the declaration, with its doc comments and attributes, is removed through the preview.
- Uses found: they are listed instead, so you can deal with them first.
:safedelete! skips the check and opens the deletion in the preview unchecked, for you to decide.
Code actions
Section titled “Code actions”Alt+Enter (or :fix) shows the server’s quick fixes and refactorings for the cursor position, such as “add missing import” or “inline variable”.
A lightbulb in the sign column means some are available. Ones that touch several files open the preview.
Structural search and replace
Section titled “Structural search and replace”For changes by shape rather than by name, use ast-grep patterns:
:sgrep foo($A, $$$REST):srep foo($A, $B) => bar($B, $A):srep rewrites every match through the preview. See Project search.
Smaller edits in one file
Section titled “Smaller edits in one file”| Key | Typed command | Does |
|---|---|---|
| Alt+O / Alt+I | :expand / :contract |
Grow / shrink the selection to the enclosing syntax node |
| Alt+↑ / Alt+↓ | :moveup / :movedown |
Move lines |
| Ctrl+D | :addcursor |
Multiple cursors on the next match (more) |
:SortLines, :JoinLines |
Sort or join the selected lines | |
:UpperCase, :LowerCase, :TitleCase |
Change case of the selection or word |
Every key also has a typed command. See Typed commands.