Git Product home page Git Product logo

vim-apathy's Introduction

apathy.vim

Apathy sets the five path searching options — 'path', 'suffixesadd', 'include', 'includeexpr', and 'define' — for file types I don't care about enough to bother with creating a proper plugin.

Rationale

As you might have guessed from /usr/include being in the default, the original purpose of the 'path' option was to house the C preprocessor include path. This enabled Vim to parse a preprocessor declaration like #include <stdio.h> and determine that the file being included was /usr/include/stdio.h. Several features are built-in on this groundwork:

  • gf, <C-W>f, <C-W>gf: jump to the included file under the cursor.
  • :find, :sfind, :tabfind: jump to the specified included file.
  • [i: display the first line in the current file or an included file containing the keyword under the cursor.
  • ]i: like above, but start searching after the cursor.
  • :isearch: like above, but give your own line range and search pattern.
  • [I, ]I, :ilist: like above, but display all matches.
  • [<C-I>, ]<C-I>, <C-W>i, :ijump, :isplit: like above, but jump to the match.
  • <C-X><C-I>: complete keywords from included files.
  • [d, ]d, :dsearch, [D, ]D, :dlist, [<C-D>, ]<C-D>, <C-W>d, :djump, :dsplit, <C-X><C-D>: like their i equivalents, but for macro definitions.
  • :checkpath: list missing included files.

I list these exhaustively to stress that included files aren't just a potential use of 'path', they are the very purpose of 'path'. If you've been using 'path' to contain a list of commonly accessed directories or something like **/*, you're precluding yourself from using 38 different commands. Oops! (Try one of the many fuzzy finder plugins instead.)

While Vim is set up for C by default, it provides a few options to use these features for other languages:

  • 'include' is a pattern for matching include declarations, defaulting to ^\s*#\s*include. A value for JavaScript imports might look like \<require\|\<from.
  • 'includeexpr' is a simple function for converting an include to a filename. In languages like Java, Lua, and Python, this could be used to change foo.bar into foo/bar.
  • 'suffixesadd' is a list of file extensions to try. JavaScript might use something like .js,.coffee.
  • 'define' is a pattern for matching macro definitions, defaulting to ^\s*#\s*define. This doesn't serve much purpose for languages without a preprocessor, but sometimes it is helpful to make it match function and/or variable declarations.

These, along with 'path', make up the purview of Apathy.

Supported file types

Additionally, the C related defaults are stripped out of the global config, so you don't have to worry about /usr/include tainting everything.

Related plugins

Installation

Install using your favorite package manager, or use Vim's built-in package support:

mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone https://tpope.io/vim/apathy.git

License

Copyright © Tim Pope. Distributed under the same terms as Vim itself. See :help license.

vim-apathy's People

Contributors

bfrg avatar maxnordlund avatar miles-d avatar tomasv avatar tpope 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  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  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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-apathy's Issues

It doesn't work for lua

If you have one file in directory, for example: main.lua with contents require "adsfasdf", checkpath command will say all included files found.
Also, even when the included file exists and there is a definition in it, commands such as: [i :isearch will not find it.

Doesn't work with scoped or local/aliased node_modules

Scoped npm modules

Scoped npm packages follow this pattern @scope/name which translates inside node_modules folder like this

node_modules
|_ @scope
  |_ name

and import will look like this

import foo from '@scope/name'

The plugin doesn't work with this.

local paths/aliased modules

Also, package.json supports local paths which will link to the folder inside node_modules. Example:

{
  "name": "baz",
  "dependencies": {
    "bar": "file:../foo/bar",
    "~somepackage": "file:../foo/somepackage",
    "@anotherone": "file:../foo/anotherone",
  }
}

and imports will look like this

import foo from 'bar' // this works as expected
import foo from '~somepackage' // this doesn't work
import foo from '@anotehrpackage' // this doesn't work

The plugin works fine with bar but not with ~somepackage or @anotherpakcage.

c/cpp on OS X/macOS >= v10.8: clang is the default & only compiler provided by XCode

According to wikipedia

Up to Xcode 4.1, the Xcode suite included a modified version of the GNU Compiler Collection.
In Xcode 3.1 up to Xcode 4.6.3, it included the LLVM-GCC compiler, with front ends from the GNU Compiler Collection and a code generator based on LLVM
Starting with Xcode 5.0, Clang was the only compiler provided.

This means since 2013 with OS X v10.8 which installed XCode 5.0, there is no GNU c preprocessor cpp if someone has only installed XCode.

On my machine (macOS 10.12) the commands cpp -v -x c and cpp -v -x c++ do only return:

❯ cpp -v -x c
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: warning: argument unused during compilation: '-traditional' [-Wunused-command-line-argument]

I am not entirely sure if following commands are the best equivalents for clang but for me they return the list of include paths used by clang

clang -v -x c /dev/null
clang++ -v -x c++ /dev/null
❯ clang++ -v -x c++ /dev/null
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir / -ferror-limit 19 -fmessage-length 135 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/d_/5kjxh9v92k752bvzf559fd3c0000gn/T/null-d43315.o -x c++ /dev/null
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin16.7.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out /var/folders/d_/5kjxh9v92k752bvzf559fd3c0000gn/T/null-d43315.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If someone else could confirm that these commands are the most appropriate ones, I would suggest that vim-apathy uses them if cpp --version returns Apple LLVM version X.X.X (clang-X).

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.