{"id":15357161,"url":"https://github.com/chocolateboy/vim-myspace","last_synced_at":"2025-03-27T14:47:39.635Z","repository":{"id":53776374,"uuid":"133729864","full_name":"chocolateboy/vim-myspace","owner":"chocolateboy","description":"Safely view and edit files with your preferred indentation size","archived":false,"fork":false,"pushed_at":"2024-11-23T19:41:12.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T18:45:37.885Z","etag":null,"topics":["indent","indent-size","indentation","indentation-size","roundtrip","space","spaces","spacing","transparent","vim","vim-plugin"],"latest_commit_sha":null,"homepage":"","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/chocolateboy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-16T22:34:17.000Z","updated_at":"2024-11-23T19:41:16.000Z","dependencies_parsed_at":"2022-09-10T18:02:50.006Z","dependency_job_id":null,"html_url":"https://github.com/chocolateboy/vim-myspace","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fvim-myspace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fvim-myspace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fvim-myspace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chocolateboy%2Fvim-myspace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chocolateboy","download_url":"https://codeload.github.com/chocolateboy/vim-myspace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245865225,"owners_count":20685186,"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":["indent","indent-size","indentation","indentation-size","roundtrip","space","spaces","spacing","transparent","vim","vim-plugin"],"created_at":"2024-10-01T12:33:37.623Z","updated_at":"2025-03-27T14:47:39.592Z","avatar_url":"https://github.com/chocolateboy.png","language":"Vim Script","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vim-myspace\n\n\u003c!-- toc --\u003e\n\n- [NAME](#name)\n- [INSTALLATION](#installation)\n  - [Pathogen](#pathogen)\n  - [vim-plug](#vim-plug)\n  - [Vundle](#vundle)\n- [SYNOPSIS](#synopsis)\n- [DESCRIPTION](#description)\n  - [Why?](#why)\n- [SETTINGS](#settings)\n  - [myspace_filetype](#myspace_filetype)\n  - [myspace_disable](#myspace_disable)\n- [TIPS \u0026 TRICKS](#tips--tricks)\n  - [Project-Specific Settings](#project-specific-settings)\n  - [Auto-Indentation](#auto-indentation)\n- [CAVEATS](#caveats)\n  - [Tabs](#tabs)\n  - [Preformatted Sections](#preformatted-sections)\n- [FAQ](#faq)\n  - [I prefer 2 spaces. Can I use this plugin to view/edit 4-space files with 2 spaces?](#i-prefer-2-spaces-can-i-use-this-plugin-to-viewedit-4-space-files-with-2-spaces)\n- [SEE ALSO](#see-also)\n- [VERSION](#version)\n- [AUTHOR](#author)\n- [COPYRIGHT AND LICENSE](#copyright-and-license)\n\n\u003c!-- tocstop --\u003e\n\n# NAME\n\nvim-myspace - safely view and edit files with your preferred indentation size\n\n# INSTALLATION\n\n## [Pathogen](https://github.com/tpope/vim-pathogen)\n\n    $ git clone https://github.com/chocolateboy/vim-myspace ~/.vim/bundle/vim-myspace\n\n## [vim-plug](https://github.com/junegunn/vim-plug)\n\nAdd `Plug 'chocolateboy/vim-myspace'` to your `~/.vimrc` and run `PlugInstall`.\n\n## [Vundle](https://github.com/gmarik/Vundle.vim)\n\nAdd `Plugin 'chocolateboy/vim-myspace'` to your `~/.vimrc` and run `PluginInstall`.\n\n# SYNOPSIS\n\n```vim\n\" safely view and edit these 2-spaced filetypes (community standard) with 4 spaces (my preference)\nlet g:myspace_filetype = { 'crystal|ruby|scala|swift': [2, 4] }\n```\n\n# DESCRIPTION\n\nvim-myspace is a vim plugin which allows files to be viewed and edited with your preferred\nindentation size (e.g. 4 spaces) but transparently saved with the default/community-standard\nsize (e.g. 2 spaces).\n\n## Why?\n\nI find 2 spaces cramped and painful to read, but the community has settled on this standard for\nvarious languages, including:\n\n* Crystal\n* Ruby\n* Scala\n* Swift\n* YAML\n\nRather than fruitlessly attempting to overthrow the status quo, this plugin allows you to\nview and edit files in your preferred style, while saving and shipping them in the style\nstipulated by a project, workplace, community etc.\n\n# SETTINGS\n\n## myspace_filetype\n\nThe plugin is configured by assigning a dictionary of mappings to `g:myspace_filetype`\n(global) or `b:myspace_filetype` (buffer-local). If defined, the buffer-local mappings\ntake precedence over the global mappings.\n\n```vim\n\" ~/.vimrc\nlet g:myspace_filetype = { 'crystal|ruby|scala|swift': [2, 4] }\n```\n\nThe dictionary's keys are [filetypes](http://vimdoc.sourceforge.net/htmldoc/filetype.html)\n(strings) and its values are either `from` → `to` pairs (arrays), or false (0) to disable\nrewriting for the type(s). Indentations spanning multiple `from` spaces are translated\nto the corresponding number of `to` spaces when files of the specified type are loaded,\nand are unmapped (`to` → `from`) and remapped (`from` → `to`) before and after the\nfiles are saved. Remainders are passed through unchanged in both directions, e.g.\nfor 2 → 4:\n\n| from  | to    | back |\n| ----- | ----- | ---: |\n| 2     | 4     | 2    |\n| 3     | 5     | 3    |\n| 4     | 8     | 4    |\n| 5     | 9     | 5    |\n\nThe mapping from filetypes to `from`/`to` pairs can be specified individually, e.g.:\n\n```vim\nlet g:myspace_filetype = {\n    \\ 'crystal': [2, 4],\n    \\ 'ruby':    [2, 4],\n    \\ 'scala':   [2, 4],\n    \\ 'swift':   [2, 4],\n    \\ }\n```\n\nOr, if multiple filetypes share the same rewrite rule, they can be specified together,\nseparated by a pipe character:\n\n```vim\nlet g:myspace_filetype = {\n    \\ 'crystal|ruby|scala|swift': [2, 4],\n    \\ 'ada':                      [3, 4],\n    \\ }\n```\n\n## myspace_disable\n\nThe plugin can be disabled by setting `g:myspace_disable` (global) or `b:myspace_disable` (buffer-local)\nto true (1), e.g.:\n\n```vim\nlet b:myspace_disable = 1\n```\n\n# TIPS \u0026 TRICKS\n\n## Project-Specific Settings\n\nIndentation can be configured on a per-project basis by defining\n[directory-specific autocommands](https://til.hashrocket.com/posts/720a6a05f9-matching-on-directories-for-vims-autocmd),\nwhich either:\n\n* (re-)define mappings:\n\n    ```vim\n    autocmd BufNewFile,BufRead ~/build/example/*.js let b:myspace_filetype = { 'javascript': [2, 4] }\n    ```\n\n* disable rewrites for files that already use your preferred style:\n\n    ```vim\n    autocmd BufNewFile,BufRead ~/build/example/* let b:myspace_disable = 1\n    ```\n\n* or a combination of the two:\n\n    ```vim\n    \" default settings: expand 2-space TypeScript to 4 spaces\n    let g:myspace_filetype = { 'typescript': [2, 4] }\n\n    \" custom settings for a project with 2-space JavaScript (expand) and 4-space\n    \" TypeScript (no change)\n    autocmd BufNewFile,BufRead ~/build/example/* let b:myspace_filetype = {\n        \\ 'javascript': [2, 4],\n        \\ 'typescript': 0,\n        \\ }\n    ```\n\nSince overrides are typically buffer-local, they can be sourced from\na (shared) file without affecting the global settings, e.g.:\n\n```vim\n\" ~/.vim/local/indent-js-24.vim\nlet b:myspace_filetype = { 'javascript': [2, 4] }\n```\n\n```vim\n\" ~/.vimrc\nautocmd BufNewFile,BufRead ~/code/example/*.js source ~/.vim/local/indent-js-24.vim\n```\n\n## Auto-Indentation\n\nYou may need to tweak the indentation settings in your `~/.vimrc` to reflect your preferred style.\nAutomatic indentation (i.e. while typing) works as expected for me with the following `~/.vimrc` settings:\n\n```vim\nset autoindent\nset shiftwidth=4\nset softtabstop=4\nset tabstop=8\n```\n\nIn addition, you may need to add overrides for core and third-party filetype plugins\nwhich impose an indentation size:\n\n```vim\n\" override the 2-space indentation imposed by vim-ruby\n\" https://github.com/vim-ruby/vim-ruby/issues/234\nautocmd FileType ruby :setlocal expandtab shiftwidth=4 tabstop=4\n```\n\nAlternatively, it may be possible to toggle a plugin's indentation settings on/off via a variable, e.g.:\n\n```vim\n\" disable the 2-space indentation imposed by vim-ruby's filetype plugin\nlet g:ruby_recommended_style = 0\n```\n\n# CAVEATS\n\n## Tabs\n\nThe plugin only operates on lines that begin with spaces. Lines that begin with tabs are unaffected.\nLines that begin with spaces followed by one or more tabs are only transformed up to the tab(s).\n\n## Preformatted Sections\n\nThe transform may occasionally affect indentation on lines that are already correctly indented\nsuch as the bodies of multi-line comments or heredocs, e.g.:\n\n**before**\n\n```ruby\ncode = \u003c\u003cEOS # four spaces\nclass Foo {\n    foo() {\n        return 42\n    }\n}\nEOS\n```\n\n**after**\n\n```ruby\ncode = \u003c\u003cEOS # eight spaces\nclass Foo {\n        foo() {\n                return 42\n        }\n}\nEOS\n```\n\n# FAQ\n\n## I prefer 2 spaces. Can I use this plugin to view/edit 4-space files with 2 spaces?\n\nYes and no. While well-formed indents can correctly be roundtripped, e.g. for 4 → 2:\n\n| from   | to   | back   |\n| -----: | ---: | -----: |\n| 4      | 2    | 4      |\n| 8      | 4    | 8      |\n| 12     | 6    | 12     |\n| 16     | 8    | 16     |\n\n\\- real-world code contains ill-formed indents, e.g. 4-spaced files with lines that\nbegin with, say, 6 spaces:\n\n```cpp\n    if (::v8::internal::FLAG_trace_sim) {                //  4\n      PrintF(\"Call to host function at %p args %08x\\n\",  //  6 (!)\n          reinterpret_cast\u003cvoid*\u003e(external), arg0);      // 10 (!)\n    }                                                    //  4\n```\n\n\\- or lines that begin with an odd number of spaces:\n\n```javascript\n    if (                                                 //  4\n           (await Fs.exists(cachedPath))                 // 11 (!)\n        \u0026\u0026 (cached = await Fs.readFile(cachedPath))      //  8\n    ) {                                                  //  4\n        request = Promise.resolve(cached)                //  8\n    }                                                    //  4\n```\n\n```cpp\n    /*******              // 4\n     * this is a comment  // 5\n     */                   // 5\n```\n\nExpansion is always reversible, i.e. if `from` \u003c= `to`, there is no loss of\ninformation about the original number of spaces when multiples of `from`\nare mapped to multiples of `to`. The same is not always true if `from` \u003e\n`to`, e.g. for 4 → 2:\n\n| from   | to   | back   |\n| -----: | ---: | -----: |\n| 2      | 2    | 4      |\n| 3      | 3    | 5      |\n| 6      | 4    | 8      |\n| 7      | 5    | 9      |\n\n# SEE ALSO\n\n* [AutoAdapt](https://www.vim.org/scripts/script.php?script_id=4654) - automatically update timestamps, copyright notices, etc.\n* [detectindent](https://github.com/ciaranm/detectindent) - vim script for automatically detecting indent settings\n* [sleuth.vim](https://github.com/tpope/vim-sleuth) - heuristically set indentation options\n\n# VERSION\n\n1.0.1\n\n# AUTHOR\n\n[chocolateboy](mailto:chocolate@cpan.org)\n\n# COPYRIGHT AND LICENSE\n\nCopyright © 2016-2024 by chocolateboy\n\nThis is free software; you can redistribute it and/or modify it under the terms\nof the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchocolateboy%2Fvim-myspace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchocolateboy%2Fvim-myspace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchocolateboy%2Fvim-myspace/lists"}