Home

Awesome

alternate-lite Last release Project Stats

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:

My main use case for this plugin is to build things like lh-cpp's :GOTOIMPL command.

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 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().

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):

" 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 project feature, you could define instead:

" 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:

Examples:

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.

Installation

ActivateAddons alternate-lite
flavor 'LucHermitte/alternate-lite'
git clone git@github.com:LucHermitte/lh-vim-lib.git
git clone git@github.com:LucHermitte/alternate-lite.git
Bundle 'LucHermitte/lh-vim-lib'
Bundle 'LucHermitte/alternate-lite'

Credits

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.