Git Product home page Git Product logo

Comments (14)

junegunn avatar junegunn commented on July 19, 2024 106

This is what I have in my .vimrc.

nnoremap <silent> <Leader>ag :Ag <C-R><C-W><CR>

Looks like we can now close the issue.

from fzf.vim.

junegunn avatar junegunn commented on July 19, 2024 14

@cj Right, the function signature was changed in b9285c8

So you can now simply do this:

call fzf#vim#tags(expand('<cword>'))

from fzf.vim.

junegunn avatar junegunn commented on July 19, 2024 11

Nice, you can further simplify the code like follows, no need for if-else branch:

call fzf#vim#tags({'options': '-q '.shellescape(expand('<cword>'))})

Note that :Tags command passes layout option as well.

call fzf#vim#tags({'options': '-q '.shellescape(expand('<cword>')), 'down': '~40%'})

Is there anything else you want to know?

from fzf.vim.

xarthna avatar xarthna commented on July 19, 2024 5

Taking cues from this thread, I mapped over <c-]> to act like :tjump to jump to the tag if a single match or open it with FZF otherwise:

function! FzfTagsCurrentWord()
  let l:word = expand('<cword>')
  let l:list = taglist(l:word)
  if len(l:list) == 1
    execute ':tag ' . l:word
  else
    call fzf#vim#tags(l:word)
  endif
endfunction

noremap <c-]> :call FzfTagsCurrentWord()<cr>

from fzf.vim.

cj avatar cj commented on July 19, 2024 2

@junegunn when I try your solution in nvim I get this error

from fzf.vim.

martinklepsch avatar martinklepsch commented on July 19, 2024 2

This is pretty awesome! Is there a way to have it show the preview like :Ag does as well?

EDIT: I found that the following does show a preview :)

nnoremap <silent><Leader>r :Rg <C-R><C-W><CR>

from fzf.vim.

danihodovic avatar danihodovic commented on July 19, 2024 1

Seems like the plugin is pretty extensible. I got it to work with

fu! FzfTagsCurrWord()
  let currWord = expand('<cword>')
  if len(currWord) > 0
    call fzf#vim#tags({'options': '-q ' . currWord})
  else
    execute ':Tags'
  endif
endfu

from fzf.vim.

shaypal5 avatar shaypal5 commented on July 19, 2024 1

Just adding for those preferring to search the current word in :Ag:

" map <Leader>+F to search in ag the word under the cursor
map <Leader>F :call fzf#vim#ag(expand('<cword>'))<kEnter>

from fzf.vim.

danihodovic avatar danihodovic commented on July 19, 2024

Cool!

Is it possible to do this with :Ag too? Provide the word under cursor or a visual selection?

from fzf.vim.

danihodovic avatar danihodovic commented on July 19, 2024

👍

from fzf.vim.

cj avatar cj commented on July 19, 2024

@junegunn ah, there we go. thank you!

from fzf.vim.

 avatar commented on July 19, 2024

@junegunn : it's beautiful.

from fzf.vim.

shaypal5 avatar shaypal5 commented on July 19, 2024

Awesome! I stole your version! Why Rg and not Ag, though?

Edit: Oh, to use ripgrep instead of The Silver Searcher, right?

from fzf.vim.

nornagon avatar nornagon commented on July 19, 2024

Here's what I ended up with to ripgrep for the token under the cursor (i.e. the whole word, not as a substring of another token):

nnoremap <silent>+ :call fzf#vim#grep(
  \ "rg --column --line-number --no-heading --color=always --smart-case -- "
  \ . fzf#shellescape('\b'.expand('<cword>').'\b'),
  \ fzf#vim#with_preview(), 0)<cr>

(it's too bad there's no fzf#vim#rg like there is fzf#vim#ag, that would have made this snippet a lot shorter! As it is, this is copied from the definition of :Rg, as below)

\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".fzf#shellescape(<q-args>), fzf#vim#with_preview(), <bang>0)',

from fzf.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.