To speak of the Vim editor is to speak of MULTIPLE FACILITIES with simple keystrokes and useful commands. This Cheat Sheet is one of those to bookmark and consult whenever necessary.
|Use the h command to navigate to the left side of the Vim console. This is analogous to the left arrow on your keyboard.|
|Commands help you navigate right and replace the right arrow key.|
|Use the lowercase k command to move up. Similar to the up arrow key.|
|The j command takes you down and is a substitute for the down arrow key.|
|This command takes the cursor in the upper region of the screen.|
|Will place the cursor in the middle of the Vim screen.|
|The capital letter places the cursor at the bottom of the screen.|
|Entering 0 or the [HOME] button will take you to the beginning of the line.|
|This is one of the most commonly used Vim commands to get the first nonblank character of a line.|
|This command takes the cursor at the end of the current line.|
|The lowercase b command returns tokens.|
|This command helps you to advance through tokens.|
|The capital variant of b allows you to return by words.|
|This command allows you to advance by words.|
|This Vim command is basically a Page Up command. However, it moves the screen in half and keeps the current cursor position.|
|The Page Down variant of the above command works the same way.|
|Prefix G with a number to jump directly to a specific line number.Suppose that if you have line numbering enabled and are writing a shell script, you can go to line 10 simply by typing 10G.|
|Given, # is the number of a specific line, entering this command will take you directly to that line. It is one of Vim’s most commonly used commands to jump from one line to another.|
|This command (two ticks back) takes you where you were.|
|You can access at the beginning of the following sentence with this command.|
|Go to at the beginning of the previous sentence.|
|Used to go to the beginning of the next block of text.|
|Get the cursor at the beginning of the previous text block. Vim Commands for Editing Text|
|Pressing i on the console takes you to insert mode. Now you can start typing your texts in Vim. The text you type will appear in front of the cursor key.|
|There are other commonly used Vim commands you can use to enter text. Text will be appended right after the cursor.|
|Do you want to place your text at the beginning of the current line? The l command allows you to enter text directly at the desired location.|
|This is one of my favorite Vim commands for adding text at the end of my current line. It also fits the Vim commands used to enter text.|
|Pressing the lower case letter o creates a new line just after the current line you are on.|
|The uppercase variant creates the new line before the current line.|
|You can use this little command to open your files under the cursor.|
|One of my favorite Vim commands, gi restarts insert mode at the last insertion point you used.|
|Entering long text strings does not matter if you cannot save them for future use. Enter the wq command in command mode to save your file and exit Vim.|
|Often, you find yourself in a position where you are not satisfied with the text you typed and would like to close the editor without saving its contents. By typing q! In command mode, you can do just that. if by the console|
|The yy command lets you copy an entire line. This is something you often use during your time with Vim.|
|This is one of the most widely used Vim commands for copying a word in the editor.|
|One of my all-time favorite Vim commands offers users the ability to copy text from the current cursor position to the end of a line.|
|The v command can be used to highlight a single character at a time in combination with the arrow keys (arrows / hjkl).|
|This is one of the most commonly used Vim commands to delete highlighted texts.|
|Do you want to delete an entire line with a single command from Vim? The dd command is created especially for this purpose.|
|You can delete a single word quickly with the dw command.|
|One of the most powerful Vim commands of all time, the D command deletes everything from the current cursor location to the end of the line.|
|This command is used to delete everything from the current cursor position to the beginning of the line.|
|You can use this command to delete everything from your current cursor position to the beginning of the file.|
|This command erases everything from your current cursor position to the end of the file.|
|Use the x command whenever you need to delete a single character.|
|The u command is among the Vim commands most widely used by many to undo the last operation. Combining with a postfix, users can undo several actions. Then you undo the last number of actions.|
|Use the command above to redo the last undo operation.|
|The dot (.) Command is one of those useful Vim commands that significantly reduces your workload by repeating the last action whenever you need this functionality.|
|You can use the cc command to change lines by clearing and entering insert mode at the same time. The cursor is placed at the current level of indentation. Vim’s useful commands for replacing text|
|The r command is a very useful tool for changing a single character. Follow it with [character] and it will change the current character under the cursor with [character].|
|Uppercase OR opens the input mode, but instead of entering text, you can replace it with this command.|
|The tilda (~) command is very useful when you need to change the box of one character in your document. Follow it with a number to invert as many characters.|
|Type t [character] to select up to, but not including, the next [character] on a specific line.|
|Press f [character] to select up to and including the next [character] in a line.|
|Do you want to select everything between parentheses or another unique character? Type i [character] to select everything between two consecutive [characters].|
|This command is identical to the previous one, but includes the [character] at both ends of the text. Commands I came most commonly used to search in a document|
Search and Replacement
|The slash command is the most commonly used command to search large text files in Vim. Just type / and proceed with the text you want Vim to look for you and look at the bottom corner of the console.|
|The option, when directed to the search (/) command, allows users to search for case-sensitive text. Wise use of this command can save hours of hard work.|
|This is one of Vim’s most useful commands for searching previous texts for a given [pattern].|
|The n command searches in the direction of your last search. Use this command if you know which direction the search item is in.|
|Almost identical to the above command, but searches in the opposite direction to your last search.|
|The above command uses regular expression to search for all occurrences of [pattern] and replaces it with [replacement] without prompting.|
|Same as previous command, but prompts for confirmation before replacing each instance of [default] with [replacement].|
|Instead of replacing all instances of [default] in your file, this Vim command will only replace those [default] that are on the current line with [replacement].|
|This is one of Vim’s powerful commands that allows users to search for [pattern] in all currently opened buffers. This will increase your productivity and significantly shorten your search time.|
|This is one of the useful Vim commands that will be useful whenever you want to delete all lines containing string from your document. Linux Command Tips Sheet for Working with Multiple Files in Vim|
Screen Manipulation and Editing
:sp [filename]→ Use this command to create a new file and split the console screen horizontally to show the two different buffers.
:vsp [filename]→ The functionality of this Vim command is essentially identical to the above command, but instead of splitting the console horizontally, it splits the screen vertically.
:bn→ This Vim command will change its editor to the next buffer. It is among the few fundamental Vim commands without which you will not be able to work with multiple documents in Vim.
:bp→ Identical to the previous command, but switches to the previous buffer instead of advancing.
:bd→ Use this Vim command when closing a specific buffer. Save your data using the appropriate Vim commands.
:ls→ This is one of the useful Vim commands that will present users with a list of all open buffers.
ctrl+ws→ If you want to split Vim windows horizontally, this is the command you are looking for.
ctrl+wv→ Instead of splitting windows horizontally, this Vim command will split it vertically.
ctrl+ww→ Use this command to switch between multiple windows directly from command mode.
ctrl+wq→ You can use this useful Vim command to exit a specific window.
ctrl+wh→ This command moves your cursor location to the left window.
ctrl+wl→ Same as the previous command, but instead of moving the cursor to the left, this command will point to the right window.
ctrl+wj→ Use this command whenever you want to move a window below the existing window.
ctrl+wk→ Same as above, but takes the cursor to the window above the current one. Vim’s useful commands when working with multiple tabs
:tabnew→ You can use the: tabnew command to create a new tab and work with another document without leaving the current file.
gt→ The gt command will show you the next tab you open.
:tabfirst→ The above command shows the first tab you opened in a specific session.
:tablast→ Same as the previous command, but instead of showing the first tab, it will display the last tab.
tabm n(position)→ This powerful Vim command will be useful whenever you feel the need to rearrange your existing tabs.
tabdo %s/foo/bar/g→ You can use the above command whenever you want to execute a command on all open tabs at the same time.
:tab ball→ This Vim command is one of my favorite Vim commands and puts each open file in one [CODE]:tab ball`** .
:new abc.txt→ This is one of Vim’s commands that allows you to open a new file called abc.txt in a new window without leaving the current document.
:w→ Pressing this command Vim in command mode saves the current document, but there is no existing session.
:q→ This command exits the current session without saving your changes. Note that you will see error E37 if you have unsaved changes to your document. In such scenarios, you need to override this command and use q! instead.
:help [command]→ The help command performs a search operation on the command you entered and displays relevant information about them directly in the console.
:e [file]→ This command will open a file named [file] and create a new one if it no longer exists in your file system.
:w [filename]→ Use this command to save the existing document directly to a new file named [filename].
:stop→ Writing this command in command mode will suspend your current Vim session. You can also do this by pressing ctrl + z at the same time.
:browse e→ Use this command whenever you want to call the graphics file explorer from your Vim console.
:%!fmt→ Writing this command will align each line of your current file.
!}fmt→ Use it whenever you need to align all lines at the current position of your cursor.
:set autoindent→ This is one of the most commonly used Vim commands that you will use during your time in Vim. It sets autoindent for your current session. Final thoughts
Meet our Vim Moderno and Vimscript Course at Udemy. Although the classes are in the Portuguese language, Udemy offers automatic translation if you are interested. Link:
Thanks for reading!