Giter Site home page Giter Site logo

gitgrep.vim's Introduction

gitgrep.vim

An easy way to issue a git grep command across a git repository and navigate between the results.

Pros

  • Alternative (or addition) to ctags and cscopse.
  • No need to refresh index.
  • No dependencies.
  • Cross language.

Installation

  • Install using your favorite package manager, e.g., Vundle:

    1. Add the following to your .vimrc: Plugin 'eranfrie/gitgrep.vim'.
    2. Reload .vimrc.
    3. Run: :PluginInstall.
  • Manual installation: copy gitgrep.vim to your plugin directory (e.g., ~/.vim/plugin/ in Unix / Mac OS X).

Selection Menu:

  • Down / Up / PageDown / PageUp to navigate the menu.
  • Enter to select a result and jump to it.
  • Esc / Ctrl-C to cancel.
  • Backspace to remove the last character from the pattern.
  • Any other key to add a character to the pattern.

Functions:

  • GitGrep(flags, pattern) - issue a git grep command and open the selection menu, where flags are git grep flags (can be empty string) and pattern is the pattern to look for.

  • GitGrepBack() - jump back to previous location.

  • GitGrepIterPrev() / GitGrepIterNext() - iterate to the previous/next match.

Customizations:

  • Change the default git grep command
let g:gitgrep_cmd = "grep -r"
  • Exclude files using Vim's regex
let g:gitgrep_exclude_files = "<regex>"

E.g., exclude files stsarting witth test or containing simulation

let g:gitgrep_exclude_files = "^test\\|simulation"
  • Set the height (number of lines) of the selection menu
let g:gitgrep_menu_height = 15
  • Set the color of the file path
let g:gitgrep_file_color = "blue"
  • Set the color of the matched pattern
let g:gitgrep_pattern_color = "red"
  • Disable loading the plugin
let g:loaded_gitgrep = 1

Mappings:

Keys are not mapped automatically. You can choose your own mapping,

Some recommendations:

Easily gitgrep for the word under cursor and jump back:

nnoremap <leader>g :call GitGrep("-w", expand("<cword>"))<CR>
nnoremap <leader>t :call GitGrepBack()<CR>

Create mappings with common grep flags:

command -bang -nargs=* GG call GitGrep("", expand(<q-args>))
command -bang -nargs=* GGw call GitGrep("-w", expand(<q-args>))
command -bang -nargs=* GGi call GitGrep("-i", expand(<q-args>))

Create mappings to iterate to the previous and next matches:

nnoremap <leader>p :call GitGrepIterPrev()<CR>
nnoremap <leader>n :call GitGrepIterNext()<CR>

Examples:

Most basic usage - find all instances of "test":

:GG test

To use special characters such as space, escape the pattern:

:GG "def test"

Regex:

:GG def.*test

Additional grepping (can be used to filter files):

:GG def | grep test.py

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.