From e89adb85ef969e305c9b50c957c051d696caf81d Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 3 Mar 2023 09:27:18 -0600 Subject: brought up to date --- bookmarks/vim reference document.txt | 763 ----------------------------------- 1 file changed, 763 deletions(-) delete mode 100755 bookmarks/vim reference document.txt (limited to 'bookmarks/vim reference document.txt') diff --git a/bookmarks/vim reference document.txt b/bookmarks/vim reference document.txt deleted file mode 100755 index 64353db..0000000 --- a/bookmarks/vim reference document.txt +++ /dev/null @@ -1,763 +0,0 @@ ---- -title: Vim Reference Document -date: 2011-11-30T17:55:52Z -source: http://www.jasondrury.com/ref_vim.php#navigate -tags: Vim - ---- - - -**Last updated:** Apr 27, 2013 - -  - -1. [Introduction][1] -2. [Navigation][2] -3. [Inserting][3] -4. [Deletion][4] -5. [Yanking/Putting][5] -6. [Searching][6] -7. [Substitution][7] -8. [Changing Case][8] -9. [Replacement][9] -10. [Marking][10] -11. [Spell Checking][11] -12. [Visual Mode][12] -13. [Miscellaneous][13] -14. [Files][14] -15. [Multiple Windows][15] -16. [Help][16] -17. [Keyboard Mappings -18. [Vimrc Files][17] -19. [Plugins][18] -20. [Vim as Python IDE][19] -][20] - -  - -_**Introduction**_ - -I have been using Vi/Vim for about 13 years now. I thought I knew most of what there was to know about Vim until this year when I decided to see what else I could do with Vim and wow, I didn't realize how little I was utilizing it's capabilities. This was primarily as a result of finding an article about using Vim as a Python IDE. I discuss this more in the [plugins][18] section. - -This is not an intro to Vim document. It is meant more as a reference document after you learn the basics. There are MANY websites and books available where you can learn vi. Here are one's that I recommend: - -1. Execute the command **vimtutor** on Linux for a very good introduction to Vim - - -2. Another two good built-in introduction to Vim documents:  **:help usr_02** and **:help intro** \- run these commands from within Vim. If you never navigated the Vim documentation before, there are some tips that I have [here][16] - - -3. [Learning the vi and Vim Editors][21] \- the best book available on the subject - - -4. [Swaroop CH's Byte of Vim][22] \- a very good introduction (plus more) to Vim. He also has a good intro to Python book if you are interested in that. - -This document does not include every single Vim command especially if they are very basic (ie. what the navigating commands "hjkl" do) nor more advanced Vim topics (ie. nothing on scripting at the moment). You can think of it as a Vim cheat sheet or user manual, but I feel it is much more then that which is why I am referring to it as a reference document. I have included the commands/capabilities that I often forget or that I feel may not be as well known to the casual Vim user. Also something that I have not seen on many other Vim related websites, I include the most common commands to the [plugins][18] as well as where to go for additional information on said plugins. I hate having to track down the help for a plugin that I only use occasionally. - -**Note1:** some of the commands are in ex mode. Make sure you notice if there is a colon (:) or not before a command. This makes a big difference. - -**Note2:** if a letter below is capitalize, then ensure you capitalized it when using it. - -**Note3:** below is the environment that I use Vim in. If you use something different, there may be some slight differences in the below commands/plugins: - -* Vim version: 7.3.154 -* Terminal: Gnome Terminal 3.0.1 -* Screen version: 4.00.03jw4 (FAU) 2-May-06 - -If you feel any of the content in this document is wrong or there is something that I should add, I would appreciate it if you would [contact me][23] and let me know. Thanks! - -  - -[[Table of Contents][24]] - -  - -  - -_**Navigation**_ - -I use the below scroll commands and record commands constantly. The record commands allow you to record a series of steps and then perform them again later on. I just learned about the move commands and I feel I will be using them more. See **:help motion** for more info on navigation. - -Scrolling: - -* Forward a full screen: **Ctrl-F** -* Backward a full screen: **Ctrl-B** -* Forward a half screen: **Ctrl-D** -* Backward a half screen: **Ctrl-U** -* Help:  **:help scrolling** -Record Commands: -* To turn recording on: **q<name of buffer>** \- I use "a, b, c, etc." for the name of my buffers -* To turn recording off (when you are done entering your commands): **q** -* To retrieve your buffer: **@<name of buffer>** -* See a list of your recorded commands (actually it includes all of your registers):  **:reg** -* Help:  **:help record** and **:help 10.1** -Move to -* Top line of screen: **H** -* Middle line of screen: **M** -* Last line of screen: **L** -* 5th line after the top line of screen: **5H** -* 5th line after the middle line of screen: **5M** -* 5th line before the last line of screen: **5L** -* First character of the next line: **+** -* First character of the previous line: **-** -* First nonblank character on the current line: **^** -* Beginning of sentence: **(** -* Beginning of next sentence: **)** -* Beginning of paragraph: **{** -* Beginning of next paragraph: **}** -* 5th line of the file: **5G** -* Last line of the file: **G** -* First line of the file: **gg** -* Return to the previous location you where just at: **``** -* Help:  **:help object-motions** and **:help various-motions** -In ex mode (when you type a colon ":" then a command), the following are shortcuts: -* Current line (not necessary to include the period "." It is assumed by default):  **:.** -* Last line:  **$** Every line:  **%** -* Next 10 things (things can be words, lines, etc and + means one, ++ means two, etc):  **+10** -* Previous 10 things:  **-10** -* Move lines 25 to the end of the file 5 lines above current line:  **:25,$m.-5** -* Display line numbers from the current line to the next 10 lines:.  **,+10#** - -  - -[[Table of Contents][24]] - -  - -  - -_**Inserting**_ - -* Append at the end of the word: **ea** -* Append at the beginning of a sentence: **Shift-I** -* Insert the character above: **Ctrl-Y** -* Insert text of file at the current cursor position:  **:r file** - -  - -[[Table of Contents][24]] - -  - -  - -_**Deletion**_ - -* Delete from the cursor to the end of the line: **D** -* Delete from the cursor to "pattern" going backwards: **d?pattern** -* Delete from the cursor to "pattern" going forward: **d/pattern** or **:/pattern/d** -* Delete the line below the line containing pattern:  **:/pattern/+1d** \- you can leave off the 1 because 1 is assumed by default but I find it clearer to keep it -* Delete from line containing pattern1 to line containing pattern2:  **:/pattern1/,/pattern2/d** -* Delete from the cursor to top of screen: **dH** middle of screen: **dM** and bottom of screen: **dL** -* Move the txt from current line to 1st line containing pattern and move to line after line 10:  **:.,/pattern/m10** -* Delete the next three lines and place into buffer named "b": **"b3dd** -* Put the contents of buffer named "b" after the cursor: **"bp** -* Delete lines 1-20:  **:1,20d** -* Delete from current line to end of file: **:.,$d** -* Delete all lines in file:  **:%d** -* Go through your deletion buffer: **"1pu.u.u** \- the "u" undoes the previous deletion and "." puts the next one - -  - -[[Table of Contents][24]] - -  - -  - -_**Yanking/Putting**_ - -Yanking and putting text is a very useful feature - -* Put before cursor: **P** -* Put after cursor: **p** -* Yank lines 1-10:  **:1,10y** -* Put the links you just yanked:  **:pu** -* Yank from the cursor to pattern going forward: **y/pattern** -* Yank from the cursor to pattern going backwards: **y?pattern** -* Yank current line into buffer "a": **"ayy** -* Put contents of buffer "a" after cursor: **"ap** -* Yank the next 5 lines into buffer "b": **"b5yy** -* Put contents of buffer "b" before cursor: **"bp** - -  - -[[Table of Contents][24]] - -  - -  - -_**Searching**_ - -* Search for string within a word boundary: **/\<string\>/** -* To find the next occurrence of a word (while you are positioned over it): * and # (backwards) -* To search for a word in reverse: **N** -* Turn on search highlighting:  **:set hlsearch ** -* Turn off search highlighting:  **:set nohlsearch ** -* Do not ignore case:  **:set smartcase ** -* Ignore case: **:set ic** -* The characters **.*[]^%/\?~$** have special meaning. If you want to use them in a search you must put a backslash (\\) in front of them. -* Go to first space character: **/\s** -* Do not start search from the top once it hits bottom:  **:set nowrapscan** -* Print all lines that contain "pattern":  **:g/pattern** -* Print all lines that do NOT contain "pattern":  **:g!/pattern/** or **:v/pattern** -* Get a list of your search history:  **q/** \- use Ctrl-c twice to exit this mode -Help:  **:help search** and **:help usr_27** - -Note, also look at the [substitution][7] section for more string matching options that you can also use when searching - -  - -[[Table of Contents][24]] - -  - -  - -_**Substitution**_ - -Vim's substitution capabilities are one of it's most powerful features. A few helpful notes before jumping into the examples: - -1. Many examples have the percent sign character '%' which means perform the change on the entire file. If this is not included the substitution works only on the current line (or a range of lines if you specify that). - - -2. The caret character '^' matches at the beginning of a line and the dollar sign '$' at the end - -Now for some examples: - -* Substitute y for every occurrence x in lines 1 through last:  **:1,$ s/x/y/g** -* Substitute y for every occurrence x in lines 50-75 through last:  **:50,75 s/x/y/g** -* To replace all occurrences of "hi" with "bye" in the current line:  **:% s/hi/bye/g** -* Replace all occurrences of "ACCEPT" with "DENY -i eth1": -  **:% s/ACCEPT/DENY -i eth1/g** -* To replace the text "red" with "blue", but only when red is the first word on the line:  **:s/^red/blue/** -* Remove anything that has the word "line" follow by a space, follow by one or more digits:  **:% s/line \d* //g** -* Remove a forward slash at the end of a line (notice you must backslash the forward slash): **0,$ s/\/$/** -* Substitute everything that has ".20" in it with ".200" on just line 16: -  **:16 s/.20\>/.200/g** -* Use "c" to be prompted to replace each substitution:  **:% s/hi/bye/c** -* Use "i" for for the match to be case insensitive: **:% s/hi/bye/i** -* Use "I" (uppercase "i") for for the match to be case sensitive (which is the default setting but you may want to use this if you set case insenstive searches in your .vimrc file "set ignorecase"): **:% s/hi/bye/I** - -One of the most powerful features of substitution is being able to use regular expressions. Below are some examples I have used: - -* Remove all word () and underscore characters (_). Note to match two different things, you need to use this format \\(pattern1\|pattern2\\):  **:% s/\\(\|_\\)//g** -* Remove all blank lines (regardless if they have any spaces "\s" and/or newlines " "): **:% s/\\(^\\( \|\s\\)*\\)//g** -* Delete anything that says "port /" (example: port 443/tcp or port 161/udp) **:% s/port\s\d*\/\\(tcp\|udp\\)//** - -You can find more examples here: -Help:  **:help substitute**, **:help 10.2**, or [Substitution on vimdoc][25] - -  - -[[Table of Contents][24]] - -  - -  - -_**Changing Case**_ - -This sections shows the different options to change the case of characters and words - - -* Use **g~** followed by any movement command to change the case to the opposite of what it currently is (aka "toggle"). Here are some examples: - * To the end of the line: **g~$** (ie. "GoodBye" will change to "gOODbYE" - * The next three lines: **g~2j** - * The next three characters: **g~3l** -* Use **gU** followed by any movement command to change any lowercase characters to uppercase. (ie. **gUw** will change "GoodBye" to "GOODBYE") -* Use **gu** followed by any movement command to change any uppercase characters to lowercase. (ie. **guw** will change "GoodBye" to "goodbye") -* Toggle the case of the current line: **g~~** -* Uppercase the current line: **gUU** -* Lowercase the current line: **guu** -* Lowercase an entire file: **:%s/.*/\L&/** or from the first line: **guG** -* Uppercase an entire file: **:%s/.*/\U&/** or from the first line: **gUG** - -Help: [Switching the case of characters][26] - -  - -[[Table of Contents][24]] - -  - -  - -_**Replacement**_ - -This sections deals with word and line replacement - -Change: - -* To the end of the line: **c$** or just **C** -* To the beginning of the line: **c^** or **c0** -* Just a single word: **cw** -* The next two words: **2cw** -* The previous word: **cb** -* The previous two words: **2cb** -* An entire line: **cc** or **S** -* From the cursor to the top of the screen: **cH** middle of screen: **cM** and bottom of screen: **dL** -* From the cursor to "pattern" going forward: **c/pattern** -* From the cursor to "pattern" going backwards: **c?pattern** - -  - -[[Table of Contents][24]] - -  - -  - -_**Marking**_ - -You can place an invisible marker in your file that you can reference later. Note, these are deleted once you close the file. - -* Leave a mark named "a" where the cursor is currently:  **ma** -* Move to the mark "a":  **`a** -* Move to the beginning of the line where the mark "a" is located:  **'a** -* Go to the previous location:  **Ctrl-o** -* Go to the next location:  **Ctrl-i** -Help:  **:help mark-motions** - -  - -[[Table of Contents][24]] - -  - -  - -_**Spell Checking**_ - -Yes, that's right, Vim has spell checking and it rocks! - -Here are the most useful commands: - - -* Enable spell checking:  **:set spell spelllang=en_us** -* Disable spell checking:  **:set nospell** -* For the misspelled word, suggest a replacement:  **z=** -* Repeat the replacement for the misspelled word for all matches:  **:spellr** -* Move to the next misspelled word:  **]s** -* Move to the next misspelled word, going backwards:  **[s** -* Add word to dictionary:  **zg** -* Remove a word from the dictionary: **zug** -If you are using my advanced .vimrc file, I mapped the following keys: -* Enable spell checking: **<F5>** -* Disable spell checking: **<F6>** -Help:  **:help spell** - -  - -[[Table of Contents][24]] - -  - -  - -_**Visual Mode**_ - -I just started using visual mode, but I really like it for certain things. My favorite use of it so far is to quickly indent or add comments to a block of code. - -**Note:** to get out of any visual mode, hit the <ESC> key and wait about 3 seconds. - -* Start visual mode:  **v** \- this works on a character basis, but when you move down it selects the entire line -* Start visual mode:  **V** \- this works on a line basis ( -* Start block visual mode:  **Ctrl-v** \- this is the most useful mode. It allows you to highlight just certain parts of the text using either the arrow keys or navigation keys -* Change while in block visual mode:  **c** \- this is used the same way as insert above, but you are changing the text you have highlighted. Just like insert, the changes do not reflect for all lines (just the first line) until you hit ESC key -* These are the options you have with highlighted text: - * Change the case of characters:   **~** (tilde symbol) - * Indent right:   **>** (greater then symbol) - * Indent left (un-indent):   ** (less then symbol)** - * Change text: **c** \- in block mode, the same things applies as the note I include below for insert mode - * Yank text: **y** - * Delete/Cut text: **d** (To paste text move cursor to desired location and use **P** to put text above the cursor or **p** for below - -For more examples, see:  **:help text-objects** - - -* Another very useful feature is the ability to insert while in _block_ visual mode:  **I** -Note: when inserting, what you are inserting will ONLY appear on the first line, but when you are done and hit the <ESC> key about 3 seconds later it should put what you inserted on every line you had selected -* Select the entire file (usefull when copying and pasting): **ggvG** -* Select from where the cursor is currently positioned to the end of file: **vG** -* Exit out of visual mode: **<Esc>** key -Help:  **:help visual-mode** - -  - -[[Table of Contents][24]] - -  - -  - -_**Miscellaneous**_ - -* You can create abbrevations. For exampele **:ab us United States** will allow you to just type "us" and it will be replaced with "United States." To disable the abbrevation type **:unab us** -* List all abbrevations **:ab** -* Enable the ability to use your mouse in xterm:  **:set mouse=a** \- note, this is enabled by default in my advanced vimrc file and you can toggle it on/off with Ctrl-m. The only reason I ever disable it is when I need to highlight text for copying and pasting. With mouse support enabled Vim goes into visual mode when you highlight text. -* Vim supports tab completion! Look at **:help ins-completion** and the "SuperTab" plugin in the [plugins section][18] -* You can view your command line history with:  **q:** (when in this window, press Ctrl-c twice to exit) -* In ex mode you can use a pipe to combine commands (just like a unix shell). The following commands will yank lines 2-4, move to line 7 and put the previous contents of lines 2-4, move to line 4, delete it, and the write the file:  **:2,4y | 7 | pu | 4 | d | w** -* View the contents of your registers/buffers:  **:reg** -* To repeat a colon command:  **@:** and to repeat it again:  **@@** -* To view current options:  **:set** -* You can also check any individual setting  **:verbose set ai?** \- verbose is optional, but it provides additional info (sometimes) -* To add a number to each line:  **:set nu** -* To turn off numbers:  **:set nonu** \- *note: if you are using my advanced .vimrc file, you can use <F2> to toggle line numbers on and off -* To temporarily disable any option:  **:set no