nvim-telescope / telescope-live-grep-args.nvim

Live grep with args
695 stars 36 forks source link

Automatically select the word under cursor when invoking live grep #51

Closed weiyshay closed 1 year ago

weiyshay commented 1 year ago

Hi, Thanks for this nice plugin!

It is common to search for the word under cursor in case definition/reference is not helpful. Very often the function/variable names are long and it is convenient if the plugin can have them selected when invoking live grep.

Also, it will be nice if a list of the history symbols searched can be prompted, is it possible?

weeman1337 commented 1 year ago

@weiyshay do you mean something like this ?

I really have to update that PR and merge it :laughing:

weiyshay commented 1 year ago

@weeman1337 Thanks for your respone!

The original setting:

Open live_grep with current word under cursor

map('n', 'KD', function() live_grep_raw({default_text = vim.fn.expand("<cword>")}) end)

Yes, exactly. I did a quick try on the link but unfortunately it seems that the function changed and I could not make it. i). name change from 'live_grep_raw' to 'live_grep_args', this is fine. ii). The arguments changed from the pattern to search to an options which don't include a pattern due to ':help live_grep'

Error message:

E5108: Error executing lua vim/shared.lua:0: after the second argument: expected table, got string                                                                           
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_extend'
        ...p-args.nvim/lua/telescope/_extensions/live_grep_args.lua:30: in function 'live_grep_args'
        /root/.config/nvim/lua/wei-keymappings.lua:36: in function 'get_cur_word'

Any tips to work around?

图片
weeman1337 commented 1 year ago

@weiyshay you can test it by using the branch from this PR.

The mapping should look like

local live_grep_args_shortcuts = require("telescope-live-grep-args.shortcuts")
keymap.set("n", "<leader>gc", live_grep_args_shortcuts.grep_word_under_cursor)

Let me hear how that works for you.

weiyshay commented 1 year ago

Michael, Thank you very much! It works, nice!

图片 图片
weeman1337 commented 1 year ago

This has net yet been merged → reopen until then

weiyshay commented 1 year ago

okay.