Skip to content

nekowasabi/vim-rule-switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-rule-switcher

This Vim plugin provides a convenient way to switch between related files based on custom rules. It's particularly useful in projects where files of different types or with different naming conventions are logically related, such as header and implementation files in C/C++ projects, or component and test files in web development.

Features

  • Define custom switching rules based on file paths, prefixes, and postfixes.
  • Easily navigate between related files with a simple Vim command.
  • Supports integration with Git to switch between files tracked in the repository.

Requirements

Installation

You can install vim-rule-switcher using your favorite plugin manager. For example, with vim-plug:

Plug 'nekowasabi/vim-rule-switcher'

Then run :PlugInstall in Vim.

Configuration

Make json file in /path/to/example.json.

{
  "conditions": [
    {
      "name": "neovim_settings",
      "rule": "file",
      "path": [
        "~/.config/nvim/init.vim",
        "~/.config/nvim/rc/plugin.vim"
      ]
    },
    {
      "name": "unit_test",
      "rule": "file",
      "prefix": "Test",
      "postfix": "Test",
      "path": [
        "~/.config/nvim/rc/%.php",
        "~/.config/nvim/rc/%Test.php"
      ]
    },
    {
      "name": "git_sample",
      "rule": "git",
      "prefix": "Test",
      "postfix": "Test",
      "path": [
        "%.php",
        "%Test.php"
      ]
    }
  ]
}

Define your switching rules in your .vimrc or init.vim like so:

let g:switch_rule = readfile("/path/to/example.json")

Usage

To switch between files according to the defined rules, use the following Vim command:

:SwitchFileByRule

Optionally, you can pass an argument to specify the type of switch, such as 'git' to switch between files tracked by Git:

:SwitchFileByRule git

To add a new rule for the current file, use the following command:

:SaveSwitchRule <rule_name>

This command will add the current file to the specified rule in the switch rule file.

To edit the rules file, use the following command:

:OpenSwitchRuleFile

Integrated with ddu

Using ddu, you can select and open files defined in rules via a fuzzy finder.

call ddu#custom#patch_global(#{
    \   kindOptions: #{
    \     rule_switch: #{
    \       defaultAction: 'open',
    \     },
    \   }
    \ })

call ddu#start({'sources': [{'name': 'rule_switch'}]})

TODO

  • Integrate ddu
  • Enable use rules file.
  • Add config command.

Related Projects

vim-altr

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published