Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: select into window on the right #466

Open
1 task done
onexbash opened this issue Aug 22, 2024 · 1 comment
Open
1 task done

feature request: select into window on the right #466

onexbash opened this issue Aug 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@onexbash
Copy link

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

Hi all,
I added a keymap that always opens Oil in a vertical split on the left. Now I want to open the selected buffer in the next split to the right and create a new split if there is none.
I know that I can pass vertical = true to oil.select() but unfortunately it doesnt check if there already is an open split on the right.
Is it possible to achieve this?

This screenshot shows my config + the opening behaviour with oil on the left site:
CleanShot 2024-08-22 at 13 08 28

Provide background

I'm trying to have a similar experience to NvimTree in Oil.

What is the significance of this feature?

cannot use this plugin without it

Additional details

No response

@onexbash onexbash added the enhancement New feature or request label Aug 22, 2024
@matu3ba
Copy link

matu3ba commented Aug 22, 2024

Layouting stuff has unbounded complexity and you can code your own split behavior, so from my point of view, this does not belong into the plugin.

You can script your own solution with something like

local has_oil, oil = pcall(require, 'oil')
local has_myoil, myoil = pcall(require, 'my_oil')
if has_oil then
  assert(has_myoil)
  add_cmd('ODabs', function() setPlusAnd0Register(oil.get_current_dir()) end, {})
  add_cmd('ODrel', function() setPlusAnd0Register('.' .. sep .. plenary.path:new(oil.get_current_dir()):make_relative() .. sep) end, {})
  add_cmd('OFabs', function() setPlusAnd0Register(oil.get_current_dir() .. oil.get_cursor_entry().parsed_name) end, {})
  add_cmd('OFrel', function() setPlusAnd0Register('.' .. sep .. plenary.path:new(oil.get_current_dir()):make_relative() .. sep .. oil.get_cursor_entry().parsed_name) end, {})
end

and keep track of your window layouts with positions and splits yourself.
Vim and Neovim unfortunately offer no API for sane window positioning and the session file neither looks great (a bunch of hard to decipher splits with vimscript).

Some more code to reuse

add_cmd('PrintAllWinOptions', function()
  local win_number = api.nvim_get_current_win()
  local v = vim.wo[win_number]
  local all_options = api.nvim_get_all_options_info()
  local result = ''
  for key, val in pairs(all_options) do
    if val.global_local == false and val.scope == 'win' then result = result .. '|' .. key .. '=' .. tostring(v[key] or '<not set>') end
  end
  print(result)
end, {})

-- uv.tty_get_winsize() for terminal window size
-- Note: The conversion froom vim.fn.getwininfo looks abit broken with sigla table entries.
add_cmd('PrintAllTabInfos', function()
  local windows = api.nvim_tabpage_list_wins(0)
  local reg_wins = {}
  local i = 1
  for _, win in pairs(windows) do
    local cfg = vim.api.nvim_win_get_config(win) -- see nvim_open_win()
    -- check for absence of floating window
    if cfg.relative == '' then
      reg_wins[i] = {}
      local curwin_infos = vim.fn.getwininfo(win)
      -- reg_wins[i]["loclist"] = curwin_infos[1]["loclist"] -- unused
      -- reg_wins[i]["quickfix"] = curwin_infos[1]["quickfix"] -- unused
      -- reg_wins[i]["terminal"] = curwin_infos[1]["terminal"] --unused
      -- reg_wins[i]["topline"] = curwin_infos[1]["topline"] --unused
      -- reg_wins[i]["winbar"] = curwin_infos[1]["winbar"] -- unused
      reg_wins[i]['botline'] = curwin_infos[1]['botline'] -- botmost screen line
      reg_wins[i]['bufnr'] = curwin_infos[1]['bufnr'] -- buffer number
      reg_wins[i]['height'] = curwin_infos[1]['height'] -- window height excluding winbar
      reg_wins[i]['tabnr'] = curwin_infos[1]['tabnr']
      reg_wins[i]['textoff'] = curwin_infos[1]['textoff'] -- foldcolumn, signcolumn etc width
      reg_wins[i]['variables'] = curwin_infos[1]['variables'] --unused
      reg_wins[i]['width'] = curwin_infos[1]['width'] -- width (textoff to derive rightmost screen column)
      reg_wins[i]['wincol'] = curwin_infos[1]['wincol'] -- leftmost screen column of window
      reg_wins[i]['winid'] = curwin_infos[1]['winid']
      reg_wins[i]['winnr'] = curwin_infos[1]['winnr']
      reg_wins[i]['winrow'] = curwin_infos[1]['winrow'] -- topmost screen line

      -- included with offset + 1 in winrow, wincol
      local winpos = api.nvim_win_get_position(win) -- top left corner of window
      reg_wins[i]['row'] = winpos[1]
      reg_wins[i]['col'] = winpos[2]

      i = i + 1
    end
  end
  print(vim.inspect(reg_wins))
end, {})

add_cmd('PrintBuffersWithProperties', function()
  local bufprops = {}
  local bufs = api.nvim_list_bufs()
  -- local buf_loaded = nvim_buf_is_loaded()
  for _, v in ipairs(bufs) do
    local name = api.nvim_buf_get_name(v)
    local is_loaded = api.nvim_buf_is_loaded(v)
    local ty = vim.bo[v].buftype
    local is_ro = vim.bo[v].readonly
    local is_hidden = vim.bo[v].bufhidden
    local is_listed = vim.bo[v].buflisted
    -- print( i, ', ', v, 'name:', name, 'loaded:', is_loaded, 'ty:', ty, 'ro:', is_ro, 'is_hidden:', is_hidden, 'is_listed:', is_listed)
    -- readonly, bufhidden, buflisted
    local row = { name, is_loaded, ty, is_ro, is_hidden, is_listed }
    bufprops[v] = row
  end
  for i, v in pairs(bufprops) do
    print(i, ', ', vim.inspect(v))
  end
  return bufprops
end, {})

-- Note: There may be options arguments added with dash or dashdash.
add_cmd('PrintCliArgs', function()
  local args = 'cli args: '
  for _, v in ipairs(vim.v.argv) do
    args = args .. v .. ' '
  end
  print(args)
end, {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants