{"id":18034696,"url":"https://github.com/yuanqing/vim-basics","last_synced_at":"2025-10-04T02:30:21.195Z","repository":{"id":25825129,"uuid":"29264388","full_name":"yuanqing/vim-basics","owner":"yuanqing","description":":v: Just the basics to get you up and running with Vim","archived":false,"fork":false,"pushed_at":"2021-01-30T07:42:29.000Z","size":14,"stargazers_count":143,"open_issues_count":1,"forks_count":40,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-22T20:52:12.667Z","etag":null,"topics":["cheatsheet","vim"],"latest_commit_sha":null,"homepage":"","language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuanqing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-14T20:33:30.000Z","updated_at":"2025-07-12T22:58:50.000Z","dependencies_parsed_at":"2022-07-27T05:32:15.673Z","dependency_job_id":null,"html_url":"https://github.com/yuanqing/vim-basics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yuanqing/vim-basics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fvim-basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fvim-basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fvim-basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fvim-basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuanqing","download_url":"https://codeload.github.com/yuanqing/vim-basics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fvim-basics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278254766,"owners_count":25956672,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cheatsheet","vim"],"created_at":"2024-10-30T11:13:26.395Z","updated_at":"2025-10-04T02:30:20.868Z","avatar_url":"https://github.com/yuanqing.png","language":"Vim script","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vim Basics\n\n\u003e Just the basics to get you up and running with [Vim](https://www.vim.org)\n\n- [Quick start](#quick-start)\n- [Commands](#commands)\n- [Settings](#settings)\n- [The `\u003cCtrl\u003e` + `z` “problem”](#the-ctrl--z-problem)\n- [See also](#see-also)\n\nThis guide assumes some familiarity with the terminal. (See [Unix Basics](https://github.com/yuanqing/shell-basics/blob/master/README.md#readme) for a quick overview.)\n\n## Quick start\n\n1. Launch Vim via the terminal:\n\n    ```sh\n    $ vim Main.java\n    ```\n\n    You are now in Vim’s ***Command*** mode.\n\n    (You should see the contents of `Main.java` if the file already exists. Otherwise you will see an empty text editor window.)\n\n2. You cannot type into or edit your file while in ***Command*** mode. To start typing into the file, you must switch to Vim’s ***Insert*** mode. Press `i` to do so. You should see \u003ccode\u003e--\u0026nbsp;INSERT\u0026nbsp;--\u003c/code\u003e on the bottom-left hand corner of your window. Now you can type as you would with any other text editor.\n\n3. When you’re done typing, press `\u003cEsc\u003e` to go back to ***Command*** mode. (The `\u003cEsc\u003e` key is your friend! Hitting `\u003cEsc\u003e` will bring you back to ***Command*** mode.)\n\n4. And… that’s about it, really! Now type `:w` and `\u003cEnter\u003e` to save the file, followed by `:q!` and `\u003cEnter\u003e` to quit Vim.\n\n## Commands\n\nAlmost all operations in Vim occur while in ***Command*** mode. Listed here are the more important commands that you should know.\n\n### Switching between ***Command*** and ***Insert*** mode\n\nAction | Keys\n:--|:--\nSwitch to ***Command*** mode | `\u003cEsc\u003e`\nSwitch to ***Insert*** mode | `i`\nSwitch to ***Insert*** mode, moving the cursor to the end of the current line | `A`\nSwitch to ***Insert*** mode, adding a new line under the current line, and moving the cursor to the new line | `o`\n\n### Moving the cursor around the file\n\nAction | Keys\n:--|:--\nPage up | `\u003cCtrl\u003e` + `u`\nPage down | `\u003cCtrl\u003e` + `d`\nMove the cursor to the next word | `W`\nMove the cursor to the previous word | `b`\nMove the cursor to the start of the current line | `0`\nMove the cursor to the end of the current line | `$`\nMove the cursor to a particular line of the file (eg. line number 9) | `9G`\n\nOf course, you can also move the cursor using any of the arrow keys (\u003ccode\u003e\u0026uarr;\u003c/code\u003e, \u003ccode\u003e\u0026darr;\u003c/code\u003e, \u003ccode\u003e\u0026larr;\u003c/code\u003e, \u003ccode\u003e\u0026rarr;\u003c/code\u003e), but it will be a lot faster to use the above commands.\n\n### Delete/cut\n\nAction | Keys\n:--|:--\nDelete the line under the cursor | `dd`\nDelete the word under the cursor | `dw`\nDelete the character under the cursor | `x`\n\nBecause whatever you delete is copied into Vim’s clipboard, these 3 commands are akin to performing a cut.\n\n### Copy and paste\n\nAction | Keys\n:--|:--\nCopy the current line | `yy`\nCopy a particular number of lines, starting from the current line (eg. 3 lines) | `3yy`\nPaste | `p`\n\nYou can also specify the text to be copied using a text selection. It is a bit more involved, though:\n\n1. While in ***Command*** mode, press `v` to switch to ***Visual*** mode. You should see \u003ccode\u003e--\u0026nbsp;VISUAL\u0026nbsp;--\u003c/code\u003e on the bottom-left hand corner of your window.\n2. [Move the cursor](#moving-the-cursor-around-the-file) to adjust the text selection.\n3. When you have selected the text that you want to copy, press `y`. This will bring you back to ***Command*** mode, and the selected text will have been copied into Vim’s clipboard.\n\n### Undo and redo\n\nAction | Keys\n:--|:--\nUndo | `u`\nRedo | `\u003cCtrl\u003e` + `r`\n\n### Fixing code indentation\n\nAction | Keys\n:--|:--\nFix the code indentation of the file | `gg=G`\n\n### Save and quit\n\nAction | Keys\n:--|:--\nSave the file | `:w` then `\u003cEnter\u003e`\nSave the file then quit | `:wq` then `\u003cEnter\u003e`\nQuit without saving the file | `:q!` then `\u003cEnter\u003e`\n\n## Settings\n\nThese are some of the commands to customise the display:\n\nAction | Keys\n:--|:--\nEnable syntax highlighting | `:syntax on` then `\u003cEnter\u003e`\nEnable line numbers | `:set number` then `\u003cEnter\u003e`\n\nVim will look for a settings file named `.vimrc` in your home directory. You can avoid having to type the above settings for every new Vim session by putting the following in your `~/.vimrc`:\n\n```viml\nsyntax on\nset number\n```\n\n## The `\u003cCtrl\u003e` + `z` “problem”\n\nRemember that the command for undo is simply `u`, *not* `Ctrl` + `z`!\n\nIf you’d accidentally pressed `Ctrl` + `z`, you will find yourself back in your terminal, where you will see something like the following:\n\n```sh\n[1]+  Stopped                 vim Main.java\n```\n\nA quick fix is to issue the `fg` command:\n\n```sh\n$ fg\n```\n\nThis will bring us back to Vim, and all is well with the world.\n\n(Explanation: Pressing `\u003cCtrl\u003e` + `z` [places the currently-running program in the background](http://en.wikibooks.org/wiki/A_Quick_Introduction_to_Unix/Job_Control#Controlling_Jobs_in_Unix). Here, the currently-running program is Vim. The `fg` program simply brings the most recent “backgrounded” program back to the foreground.)\n\n## See also\n\n- [Shell Basics](https://github.com/yuanqing/shell-basics/blob/master/README.md#readme)\n- [Vim Commands Cheatsheet](http://www.fprintf.net/vimCheatSheet.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fvim-basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanqing%2Fvim-basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fvim-basics/lists"}