Skip to content

Commit 12622c2

Browse files
stack_view: add keybinds to open in split (#93)
1 parent 5a91d16 commit 12622c2

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Heavily inspired by emacs' [xcscope.el](https://github.com/dkogan/xcscope.el).
5656
- In `CsStackView` window, use following keymaps
5757
- `<tab>` toggle child under cursor
5858
- `<cr>` open location of symbol under cursor
59+
- `<C-v>` open location of symbol under cursor in vertical split
60+
- `<C-s>` open location of symbol under cursor in horizontal split
5961
- `q` or `<esc>` close window
6062
- `<C-u>` or `<C-y>` scroll up preview
6163
- `<C-d>` or `<C-e>` scroll down preview

doc/cscope_maps.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*cscope_maps.txt* For Neovim >= v0.10.0 Last change: 2025 October 10
1+
*cscope_maps.txt* For Neovim >= v0.10.0 Last change: 2025 October 29
22

33
==============================================================================
44
Table of Contents *cscope_maps-table-of-contents*
@@ -77,6 +77,8 @@ STACK VIEW ~
7777
- In `CsStackView` window, use following keymaps
7878
- `<tab>` toggle child under cursor
7979
- `<cr>` open location of symbol under cursor
80+
- `<C-v>` open location of symbol under cursor in vertical split
81+
- `<C-s>` open location of symbol under cursor in horizontal split
8082
- `q` or `<esc>` close window
8183
- `<C-u>` or `<C-y>` scroll up preview
8284
- `<C-d>` or `<C-e>` scroll down preview

lua/cscope/stack_view/init.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ M.set_keymaps = function()
9595
vim.keymap.set("n", "<tab>", M.toggle_children, opts)
9696

9797
-- open location under cursor
98-
vim.keymap.set("n", "<cr>", M.enter_action, opts)
98+
vim.keymap.set("n", "<cr>", function()
99+
M.open_action("none")
100+
end, opts)
101+
vim.keymap.set("n", "<C-v>", function()
102+
M.open_action("vert")
103+
end, opts)
104+
vim.keymap.set("n", "<C-s>", function()
105+
M.open_action("horiz")
106+
end, opts)
99107

100108
-- scroll up
101109
vim.keymap.set("n", "<C-u>", M.pv_scroll(-1), opts)
@@ -128,7 +136,7 @@ M.set_autocmds = function()
128136
api.nvim_create_autocmd("VimResized", {
129137
group = augroup,
130138
buffer = M.cache.sv.buf,
131-
callback = function ()
139+
callback = function()
132140
buf_last_pos = fn.line(".")
133141
M.buf_close()
134142
M.buf_open_and_update()
@@ -402,7 +410,7 @@ M.toggle_win = function()
402410
M.buf_open_and_update()
403411
end
404412

405-
M.enter_action = function()
413+
M.open_action = function(split)
406414
if vim.bo.filetype ~= M.ft then
407415
return
408416
end
@@ -413,7 +421,7 @@ M.enter_action = function()
413421

414422
local _, pfilename, plnum = M.line_to_data(fn.getline("."))
415423
M.toggle_win()
416-
utils.open_file(pfilename, plnum)
424+
utils.open_file(pfilename, plnum, split)
417425
end
418426

419427
-- :CsStackView toggle

lua/cscope_maps/utils/init.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,17 @@ M.is_path_same = function(path1, path2)
139139
return path1 and path2 and M.get_abs_path(path1) == M.get_abs_path(path2)
140140
end
141141

142-
---Opens file at given line number
142+
---Opens file at given line number and split orientation
143143
---@param fname string
144144
---@param lnum number
145-
M.open_file = function(fname, lnum)
145+
---@param split string
146+
M.open_file = function(fname, lnum, split)
147+
if split == "vert" then
148+
vim.cmd("vsplit")
149+
elseif split == "horiz" then
150+
vim.cmd("split")
151+
end
152+
146153
if M.is_path_same(vim.api.nvim_buf_get_name(0), fname) then
147154
-- change position when in same buffer
148155
vim.api.nvim_win_set_cursor(0, { lnum, 0 })

0 commit comments

Comments
 (0)