Git Product home page Git Product logo

vim-definitive's Introduction

vim-definitive

Jump to the definitions of variables, classes, functions, etc., without relying on tags. To definity and beyond!

Usage

vim-definitive is definitively simple to use!

Example usage in vimscript and elixir

Commands

:FindDefinition uses :grep to search for the definition of the word under the cursor.

:FindDefinition FunctionOrVariableName greps for the definition of FunctionOrVariableName.

:SFindDefinition and :VFindDefinition are like :FindDefinition but the results will be returned in a new horizontal or vertical split, respectively.

All matches are populated into the quickfix list. If a single match is found, FindDefinition will jump to the definition immediately. If more than one match is found, FindDefinition will open the quickfix list and jump to the first match. If there is a match within the current file, FindDefinition will jump to the first match before the cursor, opening the quickfix list if there are any more matches.

Mappings

No mappings are created by default, so I recommend mapping :FindDefinition to something simple, a la:

nnoremap <Leader>d :FindDefinition<CR> " Normal mode
vnoremap <Leader>d "ay:FindDefinition <C-R>a<CR> " Visual mode

Settings

g:definitive_definitions contains the regex dictionary used to search for definitions based on filetype. To append to this dictionary or override an existing definition, simply extend g:definitive_definitions as follows:

let g:definitive_definitions = {
      \ 'javascript': '\<\(\(const\|let\|var\)\s\+%1\>\|\(function\s\+\)\=%1\s*(.*)\s*{\|class\s\+%1\s*{\)',
      \ 'some_other_filetype': 'some\+other.*fancy\\regex\s%1'
      \}

Note: %1 is used as the placeholder for the keyword that will be grepped for, so don't forget to include it somewhere in your regex.

You can also specify that a filetype should use the same regex as another filetype by using 'extends' as follows:

let g:definitive_definitions = {
    \ 'javascript.jsx': { 'extends': 'javascript' }
    \}

PS: If you can come up with a regex for a language that vim-definitive does not currently support by default, let me know or create a PR!

Languages currently supported by default:

  • Javascript
  • Typescript
  • JSX
  • PHP
  • Python
  • Ruby
  • Elixir
  • Scala
  • Kotlin
  • Vimscript
  • Shell scripts

g:definitive_associated_filetypes is used to tell vim-definitive to use a certain filetype's definition when searching from a different filetype. An example use case would be wanting to find the definition of a variable in a ruby project from inside an ERB file, which is of filetype 'eruby', not 'ruby', normally causing vim-definitive to call off its search. You can specify such relationships between filetypes as follows:

let g:definitive_associated_filetypes = {
      \  'eruby': 'ruby',
      \  'html.handlebars': 'javascript',
      \}

This will tell vim-definitive to look for ruby variables when you're in an ERB template and javascript variables when you're in a Handlebars template.

g:definitive_root_markers is the list of project root directory markers. These are files or directories which typically mark the root directory of a given project. vim-definitive uses this list to determine where it should be looking when it is searching for definitions. Common examples include .git or .hg directories or a Makefile, Gemfile, or Pipfile, and so on. You can extend this list as follows:

let g:definitive_root_markers = {
      \ 'all': [ '.git', '.gitignore', '.hg', '.hgignore', 'Makefile' ],
      \ 'javascript': [ 'package.json' ]
      \}

Note that this is filetype-specific, and that vim-definitive will search first for those files listed for the current filetype, and then for any listed under 'all'.

Also note that your extensions will overwrite the defaults for that filetype. For example, the default for javascript is to look for package.json, so if you did something like javascript: [ 'node_modules' ], vim-definitive would no longer look for the package.json file.

g:definitive_jump_to_first_match determines when vim-definitive will jump to the first match found

If 2, always jump to the first match found. If 1, only jump to the first match found if there is only a single match. If 0, never jump to the first match found. (default: 1)

Note: Regardless of what this is set to, vim-definitive will always jump to a match if there is one found within the current file.

g:definitive_open_quickfix determines when vim-definitive opens the quickfix list

If 2, always open the quickfix list. If 1, only open the quickfix list if there is more than one match. If 0, never open the quickfix list, even if there is more than one match. (default: 1)

Installation

Install it however you usually install plugins.

For example, if you use Vim-Plug, simply add to your vimrc:

Plug 'misterbuckley/vim-definitive'

Pathogen users:

cd ~/.vim/bundle
git clone https://github.com/misterbuckley/vim-definitive.git

NOTES

vim-definitive requires git version 2.19.0 or higher. If you have installed or updated vim-definitively recently and you are unable to find definitions outside of the current file, it may be because your git-grep is out of date. If you are on Ubuntu, see this StackOverflow thread.

vim-definitive's People

Contributors

flipsi avatar misterbuckley avatar toupeira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vim-definitive's Issues

Fix not being able to extend g:definitive_definitions

Right now, extending the definition map as explained under the settings section of the readme/helpfile doesn't always work because the dictionary might not exist when the user is trying to do that.

I'd like to do something like luochen1990 does in his rainbow plugin, where the user can define g:definitive_definitions and then this gets extended into the default options.

allow searching for definitions outside of the current file even when a match is found in the current file

right now, the plugin will search first for matching definitions within the current file before grepping the rest of the project. if a match is found in the current file, the grep will not take place. this is not always desired behavior - sometimes you would like to see all matching definitions in the project, not just those in the current file. should fix this by either:
A. always do the project-wide grep, but jump to the match within the current file if found (else jump to first match in the quickfix list, as it does now)
B. add a configuration option to toggle between A or the current behavior of not doing the project-wide grep when a match is found in the current file

Turn off quickfix after select

After selecting one definition from the quickfix list, can we turn it off so that it doesn't show the list in the new file?

Allow filetypes to extend one another

Hi there! Maybe consider adding a way for filetypes to extend one another. Right now I am forced to duplicate my regex for both javascript and javascript.jsx.

eg. emmet:

let g:user_emmet_settings = {
  \  'javascript.jsx' : {
  \      'extends' : 'jsx',
  \  },
  \}

Fix reliance on fugitive's Ggrep for git grepping

FindDefinition currently checks if :Ggrep is available, using it if it is, otherwise using :grep. Rather than checking for :Ggrep, it should check if git grep is available on the system and use that instead.

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.