**/editor command fails when VISUAL contains arguments with spaces/quotes** #4704

Open
opened 2026-02-16 17:45:07 -05:00 by yindo · 0 comments
Owner

Originally created by @ragu-manjegowda on GitHub (Jan 11, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Problem

The /editor command fails when the VISUAL environment variable contains command-line arguments with spaces or quotes. The arguments are incorrectly split, causing nvim to misinterpret them.

Environment

  • OS: Arch Linux (BTW)
  • OpenCode version: 1.0.220 (installed via Homebrew)
  • Shell: zsh

Steps to Reproduce

  1. Set VISUAL with arguments:

    export VISUAL="nvim --cmd 'let g:flatten_wait=1'"
    
  2. Start OpenCode TUI:

    opencode
    
  3. Run /editor command

Expected Behavior

Nvim opens with the --cmd 'let g:flatten_wait=1' argument properly passed, allowing the g:flatten_wait variable to be set before rc loads.

Actual Behavior

Error appears:

Error detected while processing pre-vimrc command line:
E20: Mark not set: 'let
Already only one window

Root Cause

The VISUAL variable appears to be split on spaces without proper quote handling. Instead of:

nvim --cmd 'let g:flatten_wait=1' /tmp/opencode-xxxxx

It's likely being invoked as:

nvim --cmd 'let g:flatten_wait=1' /tmp/opencode-xxxxx
       ↑
       Split here, so vim sees: --cmd "'let" "g:flatten_wait=1'"

Vim interprets 'let as a mark reference (marks start with '), hence E20: Mark not set.

Use Case

This pattern (VISUAL with --cmd or other flags) is common for:

  • flatten.nvim users who need let g:flatten_wait=1 for nested terminal support

Suggested Fix

Consider one of these approaches:

Use eval to properly handle quoted arguments:

// Instead of splitting on spaces
cmd := exec.Command("sh", "-c", editor + " " + shellescape(filepath))

Related

This is a common issue in CLI tools. Similar fixes have been implemented in:

  • ranger (uses eval ${VISUAL:-$EDITOR} -- "$@")
  • git (supports core.editor with proper argument handling)

Plugins

No response

OpenCode version

1.0.220

Steps to reproduce

export VISUAL="nvim --cmd 'let g:flatten_wait=1'"

Screenshot and/or share link

Image

Operating System

Arch Linux

Terminal

Alacritty

Originally created by @ragu-manjegowda on GitHub (Jan 11, 2026). Originally assigned to: @rekram1-node on GitHub. ## Description ### Problem The `/editor` command fails when the `VISUAL` environment variable contains command-line arguments with spaces or quotes. The arguments are incorrectly split, causing nvim to misinterpret them. ### Environment - **OS**: Arch Linux (BTW) - **OpenCode version**: 1.0.220 (installed via Homebrew) - **Shell**: zsh ### Steps to Reproduce 1. Set `VISUAL` with arguments: ```bash export VISUAL="nvim --cmd 'let g:flatten_wait=1'" ``` 2. Start OpenCode TUI: ```bash opencode ``` 3. Run `/editor` command ### Expected Behavior Nvim opens with the `--cmd 'let g:flatten_wait=1'` argument properly passed, allowing the `g:flatten_wait` variable to be set before rc loads. ### Actual Behavior Error appears: ``` Error detected while processing pre-vimrc command line: E20: Mark not set: 'let Already only one window ``` ### Root Cause The `VISUAL` variable appears to be split on spaces without proper quote handling. Instead of: ``` nvim --cmd 'let g:flatten_wait=1' /tmp/opencode-xxxxx ``` It's likely being invoked as: ``` nvim --cmd 'let g:flatten_wait=1' /tmp/opencode-xxxxx ↑ Split here, so vim sees: --cmd "'let" "g:flatten_wait=1'" ``` Vim interprets `'let` as a mark reference (marks start with `'`), hence `E20: Mark not set`. ### Use Case This pattern (`VISUAL` with `--cmd` or other flags) is common for: - **flatten.nvim** users who need `let g:flatten_wait=1` for nested terminal support ### Suggested Fix Consider one of these approaches: **Use `eval`** to properly handle quoted arguments: ```go // Instead of splitting on spaces cmd := exec.Command("sh", "-c", editor + " " + shellescape(filepath)) ``` ### Related This is a common issue in CLI tools. Similar fixes have been implemented in: - ranger (uses `eval ${VISUAL:-$EDITOR} -- "$@"`) - git (supports `core.editor` with proper argument handling) ### Plugins _No response_ ### OpenCode version 1.0.220 ### Steps to reproduce export VISUAL="nvim --cmd 'let g:flatten_wait=1'" ### Screenshot and/or share link <img width="1239" height="1215" alt="Image" src="https://github.com/user-attachments/assets/2b3b4737-89c6-4048-ab0d-8e7654f79309" /> ### Operating System Arch Linux ### Terminal Alacritty
yindo added the bug label 2026-02-16 17:45:07 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4704