Skip to content

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.

CommandAction
:w[rite][!] [file]write the JSON on screen to a file
:w[rite] !cmdpipe 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:

txt
:42

Press 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:

txt
: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_INDENT setting.
  • 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 :w saves 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 -i or console.log output of a query, are left out.

On success, the command line shows the file name and its size:

txt
"result.json" 12L, 340B written

Fx 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:

  • :w with a query applied asks Overwrite "users.json" with the query result? (y/n), because the result replaces your input.
  • :w other.json asks "other.json" exists, overwrite? (y/n) when the file exists.

Press y to confirm. Any other key cancels. Add ! to skip the question:

txt
:w! other.json

When fx Refuses to Write ​

Fx never writes a file it can't write completely. The command line tells you why:

MessageCause and what to do
No file namethe input came from stdin, so give a file name: :w out.json
Input is still loadingwait for the stream to end
Query is still runningwait 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 errorsfix the query
Input contains text that is not JSONthe text would be lost, so pipe in JSON only, for example curl without -i
Nothing to writethere is no JSON on screen
Can't write JSON over "config.yaml", write to another filefx 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:

txt
:w !code -
:w !vim -
:w !less
:w !jq -c . | less
:w !curl -d @- https://example.com/api

Note 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:

txt
"!less" 12L, 340B written

When the command fails, the command line shows its exit code:

txt
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.

txt
:wq
txt
:wq! result.json

Quit ​

:q quits, like q does.