Skip to content

Editing Commands

All edit commands read the new code from stdin. This makes them composable with code generators, formatters, or other tools.

Replace a symbol’s entire body.

Terminal window
cat new_impl.rs | krait edit replace <symbol>

Example:

Terminal window
cat updated_service.ts | krait edit replace OrderService

The LSP locates the symbol’s exact start and end, including its closing brace. The new code from stdin replaces everything in between.

Insert code after a symbol’s closing brace.

Terminal window
echo 'fn helper() {}' | krait edit insert-after <symbol>

Insert code before a symbol’s declaration.

Terminal window
echo '#[derive(Debug)]' | krait edit insert-before MyStruct

Cross-file rename using LSP workspace/rename. Updates all references automatically.

Terminal window
krait rename <old-name> <new-name>

Apply LSP quick fixes to a file.

Terminal window
krait fix [path]

Run the LSP formatter on a file.

Terminal window
krait format <path>
Terminal window
# From a file
cat new_body.rs | krait edit replace MyStruct
# From a heredoc
krait edit replace MyStruct << 'EOF'
pub struct MyStruct {
name: String,
}
EOF
# From a command
generate-code --symbol MyStruct | krait edit replace MyStruct

Tip: Avoid echo for multi-line content — use heredoc or pipe from a file.