Skip to content

Bug: Using enew as split options has problems with resetting other winopts #2210

@srcrip

Description

@srcrip

RTFM Checklist

  • I have searched exisiting issues / discussions
  • I have read the Wiki including the Advanced section
  • I have read man fzf / I am well versed in shell fzf

Operating system

Mac

Shell

Bash

Neovim version (nvim --version)

11

Fzf version (fzf --version)

0.42.0

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

  • My issue is reproducible with mini.sh
  • My issue IS NOT reproducible with mini.sh
  • I have not tested with mini.sh (not relevant, requires LSP, Windows, etc)

Fzf-lua configuration

require("fzf-lua").setup {
  -- fzf_bin         = 'sk',            -- use skim instead of fzf?
  -- https://github.com/lotabout/skim
  global_resume = true, -- enable global `resume`?
  -- can also be sent individually:
  -- `<any_function>.({ gl ... })`
  global_resume_query = true, -- include typed query in `resume`?
  winopts = {

    -- split = "enew", -- open in a split instead?
    split = "new",
    height = 0.90, -- window height
    width = 0.85, -- window width
    -- row    = 0.35, -- window row position (0=top, 1=bottom)
    -- col    = 0.50, -- window col position (0=left, 1=right)
    -- highlights should optimally be set by the colorscheme using
    -- FzfLuaXXX highlights. If your colorscheme doesn't set these
    -- or you wish to override its defaults use these:
    --[[ hl = {
      normal         = 'Normal',        -- window normal color (fg+bg)
      border         = 'FloatBorder',   -- border color
      help_normal    = 'Normal',        -- <F1> window normal
      help_border    = 'FloatBorder',   -- <F1> window border
      -- Only used with the builtin previewer:
      cursor         = 'Cursor',        -- cursor highlight (grep/LSP matches)
      cursorline     = 'CursorLine',    -- cursor line
      cursorlinenr   = 'CursorLineNr',  -- cursor line number
      search         = 'IncSearch',     -- search matches (ctags|help)
      title          = 'Normal',        -- preview border title (file/buffer)
      -- Only used with 'winopts.preview.scrollbar = 'float'
      scrollfloat_e  = 'PmenuSbar',     -- scrollbar "empty" section highlight
      scrollfloat_f  = 'PmenuThumb',    -- scrollbar "full" section highlight
      -- Only used with 'winopts.preview.scrollbar = 'border'
      scrollborder_e = 'FloatBorder',   -- scrollbar "empty" section highlight
      scrollborder_f = 'FloatBorder',   -- scrollbar "full" section highlight
    }, ]]
    -- border     = false,
    backdrop = 100,
    -- fullscreen = true,            -- start fullscreen?
    preview = {
      default = "bat", -- override the default previewer?
      -- default uses the 'builtin' previewer
      border = "border", -- border|noborder, applies only to
      -- native fzf previewers (bat/cat/git/etc)
      wrap = "nowrap", -- wrap|nowrap
      hidden = "nohidden", -- hidden|nohidden
      vertical = "up:40%", -- up|down:size
      horizontal = "right:40%", -- right|left:size
      layout = "vertical", -- horizontal|vertical|flex
      flip_columns = 120, -- #cols to switch to horizontal on flex
      -- Only used with the builtin previewer:
      title = true, -- preview border title (file/buf)?
      title_pos = "left", -- left|center|right, title alignment
      scrollbar = "float", -- `false` or string:'float|border'
      -- float:  in-window floating border
      -- border: in-border chars (see below)
      scrolloff = "-2", -- float scrollbar offset from right
      -- applies only when scrollbar = 'float'
      scrollchars = { "", "" }, -- scrollbar chars ({ <full>, <empty> }
      -- applies only when scrollbar = 'border'
      delay = 100, -- delay(ms) displaying the preview
      -- prevents lag on fast scrolling
      winopts = { -- builtin previewer window options
        number = true,
        relativenumber = false,
        cursorline = true,
        cursorlineopt = "both",
        cursorcolumn = false,
        signcolumn = "no",
        list = false,
        foldenable = false,
        foldmethod = "manual",
      },
    },
    on_create = function()
      -- called once upon creation of the fzf main window
      -- can be used to add custom fzf-lua mappings, e.g:
      --   vim.api.nvim_buf_set_keymap(0, "t", "<C-j>", "<Down>",
      --     { silent = true, noremap = true })
    end,
  },
  keymap = {
    builtin = {
      ["<c-n>"] = "preview-page-down",
      ["<c-p>"] = "preview-page-up",
    },
    fzf = {
      -- Only valid with fzf previewers (bat/cat/git/etc)
      ["ctrl-w"] = "toggle-preview-wrap",
      ["ctrl-space"] = "toggle-preview",
      ["ctrl-n"] = "preview-page-down",
      ["ctrl-p"] = "preview-page-up",
    },
  },
  fzf_opts = {
    ["--ansi"] = "",
    ["--info"] = "default",
    ["--height"] = "100%",
    ["--layout"] = "default",
    ["--border"] = "none",
  },
  fzf_colors = {
    ["fg"] = { "fg", "Normal" },
    ["bg"] = { "bg", "Normal" },
    ["hl"] = { "fg", "Comment" },
    ["fg+"] = { "fg", "CursorLine" },
    ["bg+"] = { "bg", "Normal" },
    ["hl+"] = { "fg", "Statement" },
    ["info"] = { "fg", "PreProc" },
    ["border"] = { "fg", "Ignore" },
    ["prompt"] = { "fg", "Conditional" },
    ["pointer"] = { "fg", "Exception" },
    ["marker"] = { "fg", "Keyword" },
    ["spinner"] = { "fg", "Label" },
    ["header"] = { "fg", "Comment" },
  },
  previewers = {
    cat = {
      cmd = "cat",
      args = "--number",
    },
    bat = {
      cmd = "bat",
      args = "--style=changes --color always",
      config = nil, -- nil uses $BAT_CONFIG_PATH
    },
    head = {
      cmd = "head",
      args = nil,
    },
    git_diff = {
      cmd_deleted = "git diff --color HEAD --",
      cmd_modified = "git diff --color HEAD",
      cmd_untracked = "git diff --color --no-index /dev/null",
      -- uncomment if you wish to use git-delta as pager
      -- can also be set under 'git.status.preview_pager'
      -- pager        = "delta --width=$FZF_PREVIEW_COLUMNS",
    },
    man = {
      -- NOTE: remove the `-c` flag when using man-db
      cmd = "man -c %s | col -bx",
    },
    builtin = {
      syntax = true, -- preview syntax highlight?
      syntax_limit_l = 0, -- syntax limit (lines), 0=nolimit
      syntax_limit_b = 1024 * 1024, -- syntax limit (bytes), 0=nolimit
      limit_b = 1024 * 1024 * 10, -- preview limit (bytes), 0=nolimit
      -- preview extensions using a custom shell command:
      -- for example, use `viu` for image previews
      -- will do nothing if `viu` isn't executable
      extensions = {
        -- neovim terminal only supports `viu` block output
        ["png"] = { "viu", "-b" },
        ["jpg"] = { "ueberzug" },
      },
      -- if using `ueberzug` in the above extensions map
      -- set the default image scaler, possible scalers:
      --   false (none), "crop", "distort", "fit_contain",
      --   "contain", "forced_cover", "cover"
      -- https://github.com/seebye/ueberzug
      ueberzug_scaler = "cover",
    },
  },
  -- provider setup
  files = {
    -- previewer      = "bat",          -- uncomment to override previewer
    -- (name from 'previewers' table)
    -- set to 'false' to disable
    prompt = "Files❯ ",
    multiprocess = true, -- run command in a separate process
    git_icons = true, -- show git icons?
    file_icons = true, -- show file icons?
    color_icons = true, -- colorize file|git icons
    -- executed command priority is 'cmd' (if exists)
    -- otherwise auto-detect prioritizes `fd`:`rg`:`find`
    -- default options are controlled by 'fd|rg|find|_opts'
    -- NOTE: 'find -printf' requires GNU find
    -- cmd            = "find . -type f -printf '%P\n'",
    find_opts = [[-type f -not -path '*/\.git/*' -printf '%P\n']],
    rg_opts = "--color=never --files --hidden --follow -g '!.git'",
    fd_opts = "--color=never --type f --hidden --follow --exclude .git",
    actions = {
      -- inherits from 'actions.files', here we can override
      -- or set bind to 'false' to disable a default action
      -- ["default"] = actions.file_edit,
      -- custom actions are available too
      ["ctrl-y"] = function(selected)
        print(selected[1])
      end,
      -- `file_edit_or_qf` opens a single selection or sends multiple selection to quickfix
      -- replace `enter` with `file_edit` to open all files/bufs whether single or multiple
      -- replace `enter` with `file_switch_or_edit` to attempt a switch in current tab first
      -- ["default"] = actions.file_edit,
      -- ["esc"]     = function()
      --   -- call nvim_win_close
      --   vim.api.nvim_win_close(0, true)
      -- end
      -- ["default"] = actions.file_switch_or_edit
      ["default"] = actions.file_edit,
      -- ["default"] = { fn = actions.file_edit, noclose = true }
    },
  },
  git = {
    files = {
      prompt = "GitFiles❯ ",
      cmd = "git ls-files --exclude-standard",
      multiprocess = true, -- run command in a separate process
      git_icons = true, -- show git icons?
      file_icons = true, -- show file icons?
      color_icons = true, -- colorize file|git icons
      -- force display the cwd header line regardles of your current working
      -- directory can also be used to hide the header when not wanted
      -- show_cwd_header = true
    },
    status = {
      prompt = "GitStatus❯ ",
      -- consider using `git status -su` if you wish to see
      -- untracked files individually under their subfolders
      cmd = "git status -s",
      file_icons = true,
      git_icons = true,
      color_icons = true,
      previewer = "git_diff",
      -- uncomment if you wish to use git-delta as pager
      --preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
      actions = {
        -- actions inherit from 'actions.files' and merge
        ["right"] = { actions.git_unstage, actions.resume },
        ["left"] = { actions.git_stage, actions.resume },
      },
    },
    commits = {
      prompt = "Commits❯ ",
      cmd = "git log --color --pretty=format:'%C(yellow)%h%Creset %Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset'",
      preview = "git show --pretty='%Cred%H%n%Cblue%an <%ae>%n%C(yellow)%cD%n%Cgreen%s' --color {1}",
      -- uncomment if you wish to use git-delta as pager
      --preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
      actions = {
        ["default"] = actions.git_checkout,
      },
    },
    bcommits = {
      prompt = "BCommits❯ ",
      -- default preview shows a git diff vs the previous commit
      -- if you prefer to see the entire commit you can use:
      --   git show --color {1} --rotate-to=<file>
      --   {1}    : commit SHA (fzf field index expression)
      --   <file> : filepath placement within the commands
      cmd = "git log --color --pretty=format:'%C(yellow)%h%Creset %Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset' <file>",
      preview = "git diff --color {1}~1 {1} -- <file>",
      -- uncomment if you wish to use git-delta as pager
      --preview_pager = "delta --width=$FZF_PREVIEW_COLUMNS",
      actions = {
        ["default"] = actions.git_buf_edit,
        ["ctrl-s"] = actions.git_buf_split,
        ["ctrl-v"] = actions.git_buf_vsplit,
        ["ctrl-t"] = actions.git_buf_tabedit,
      },
    },
    branches = {
      prompt = "Branches❯ ",
      cmd = "git branch --all --color",
      preview = "git log --graph --pretty=oneline --abbrev-commit --color {1}",
      actions = {
        ["default"] = actions.git_switch,
      },
    },
    stash = {
      prompt = "Stash> ",
      cmd = "git --no-pager stash list",
      preview = "git --no-pager stash show --patch --color {1}",
      actions = {
        ["default"] = actions.git_stash_apply,
        ["ctrl-x"] = { actions.git_stash_drop, actions.resume },
      },
      fzf_opts = {
        ["--no-multi"] = "",
        ["--delimiter"] = "'[:]'",
      },
    },
    icons = {
      ["M"] = { icon = "M", color = "yellow" },
      ["D"] = { icon = "D", color = "red" },
      ["A"] = { icon = "A", color = "green" },
      ["R"] = { icon = "R", color = "yellow" },
      ["C"] = { icon = "C", color = "yellow" },
      ["T"] = { icon = "T", color = "magenta" },
      ["?"] = { icon = "?", color = "magenta" },
      -- override git icons?
      -- ["M"]        = { icon = "★", color = "red" },
      -- ["D"]        = { icon = "✗", color = "red" },
      -- ["A"]        = { icon = "+", color = "green" },
    },
  },
  grep = {
    prompt = "Rg❯ ",
    input_prompt = "Grep For❯ ",
    multiprocess = true, -- run command in a separate process
    git_icons = true, -- show git icons?
    file_icons = true, -- show file icons?
    color_icons = true, -- colorize file|git icons
    -- executed command priority is 'cmd' (if exists)
    -- otherwise auto-detect prioritizes `rg` over `grep`
    -- default options are controlled by 'rg|grep_opts'
    -- cmd            = "rg --vimgrep",
    grep_opts = "--binary-files=without-match --line-number --recursive --color=auto --perl-regexp",
    rg_opts = "--column --line-number --no-heading --color=always --smart-case --max-columns=512",
    -- set to 'true' to always parse globs in both 'grep' and 'live_grep'
    -- search strings will be split using the 'glob_separator' and translated
    -- to '--iglob=' arguments, requires 'rg'
    -- can still be used when 'false' by calling 'live_grep_glob' directly
    rg_glob = false, -- default to glob parsing?
    glob_flag = "--iglob", -- for case sensitive globs use '--glob'
    glob_separator = "%s%-%-", -- query separator pattern (lua): ' --'
    -- advanced usage: for custom argument parsing define
    -- 'rg_glob_fn' to return a pair:
    --   first returned argument is the new search query
    --   second returned argument are addtional rg flags
    -- rg_glob_fn = function(query, opts)
    --   ...
    --   return new_query, flags
    -- end,
    actions = {
      -- actions inherit from 'actions.files' and merge
      -- this action toggles between 'grep' and 'live_grep'
      ["ctrl-g"] = { actions.grep_lgrep },
    },
    no_header = false, -- hide grep|cwd header?
    no_header_i = false, -- hide interactive header?
  },
  args = {
    prompt = "Args❯ ",
    files_only = true,
    -- actions inherit from 'actions.files' and merge
    actions = { ["ctrl-x"] = { actions.arg_del, actions.resume } },
  },
  oldfiles = {
    prompt = "History❯ ",
    cwd_only = false,
    stat_file = true, -- verify files exist on disk
    include_current_session = false, -- include bufs from current session
  },
  buffers = {
    prompt = "Buffers❯ ",
    file_icons = true, -- show file icons?
    color_icons = true, -- colorize file|git icons
    sort_lastused = true, -- sort buffers() by last used
    actions = {
      -- actions inherit from 'actions.buffers' and merge
      -- by supplying a table of functions we're telling
      -- fzf-lua to not close the fzf window, this way we
      -- can resume the buffers picker on the same window
      -- eliminating an otherwise unaesthetic win "flash"
      ["ctrl-x"] = { actions.buf_del, actions.resume },
    },
  },
  tabs = {
    prompt = "Tabs❯ ",
    tab_title = "Tab",
    tab_marker = "<<",
    file_icons = true, -- show file icons?
    color_icons = true, -- colorize file|git icons
    actions = {
      -- actions inherit from 'actions.buffers' and merge
      ["default"] = actions.buf_switch,
      ["ctrl-x"] = { actions.buf_del, actions.resume },
    },
    fzf_opts = {
      -- hide tabnr
      ["--delimiter"] = "'[\\):]'",
      ["--with-nth"] = "2..",
    },
  },
  lines = {
    previewer = "builtin", -- set to 'false' to disable
    prompt = "Lines❯ ",
    show_unlisted = false, -- exclude 'help' buffers
    no_term_buffers = true, -- exclude 'term' buffers
    fzf_opts = {
      -- do not include bufnr in fuzzy matching
      -- tiebreak by line no.
      ["--delimiter"] = "'[\\]:]'",
      ["--nth"] = "2..",
      ["--tiebreak"] = "index",
    },
    -- actions inherit from 'actions.buffers' and merge
    actions = {
      ["default"] = actions.buf_edit_or_qf,
      ["alt-q"] = actions.buf_sel_to_qf,
      ["alt-l"] = actions.buf_sel_to_ll,
    },
  },
  blines = {
    previewer = "builtin", -- set to 'false' to disable
    prompt = "BLines❯ ",
    show_unlisted = true, -- include 'help' buffers
    no_term_buffers = false, -- include 'term' buffers
    fzf_opts = {
      -- hide filename, tiebreak by line no.
      ["--delimiter"] = "'[\\]:]'",
      ["--with-nth"] = "2..",
      ["--tiebreak"] = "index",
    },
    -- actions inherit from 'actions.buffers' and merge
    actions = {
      ["default"] = actions.buf_edit_or_qf,
      ["alt-q"] = actions.buf_sel_to_qf,
      ["alt-l"] = actions.buf_sel_to_ll,
    },
  },
  tags = {
    prompt = "Tags❯ ",
    ctags_file = "tags",
    multiprocess = true,
    file_icons = true,
    git_icons = true,
    color_icons = true,
    -- 'tags_live_grep' options, `rg` prioritizes over `grep`
    rg_opts = "--no-heading --color=always --smart-case",
    grep_opts = "--color=auto --perl-regexp",
    actions = {
      -- actions inherit from 'actions.files' and merge
      -- this action toggles between 'grep' and 'live_grep'
      ["ctrl-g"] = { actions.grep_lgrep },
    },
    no_header = false, -- hide grep|cwd header?
    no_header_i = false, -- hide interactive header?
  },
  btags = {
    prompt = "BTags❯ ",
    ctags_file = "tags",
    ctags_autogen = false, -- dynamically generate ctags each call
    multiprocess = true,
    file_icons = true,
    git_icons = true,
    color_icons = true,
    rg_opts = "--no-heading --color=always",
    grep_opts = "--color=auto --perl-regexp",
    fzf_opts = {
      ["--delimiter"] = "'[\\]:]'",
      ["--with-nth"] = "2..",
      ["--tiebreak"] = "index",
    },
    -- actions inherit from 'actions.files'
  },
  colorschemes = {
    prompt = "Colorschemes❯ ",
    live_preview = true, -- apply the colorscheme on preview?
    actions = { ["default"] = actions.colorscheme },
    winopts = { height = 0.55, width = 0.30 },
    post_reset_cb = function()
      -- reset statusline highlights after
      -- a live_preview of the colorscheme
      -- require('feline').reset_highlights()
    end,
  },
  quickfix = {
    file_icons = true,
    git_icons = true,
  },
  lsp = {
    prompt_postfix = "", -- will be appended to the LSP label
    -- to override use 'prompt' instead
    cwd_only = false, -- LSP/diagnostics for cwd only?
    async_or_timeout = 5000, -- timeout(ms) or 'true' for async calls
    file_icons = true,
    git_icons = false,
    -- settings for 'lsp_{document|workspace|lsp_live_workspace}_symbols'
    symbols = {
      async_or_timeout = true, -- symbols are async by default
      symbol_style = 1, -- style for document/workspace symbols
      -- false: disable,    1: icon+kind
      --     2: icon only,  3: kind only
      -- NOTE: icons are extracted from
      -- vim.lsp.protocol.CompletionItemKind
      -- colorize using nvim-cmp's CmpItemKindXXX highlights
      -- can also be set to 'TS' for treesitter highlights ('TSProperty', etc)
      -- or 'false' to disable highlighting
      symbol_hl_prefix = "CmpItemKind",
      -- additional symbol formatting, works with or without style
      symbol_fmt = function(s)
        return "[" .. s .. "]"
      end,
    },
    code_actions = {
      prompt = "Code Actions> ",
      ui_select = true, -- use 'vim.ui.select'?
      async_or_timeout = 5000,
      winopts = {
        row = 0.40,
        height = 0.35,
        width = 0.60,
      },
    },
  },
  diagnostics = {
    prompt = "Diagnostics❯ ",
    cwd_only = false,
    file_icons = true,
    git_icons = false,
    diag_icons = true,
    icon_padding = "", -- add padding for wide diagnostics signs
    -- by default icons and highlights are extracted from 'DiagnosticSignXXX'
    -- and highlighted by a highlight group of the same name (which is usually
    -- set by your colorscheme, for more info see:
    --   :help DiagnosticSignHint'
    --   :help hl-DiagnosticSignHint'
    -- only uncomment below if you wish to override the signs/highlights
    -- define only text, texthl or both (':help sign_define()' for more info)
    -- signs = {
    --   ["Error"] = { text = "", texthl = "DiagnosticError" },
    --   ["Warn"]  = { text = "", texthl = "DiagnosticWarn" },
    --   ["Info"]  = { text = "", texthl = "DiagnosticInfo" },
    --   ["Hint"]  = { text = "", texthl = "DiagnosticHint" },
    -- },
    -- limit to specific severity, use either a string or num:
    --   1 or "hint"
    --   2 or "information"
    --   3 or "warning"
    --   4 or "error"
    -- severity_only:   keep any matching exact severity
    -- severity_limit:  keep any equal or more severe (lower)
    -- severity_bound:  keep any equal or less severe (higher)
  },
  -- uncomment to use the old help previewer which used a
  -- minimized help window to generate the help tag preview
  -- helptags = { previewer = "help_tags" },
  -- uncomment to use `man` command as native fzf previewer
  -- (instead of using a neovim floating window)
  -- manpages = { previewer = "man_native" },
  --
  -- optional override of file extension icon colors
  -- available colors (terminal):
  --    clear, bold, black, red, green, yellow
  --    blue, magenta, cyan, grey, dark_grey, white
  file_icon_colors = {
    ["sh"] = "green",
  },
  -- padding can help kitty term users with
  -- double-width icon rendering
  file_icon_padding = "",
  -- uncomment if your terminal/font does not support unicode character
  -- 'EN SPACE' (U+2002), the below sets it to 'NBSP' (U+00A0) instead
  -- nbsp = '\xc2\xa0',
}

Describe the bug / steps to reproduce

Hi there,

enew was a really useful split option in the original fzf vim package. It makes fzf take over the current buffer.

Unfortunately if you use it with fzflua, the winopts like:

      winopts = { -- builtin previewer window options
        number = true,
        relativenumber = false,
        cursorline = true,
        cursorlineopt = "both",
        cursorcolumn = false,
        signcolumn = "no",
        list = false,
        foldenable = false,
        foldmethod = "manual",
      },

kind of 'take over' the settings of the new buffer. I can, for instance, set my fdm to indent, and then because its set to manual here, when I select a new file with fzflua, in that new buffer fdm will be set to manual.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions