Google Docs Editing
read_when:
- Editing Google Docs content, tabs, formatting, comments, or raw Docs output.
- Reviewing Docs write, format, find-replace, or tab commands.
Docs commands cover document creation, export, content writes, find/replace, comments, tabs, formatting, and raw API inspection.
#Write Markdown
Append Markdown and convert it to Google Docs formatting:
gog docs write <docId> --append --markdown --text '## Status'
Replace the document body with Markdown from a file:
gog docs write <docId> --replace --markdown --content-file README.md
Command pages:
#Format Text
Apply text or paragraph formatting:
gog docs format <docId> --match Status --bold --font-size 18
gog docs format <docId> --match "Action item" --text-color '#b00020'
gog docs format <docId> --match Heading --alignment center --line-spacing 120
Promote an existing paragraph to a heading or title style with --heading-level N (1..6 shortcut) or --named-style NAME (full enum: NORMAL_TEXT, TITLE, SUBTITLE, HEADING_1..HEADING_6, case-insensitive). Both set paragraphStyle.namedStyleType on the same update so they compose with --alignment and --line-spacing:
gog docs format <docId> --match "Status" --heading-level 2
gog docs format <docId> --match "Overview" --named-style title --alignment center
Use --match-all when every occurrence should be formatted.
Command page:
#Page Breaks
Markdown has no native page-break construct, so multi-page deliverables need a direct Docs API call. Insert a page break at a specific index or append one at end-of-doc:
gog docs insert-page-break <docId> --at-end
gog docs insert-page-break <docId> --index 250 --tab "Notes"
--index and --at-end are mutually exclusive; omit both to default to end-of-doc. Aliases: page-break, pb.
Command page:
#Page Layout
Set an existing document to pageless or paged mode:
gog docs page-layout <docId> --layout pageless
gog docs page-layout <docId> --layout pages
Use explicit page size and margin flags when the output width matters:
gog docs page-layout <docId> --page-width 960
gog docs page-layout <docId> --layout pages --page-width 8.5in --page-height 11in \
--margin-left 0.5in --margin-right 0.5in
gog docs write <docId> --replace --markdown --file report.md --pageless --page-width 960
Lengths default to points and also accept pt, in, cm, or mm. docs page-layout preserves the current page mode when only size or margin flags are supplied; pass --layout when you also want to toggle pageless/pages. --pageless preserves Google Docs' existing width unless --page-width is set explicitly.
Command page:
#Tables
Insert a native Google Docs table directly via the Docs API, bypassing the Markdown writer:
gog docs insert-table <docId> --rows 3 --cols 2 --at-end
gog docs insert-table <docId> --rows 2 --cols 2 --index 1 \
--values-json '[["A","B"],["C","D"]]'
--values-json takes a JSON 2D string array whose dimensions must match --rowsx--cols; omit it to insert an empty table structure. Use --at-end to append at the end of the document (or the selected --tab), or --index N to insert at a specific document index. Prefer this primitive when you want a guaranteed native table rather than relying on the Markdown writer's table rendering (see gog docs write --markdown).
Command page:
#Tabs
Manage Google Docs tabs:
gog docs list-tabs <docId>
gog docs add-tab <docId> --title "Notes"
gog docs rename-tab <docId> <tabId> "Archive"
gog docs delete-tab <docId> <tabId> --force
Tab-aware commands accept --tab by title or ID:
gog docs write <docId> --append --tab "Notes" --text "Follow-up"
gog docs find-replace <docId> old new --tab "Notes" --dry-run
Re-render an entire tab from a markdown source-of-truth file with --replace --markdown --tab:
gog docs write <docId> --replace --markdown --tab "Gold list" --file gold.md
Drive's markdown converter is whole-document-only, so this path wipes the targeted tab's content via DeleteContentRange and re-renders the markdown locally through the Docs API. Other tabs are untouched.
Command pages:
#Find and Replace
gog docs find-replace <docId> old new --dry-run
gog docs find-replace <docId> old '' --first
gog docs find-replace <docId> PLACEHOLDER --content-file replacement.md --format markdown
--dry-run is fully offline and reports the intended replacement without opening the document. Empty replacement strings are allowed and delete matches.
Command page:
#Raw Docs Output
Use raw output when a script needs the Google Docs API object:
gog docs raw <docId> --pretty
See Raw API Dumps for lossless-output safety notes.