{"id":13898277,"url":"https://github.com/tjdevries/edit_alternate.vim","last_synced_at":"2025-03-06T07:55:08.362Z","repository":{"id":96938779,"uuid":"71915250","full_name":"tjdevries/edit_alternate.vim","owner":"tjdevries","description":"Quickly edit related / alternate files in vim.","archived":false,"fork":false,"pushed_at":"2021-10-25T16:53:12.000Z","size":23,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-16T19:25:06.470Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tjdevries.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-25T16:10:31.000Z","updated_at":"2025-01-14T12:24:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"cefd51c7-132c-4a98-a557-b705bed9f22c","html_url":"https://github.com/tjdevries/edit_alternate.vim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjdevries%2Fedit_alternate.vim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjdevries%2Fedit_alternate.vim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjdevries%2Fedit_alternate.vim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjdevries%2Fedit_alternate.vim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tjdevries","download_url":"https://codeload.github.com/tjdevries/edit_alternate.vim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242171563,"owners_count":20083554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T18:04:12.275Z","updated_at":"2025-03-06T07:55:08.314Z","avatar_url":"https://github.com/tjdevries.png","language":"Vim script","funding_links":[],"categories":["Vim Script","Vim script"],"sub_categories":[],"readme":"# edit_alternate.vim\n\nQuickly edit related / alternate files in vim.\n\nEdit alternate uses the concept of `rules` to decide what the \"alternate\" file should be. By adding your own rules, you can configure what the alternate files are.\n\nIt also has a helper to get you to the file that you \"meant\" to open :smile:\n\nThis plugin requires `tjdevries/conf.vim`. You'll want to install that.\n\n## Install\n\n```vim\n\" I use vim-plug, but translate this to your favorite plugin manager\n\n\" Required: Handles configuration and menu making\nPlug 'tjdevries/conf.vim'\n\" Required: That's this plugin!\nPlug 'tjdevries/edit_alternate.vim'\n\n\" Optional: Used for menu creation\nPlug 'skywind3000/quickmenu.vim'\n```\n\n## Usage\n\n### Adding rules\n\nAdding `rules` will provide more ways to get an alternate file for the one you are currently editing.\nThe plugin will run each rule until it finds one that returns an existing filename,\nand then it will choose that one and open the file.\n\nFor example:\n\n```vim\n\" Adds a rule to files with the extension \"c\" to edit the alternative file, \".h\"\ncall edit_alternate#rule#add('c', {filename -\u003e fnamemodify(filename, ':r') . '.h'})\n\n\" Adds a rule to files with the extension \".cpp\" to edit the alternative file, \".hpp\"\ncall edit_alternate#rule#add('cpp', {filename -\u003e fnamemodify(filename, ':r') . '.hpp'})\n\n\" You can also add a rule to multiple extensions at once\n\" Just use a list of strings, instead of a single string to do so\ncall edit_alternate#rule#add(['c', 'cpp'], {filename -\u003e fnamemodify(filename, ':r') . '.h'})\n```\n\nThe rule must be a function that takes one argument, `filename`, and then returns a string pointing to the potential alternate file. `filename` is guaranteed to be the full path of the current file when running `EditAlternate`.\n\nRules can be more complicated. This rule checks if there is a header file one folder below the currently edited file. For example, if you were editing `$DIR/src/i2cTask.c` and wanted to switch to `$DIR/include/i2cTask.h`, you could write a rule as follows:\n\n```vim\ncall edit_alternate#rule#add('c', {filename -\u003e\n        \\ fnamemodify(filename, ':h:h')\n        \\ . '/include/'\n        \\ . 'fnamemodify(filename, ':t:r') . '.h'\n        \\ })\n```\n\n\n#### Named Rules\n\nIt is also possible to give your rule a name, so that you can remove it when desired (for example, leaving a certain project directory, you could add an autocmd to remove the file based on `DirChanged`).\n\nThe only difference between named and unnamed rules is specifying a `name` parameter at the end of a rule add call. For example:\n\n```vim\ncall edit_alternate#rule#add('c', {filename -\u003e fnamemodify(filename, ':r') . '.h'}, 'example_rule')\n```\n\nTo remove the rule:\n\n```vim\ncall edit_alternate#rule#clear('c', 'example_rule')\n```\n\nAnd then it won't be evaluated anymore.\n\n### Current File\n\nIf you are working on a `.c`/`.cpp` file, it will switch you to the `.h` with the same name. If you are working on a `.h` file, it will switch you to either the `.c` or `.cpp` file that goes with that file as well. It figures it out ;)\n\nYou can add the mapping to easily use edit alternate\n\n```vim\nnnoremap \u003cleader\u003eea :EditAlternate\u003cCR\u003e\n```\n\n### Nonexistent Files\n\nConsider:\n\n```\nmy_folder/\n-\u003e main.c\n-\u003e util.c\n-\u003e util.h\n```\n\nYou now run the command\n\n```\n:e my_folder/ut\u003cTAB\u003e\n```\n\nYou'll get completed\n\n```\n:e my_folder/util.\n```\n\nbecause there is a `.c` and a `.h` file in the same directory... but I'll just press enter right away anyway.\n\nNow, you can just do:\n\n```vim\n\" :EditOops\nnnoremap \u003cleader\u003eeo :EditOops\u003cCR\u003e\n```\n\nThis will make it so that you default open the `.c` file instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjdevries%2Fedit_alternate.vim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjdevries%2Fedit_alternate.vim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjdevries%2Fedit_alternate.vim/lists"}