Commands
Press : to open the command line at the bottom of the viewer, type a command, and press enter. Press esc to close it without running anything.
| Command | Action |
|---|---|
:w[rite][!] [file] | write the JSON on screen to a file |
:w[rite] !cmd | pipe the JSON on screen to a shell command |
:wq[!] [file] | write the JSON on screen to a file and quit |
:q[uit] | quit |
:<n> | go to line n |
Type any prefix of a command name: :w, :wr, and :write all write. Add ! to skip a confirmation.
Fx shows the outcome of a command in the command line until you press the next key. An unknown command shows Not an editor command.
TIP
Press ? to see the commands and key bindings inside fx.
Go to a Line
Type a number to move the cursor to that line:
:42Press s l to show line numbers, or set FX_LINE_NUMBERS to show them always. A number past the last line moves to the last line. A number below one moves to the first line. When the line is inside a collapsed node, fx expands the node to reach it.
Press [ to jump back to where you were before.
Write to a File
:w writes the JSON on screen back to the input file. Give a file name to write somewhere else:
:w result.json~ expands to your home directory, so :w ~/result.json works.
Fx writes what you see, with a few rules:
- Fx writes the whole document, collapsed parts included, and indents it with two spaces or your
FX_INDENTsetting. - Several documents, as in JSON Lines input, are written one per line, so the file keeps its format.
- Deleted nodes stay deleted. Move to a node, press d d to delete it, and
:wsaves the file without it. - When a query is applied, fx writes the result, not the original input.
- Lines that are not JSON, such as HTTP headers from
curl -iorconsole.logoutput of a query, are left out.
On success, the command line shows the file name and its size:
"result.json" 12L, 340B writtenFx writes to a temporary file in the same directory and renames it over the target, so a failure never leaves a half-written file. Permissions of an existing file are kept.
Confirmations
Fx asks before it overwrites something you might not expect:
:wwith a query applied asksOverwrite "users.json" with the query result? (y/n), because the result replaces your input.:w other.jsonasks"other.json" exists, overwrite? (y/n)when the file exists.
Press y to confirm. Any other key cancels. Add ! to skip the question:
:w! other.jsonWhen fx Refuses to Write
Fx never writes a file it can't write completely. The command line tells you why:
| Message | Cause and what to do |
|---|---|
No file name | the input came from stdin, so give a file name: :w out.json |
Input is still loading | wait for the stream to end |
Query is still running | wait for the query to finish, or press . esc |
Input has errors: ... | fix the input first, writing would drop everything after the error |
Query result has errors | fix the query |
Input contains text that is not JSON | the text would be lost, so pipe in JSON only, for example curl without -i |
Nothing to write | there is no JSON on screen |
Can't write JSON over "config.yaml", write to another file | fx writes JSON only, so YAML, TOML, MAML, and --raw inputs need another file: :w config.json |
Pipe to a Program
:w !cmd pipes the JSON on screen to the standard input of a shell command instead of writing a file, as in Vim. Open it in an editor, page through it, or hand it to another tool:
:w !code -
:w !vim -
:w !less
:w !jq -c . | less
:w !curl -d @- https://example.com/apiNote the space before !: :w!less is a forced write to a file named less.
The command runs in your shell, $SHELL or cmd on Windows, so quotes and pipes work. It takes over the terminal while it runs, and fx comes back when it exits. Pagers and editors read the JSON from stdin and still take their keys from the terminal.
Fx pipes exactly what :w would write: the whole document with its collapsed parts, without deleted nodes, and the result when a query is applied. The same refusals apply. Nothing is overwritten, so fx never asks for a confirmation.
On success, the command line shows the command and the size of what was piped:
"!less" 12L, 340B writtenWhen the command fails, the command line shows its exit code:
shell returned 1:wq !cmd pipes, then quits once the command succeeds.
Write and Quit
:wq writes and then quits. When the write fails, or you answer n to a confirmation, fx stays open.
:wq:wq! result.jsonQuit
:q quits, like q does.