Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/LucHermitte/alternate-lite

a.vim rewriting
https://github.com/LucHermitte/alternate-lite

cpp vim vim-plugins viml-functions viml-library

Last synced: about 2 months ago
JSON representation

a.vim rewriting

Awesome Lists containing this project

README

        

# alternate-lite [![Last release](https://img.shields.io/github/tag/LucHermitte/alternate-lite.svg)](https://github.com/LucHermitte/alternate-lite/releases) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020)

## Features
This plugin is meant to be a simplification of Michael Sharpe's alternate.vim plugin.

The design decisions that distinguishes _alternate-lite_ from _alternate_ are the
following:

* Support for project/buffer specific settings
* Use dictionaries to set variables
* Lazy definition of functions through autoload plugin
* `:IH` commands and related mappings are already defined in my
[SearchInRuntime plugin](http://github.com/LucHermitte/SearchInRuntime).

My main use case for this plugin is to build things like
[lh-cpp's `:GOTOIMPL` command](http://github.com/LucHermitte/lh-cpp).

## Commands

alternate-lite implements slightly differently all `:A` commands provided by
original `a.vim` plugin.

All these commands first deduce an alternate file for the current one. The
priority is given to files that exist. Then, they try to jump to the window
where this alternate file is displayed, if the file wasn't displayed, it'll be
opened:

* In the current window with `:A`,
* In a horizontally split opened window with `:AS`,
* In a vertically split opened window with `:AV`,
* In a new tab with `:AT`.

In case several alternate files are found, we'll be asked to choose which one
we wish to open or to jump-to.

The previous commands also take an optional parameter: the extension we wish
precisally to use to deduce the alternate file.

There is also the `:AN` command that permits to cycle through the buffers
associated to the current buffer. If possible, this command will search for a
window where the next buffer is already displayed.

## Options

Some usual extensions are already registered. This can be extended globally,
locally, on project basis, etc.
See [`lh#ft#option#get()`](https://github.com/LucHermitte/lh-dev#filetype-polymorphism).

You can obtain the latest status with a `:echo g:alternates.extensions`.

### Extension map

#### Globally change the extension mappings
Let's say you want to register `.tpp` as a new extension for files where C++
template functions would be defined, you'll need to execute (in your `.vimrc`
for instance):

```vim
" The actual {extension -> extensions} map
call lh#alternate#register_extension('g', 'h' , g:alternates.extensions.h + ['tpp'])
call lh#alternate#register_extension('g', 'hpp', g:alternates.extensions.hpp + ['tpp'])
call lh#alternate#register_extension('g', 'tpp', ['h', 'hpp'])

" The {filetype -> extensions} map
let g:alternates.fts.cpp += ['tpp']
" Note: this last command can only be done after a call to any lh#alternate#* function
```

This says that this new extension may be used in all your projects.

The last line is important and required with filetypes that share some
extensions like C, C++, ObjectiveC, and so on. Other filetypes like lex, yacc,
OCaml, ASP... aren't concerned.

If you see that `g:alternates.fts` exists for the filetype to which you wish
to register a new extension, then, don't forget to extend the associated list
with the new extension.

#### Change the extension mappings for a given project only
If you prefer to register it only in one project, with
[lh-vim-lib](http://github.com/LucHermitte/lh-vim-lib)
[project feature](https://github.com/LucHermitte/lh-vim-lib/blob/master/doc/Project.md),
you could define instead:

```vim
" The actual {extension -> extensions} map
call lh#alternate#register_extension('p', 'h' , g:alternates.extensions.h + ['tpp'])
call lh#alternate#register_extension('p', 'hpp', g:alternates.extensions.hpp + ['tpp'])
call lh#alternate#register_extension('p', 'tpp', ['h', 'hpp'])

" The {filetype -> extensions} map
LetTo p:alternates.fts.cpp = g:alternates.fts.cpp + ['tpp']
" Note: this last command can only be done after a call to any lh#alternate#* function
```

In order to override the default values, just don't reuse them.

### Directory selection
The option `(bpg):[{ft}_]alternates.searchpath` can contain a comma separated
list of directory alternance policy:

* A path with a prefix of `"wdr:"` will be treated as relative to the working
directory.
* A path prefix of `"abs:"` will be treated as absolute.
* No prefix or `"sfr:"` will result in the path being treated as relative to the
source file (see sfPath argument).

* A prefix of `"reg:"` will treat the pathSpec as a regular expression
substitution that is applied to the source file path. The format is:

```
reg:
```

* `` seperator character, we often use one of `[/|%#]`
* `` is what you are looking for
* `` is the output pattern
* `` can be g for global replace or empty

Examples:

* `'reg:/inc/src/g/'` will replace every instance of `'inc'` with `'src'` in
the source file path. It is possible to use match variables so you could do
something like: `'reg:|src/\([^/]*\)|inc/\1||'` (see `'help :substitute'`,
`'help pattern'` and `'help sub-replace-special'` for more details

Note: ',' (comma) are used internally so DON'T use it in your regular expressions
or other pathSpecs.

## TODO
Many features from the original a.vim plugin are still missing, starting with
`:A*` commands. I should eventually define them. For now I just need a simpler
tool to define correctly
[lh-cpp's `:GOTOIMPL` command](http://github.com/LucHermitte/lh-cpp).

## Installation
* Requirements: Vim 7.+, [lh-vim-lib](http://github.com/LucHermitte/lh-vim-lib) v4.6.3

* With [vim-addon-manager](https://github.com/MarcWeber/vim-addon-manager), install alternate-lite. This is the preferred method because of the various dependencies.
```vim
ActivateAddons alternate-lite
```
* or with [vim-flavor](http://github.com/kana/vim-flavor) which also supports
dependencies:
```
flavor 'LucHermitte/alternate-lite'
```
* or you can clone the git repositories (expecting I haven't forgotten anything):
```
git clone [email protected]:LucHermitte/lh-vim-lib.git
git clone [email protected]:LucHermitte/alternate-lite.git
```
* or with Vundle/NeoBundle (expecting I haven't forgotten anything):
```vim
Bundle 'LucHermitte/lh-vim-lib'
Bundle 'LucHermitte/alternate-lite'
```

## Credits
* Michael Sharpe for his original plugin
* Directory & regex enhancements added by Bindu Wavell who is well known on
vim.sf.net

## License
We grant permission to use, copy modify, distribute, and sell this software for
any purpose without fee, provided that the above copyright notice and this text
are not removed. We make no guarantee about the suitability of this software
for any purpose and we are not liable for any damages resulting from its use.
Further, we are under no obligation to maintain or extend this software. It is
provided on an "as is" basis without any expressed or implied warranty.