Giter Site home page Giter Site logo

gfi.vim's Introduction

gfi.vim

A zero-configuration extension and improved version of the gf command in Vim, which opens the file under the cursor, but now in a smarter way.

Table of Contents

Getting Started

Install gfi.vim:

Using vim-pack:

  • git clone https://github.com/kkoomen/gfi.vim ~/.vim/pack/<dir>/start/gfi

Using pathogen:

  • git clone https://github.com/kkoomen/gfi.vim ~/.vim/bundle/gfi

Using plug:

  • Plug 'kkoomen/gfi.vim'

How It Works

Files will be resolved now based on its path:

  • relative to the current buffer
  • relative to vim's current working directory
  • based on the git directory it is located in

This is default behavior for every filetype.


Files will also be checked in a more advanced way per filetype when it can:

  • javascript / typescript / jsx

    Most javascript projects these days use webpack to resolve their import statements. This module is also able to resolve these import paths, relative or absolute. Javascript-like filetype buffers will also try to resolve paths based on:

    • The moduleRoots property in the package.json of the project.
    • Whether the input is a directory and if it is, it will look for an index file in that directory, since webpack is resolving index files if a directory is imported.
  • golang

    Go has an import syntax which contains paths relative to the $GOPATH var.
    For example:

    import (
        "github.com/username/repo"
        "github.com/username/repo/src/dir/subdir"
    )
    

    These paths will be resolved using the format $GOPATH/src/<import>.

Configuration

g:gfi_open_file_command

default: 'edit'

Define the command which will open the file or directory.
For example: vsplit, split, tabnew, edit, etc...

Contributing

Help or feedback is always appreciated. If you find any bugs or improvements, feel free to submit a pull request.

Linting

Your pull request should follow the rules of the vim-vint linter which is a must to keep your code clean and prevent mistakes being made.

  • pip3 install vim-vint

If you use ALE (recommended)

let g:ale_linters = { 'vim': ['vint'] }

or if you use Syntastic

let g:syntastic_vim_checkers = ['vint']

Documentation

Every function, mapping or configurable option should contain documentation. The documentation in the doc/ should be generated using vimdoc.

License

Copyright 2019 Kim Koomen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gfi.vim's People

Contributors

kkoomen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ksaj

gfi.vim's Issues

[FEATURE] check for index file

Is your feature request related to a problem? Please describe.
Hi! Great plugin but if I try to load a path that is a folder, for example "../routes/home" it won't load as the exact file path is "../routes/home/index.js"

Describe the solution you'd like
I'd like to add the index route in the paths list with something like

call add(l:paths, simplify(getcwd() . '/' . l:cfile . '/index'))

It works for me but there might be something to take into account which I'm not aware of.

I'd be happy to send a PR but I've got no permissions

[BUG] This breaks `gf` in python files

Describe the bug

When opening python files, the behaviour of gf changes slightly, but this plugin doesn't handle that, which ends up breaking gf.

The changes I'm aware of are:

  • separator: import paths have . between the components, but those match to folder separators on the file system.
  • suffix: imported paths need to have .py appended if it's a file, and /__init__.py if it's a folder (btw, now that I think about it, I don't know what the precedence between the two should be, in case both foo.py and foo/__init.py exist)

To Reproduce
Steps to reproduce the behavior:

$ cat > foo.py <<EOF
import asd.qwe
EOF

$ mkdir asd
$ touch asd/qwe.py

Open foo.py, navigate to the second word (the import path) and hit gf.

Expected behavior

asd/qwe.py should get opened; instead the following error is printed:

Opening "asd.qwe"...
Could not open "asd.qwe"

This shows clearly that the separators are not properly converted, and that the suffix is missing.

**Output of `vim --version`** I'm using the standard `vim` package in fedora right now:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 15 2021 00:00:00)
Included patches: 1-2607
Modified by <[email protected]>
Compiled by <[email protected]>
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              +perl/dyn          +title
-clientserver      +job               +persistent_undo   -toolbar
-clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3/dyn       +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       +lua/dyn           +ruby/dyn          +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              +mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim82"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: gcc -L. -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -L/usr/local/lib -Wl,--as-needed -o vim -lm -lselinux -lncurses -lacl -lattr -lgpm -ldl -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -L/usr/local/lib -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc 

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.