{"id":13527968,"url":"https://github.com/ealter/vim_turing_machine","last_synced_at":"2025-04-01T11:30:38.704Z","repository":{"id":85777243,"uuid":"99883332","full_name":"ealter/vim_turing_machine","owner":"ealter","description":"An implementation of a Turing machine using only normal mode Vim commands","archived":false,"fork":false,"pushed_at":"2020-08-24T18:00:58.000Z","size":78,"stargazers_count":151,"open_issues_count":0,"forks_count":6,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-02T13:33:56.591Z","etag":null,"topics":["turing-machine","vim"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/ealter.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":"2017-08-10T05:05:29.000Z","updated_at":"2024-09-30T03:49:57.000Z","dependencies_parsed_at":"2023-03-13T06:38:23.929Z","dependency_job_id":null,"html_url":"https://github.com/ealter/vim_turing_machine","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/ealter%2Fvim_turing_machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealter%2Fvim_turing_machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealter%2Fvim_turing_machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealter%2Fvim_turing_machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ealter","download_url":"https://codeload.github.com/ealter/vim_turing_machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246631514,"owners_count":20808698,"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":["turing-machine","vim"],"created_at":"2024-08-01T06:02:08.758Z","updated_at":"2025-04-01T11:30:38.384Z","avatar_url":"https://github.com/ealter.png","language":"Python","funding_links":[],"categories":["Python","Surprising"],"sub_categories":[],"readme":"Vim Turing Machine\n==================\n\nEver wish you could run your code in your editor? Tired of installing huge\ndependencies like bash or python to run your scripts? Love Vim so much that you\nnever want to leave it? Why not run your code... in your editor itself? Enter\nvim_turing_machine: a tool to allow you to run a Turing machine using only\nnormal mode Vim commands.\n\nAnd now you might ask, but what can we do on a Turing machine! To demonstrate\nits capabilities, we implemented a solution to the Merge Overlapping Intervals\nquestion and defined all the state transitions needed to solve this\nglorious problem. So next time you need to merge some intervals, don't\nhand-write a 10-line python program. Instead, take out your favorite editor and\nwatch it solve the problem in less than a minute with 1400 state transitions!\n\nBut a simple naysayer may say, 'We already have vimscript! Why in God's name\nwould I want to use a Turing machine instead?' To that, we retort: our Turing\nmachine only uses normal mode. So you could theoretically just type in the\nprogram and then execute it without running a single script! No ex mode either!\nThis project proves that normal mode in Vim is as powerful as any computer!\n\nMerging your favorite intervals\n===============================\n\nGiven a set of sorted potentially overlapping open/close intervals, merge the\noverlapping intervals together.\n\nExample:\n```\n[[1, 5], [6, 7]] -\u003e [[1, 5], [6, 7]]\n[[1, 5], [2, 3], [5, 7], [12, 15]] -\u003e [[1, 7], [12, 15]]\n```\n\nRunning the Python Turing Machine: `make run`\n\nOpening the Vim Turing Machine without running it: `make open-vim-machine`\n\nOpening and then running the Vim Turing Machine: `make run-vim-machine`\n\nSo Vim did what? Wait. How does it even?\n========================================\n\nSo you run this program, and it works. Great! So what happened? Well the most\ncommon thing you're going to see is `y$@\"`. What this does is yank from the\ncurrent cursor to the end of the line and then executes the default register as\na macro. This allows us to encode motions in lines and then execute them. We\nthen chain lines together by ending lines with moving to a mark, or a search\nresult, and then yanking and executing that line.\n\nUsing that nifty trick, we begin by yanking the first line and executing it.\nThat then sets off our mark initialization. We then search for `_\u003csomeletter\u003e`\nand then mark that position with the corresponding letter. Generally the first\ninitial of whatever the thing we're marking is. Once everything is marked, we\nthen begin the state transitions.\n\nWe begin a state transition by executing a long command (located at `_n:`)\nwhich jumps to the tape marker, yanks it, then jumps to the current state\nmarker, yanks that too, and then searches for some transition that contains both\nthe state and tape values. Once it gets to that line, it jumps to the command\nstring and then executes our trusty `y$@\"` to execute it. To make sure we keep\ntransitioning, each state transition ends with `` `ny$@ `` which tells it to jump\nto our \"next state\" marker and then execute it again, which kicks off the search\nfor the next state.\n\nThe execution halts when it can't find a new state to transition to. The state\nsearch includes an \"or\" operator where it will fall back to matching `---`,\nwhich tells it to print the current state and halt.\n\nMost transitions themselves involve changing a tape value or a state value and\nthen moving in some direction on the tape. Changing values consists of jumping\nto the tape or state marks (`` `t `` or `` `k `` respectively) and then using\n`cw` or `C` to change the value. We then move the pointer by jumping to the tape\nposition (`` `t ``) and then moving a word forward (`W`) or backward (`B`), and\nthen marking the new tape position.\n\nThe last real piece of complication is extending the tape. We're living in a\nworld with unlimited tapes! What a time to be alive! This is done through a\nseries of nifty hacks. First, we have a modeline that sets `whichwrap+b,s`. This\nallows us to move across line breaks and keep the tape all in the screen. Next,\nthe line directly under the tape contains a \"fake\" value that, when added to our\nstate search, will prevent it from matching any real state transitions and\ninstead match a \"transition\" for adding a line to the tape. This line tells us\nto jump to the end of the tape, and then insert a full line of empty values (we\nuse `X`), and then go back to our original tape location and execute the next\nstate transition!\n\nAnd there you have it! A simple `ggyy@\"` will kick off all of these sequences\nuntil execution completes. The cool thing is that this isn't special to the\nintervals problem. In fact, you can write your own state machine and use the\nprovided Vim adapter to create a new Vim machine to solve any problem that can\nbe solved by a Turing Machine!\n\nTo see some more details about various common commands, you can take a look at\n`vim_turing_machine/vim_constants.py`. That file contains some constants that\nare used repeatedly in the generated `machine.vim` file and their names are\nfairly descriptive. Also, if you'd like to step through manually, you can edit\nthe Vim machine in `vim_turing_machine/machines/vim_is_number_even.py` and tell\nit not to auto step and then step through manually using `y$@\"`.\n\nHappy hacking!\n\nDependencies\n============\n\nTo run this code, you will need `python3.6`, `tox`, and `vim` installed on your\nmachine. This code hasn't been tested on other versions of python3, but they'll\nprobably work if you change the pinned version in `tox.ini`. This code is not\npython2 compatible.\n\nContributors\n============\n\neliot and ifij wrote this project in July 2017 for Yelp's Hackathon 23. It was inspired by [vimmmex](https://github.com/xoreaxeaxeax/vimmmex): a Brainfuck interpretor written in Vim.\n\n[modeline]: # ( vim: set fenc=utf-8 spell spl=en textwidth=80: )\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fealter%2Fvim_turing_machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fealter%2Fvim_turing_machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fealter%2Fvim_turing_machine/lists"}