Skip to content

LazyVim compatibility: C-j conflicts with window navigation in terminal mode #108

@syscode1

Description

@syscode1

Problem

When using opencode.nvim with LazyVim, the <C-j> key in terminal mode is mapped globally by LazyVim for window navigation. This prevents users from inserting a newline (LF) in the opencode terminal buffer.

Expected Behavior

<C-j> should send a newline character when inside the opencode terminal buffer, allowing users to create multi-line prompts.

Current Workaround

I've been using this workaround in my config:

-- Fix: Force <C-j> to be a newline in opencode buffers (overriding window navigation)
vim.api.nvim_create_autocmd({ "FileType", "BufEnter", "TermOpen" }, {
  pattern = "*",
  callback = function(ev)
    local ft = vim.bo[ev.buf].filetype
    local name = vim.api.nvim_buf_get_name(ev.buf)
    -- Check if it is an opencode buffer by filetype or name
    if (ft and ft:find("opencode")) or (name and name:find("opencode")) then
      vim.keymap.set("t", "<C-j>", "<C-j>", { buffer = ev.buf, nowait = true })
      vim.keymap.set("t", "<S-CR>", "<C-j>", { buffer = ev.buf, nowait = true })
      vim.keymap.set("t", "<C-CR>", "<C-j>", { buffer = ev.buf, nowait = true })
    end
  end,
})

Proposed Solutions

  1. Built-in fix: Handle this automatically in the plugin when creating the terminal buffer
  2. Documentation: Add a note in README for LazyVim users

Environment

  • Neovim version: 0.10+
  • LazyVim
  • Provider: snacks

Would love to hear your thoughts on the preferred approach!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions