Top List 100 Useful Vim Commands That You'll Need Every day

100 Useful Vim Commands That You’ll Need Every day

No matter whether you’re a sysadmin by profession or just an old school tech enthusiast like me, if you ever find yourself in love with the awe-inspiring Unix OS, chances are you’re gonna feel the need of a versatile terminal-based Linux text editor at one point or another. For today’s guide, we’ll keep our focus on Vim, considered the best by many, if not all, as the best Linux text editor or code editor ever. So, let’s just skip on all those holy wars among you Vim vs. Emacs pundits and just keep our eye’s on the 100 best Vim commands, today’s topic. Emacs fanatics, however, please don’t get upset, we’ll cover that extensible editor of yours definitely in some time future.

Vim Commands That Will Turn You into A Vim Guru


Below, we’re presenting the 100 most useful Vim commands that will come in handy during your time with Vim. As we’re aiming mainly to beginner Vim users, don’t get daunted all you seasoned Vim masters. This guide will not only enhance the Vim experience of new users but also prove to be a valuable reference to more mature users.

Linux Command Cheat Sheet for Exploring the Vim Modes


Before delving directly into the commands this guide is meant for, we want to draw your attention to Vim modes. Vim features two distinct modes, a command mode and an insert mode.

When you open Vim for the first time, you’re in the command mode. The command mode lets you navigate the screen, delete and copy text among many others. The insert mode on the other hand, as implied, lets users insert text into Vim’s console. You can use the ESC key to switch back to the command mode after finishing typing.

Vim commands

1. i

Pressing i in the console gets you to the insert mode. Now you can start typing your texts inside Vim. The text you type will appear in front of the cursor key.

2. a

It’s among another commonly used Vim commands you can use to insert text. The texts will be appended right after the cursor.

3. I

Want to place your texts at the beginning of the current line? The l command lets you insert text right at your desired location.

4. A

This is one of my favorite Vim commands to append text at the end of my current line. It also falls under those Vim commands used for inserting text.

5. o

Pressing the lowercase o creates a new line just after the current line you’re in.

6. O

The uppercase variant creates the new line before the current line.

7. gf

You can use this handy little command to open your files under the cursor.

8. gi

One of my most favorite Vim commands, gi restarts the insert mode in the last insert point you used.

9. wq

Typing in long strings of text doesn’t matter if you can’t save them for future usage. Enter the wq command in the command mode to save your file and exit Vim.

10. q!

Often you’ll find yourself in a position where you’re not satisfied with the texts you have typed and would like to close the editor without saving your contents. Entering q! in the command mode lets you do exactly so.

Vim Commands for Moving Around The Console


One of the foremost reason behind Vim’s ultra-fast user experience is its fast movement features. Vim features and supports numerous convenient Vim commands to make your life in front of the terminal blazing fast. Below are some of the most useful Vim commands for faster navigation.

vim-movement-commands

 

11. h

Use the h command to navigate to the left side of your Vim console. This is analogous to the left arrow of your keyboard.

12. l

The l commands help you navigate to the right and is a substitute for the right arrow key.

13. k

Use the lowercase k command to move upwards. Similar to the arrow up key.

14. j

The j command takes you to downward and is a substitute for the down arrow key.

The h j k l keys help you move across the screen much faster than the standard arrow keys. Prefix them with a number to get the most out of these Vim commands. So, for going down ten lines, instead of holding the key for a prolonged period of time, just type 10j. Mastering these passive Vim commands for navigation will enhance your productivity much faster.

15. H

This command takes the cursor at the topmost region of your screen.

16. M

It will put the cursor in the middle of your Vim screen.

17. L

The capital L puts the cursor at the end of the screen.

The H M L Vim commands come in handy whenever you want to get to an approximate portion of your console screen.

18. 0 or <HOME>

Entering either 0 or the <HOME> button will take you to the start of the line.

19. ^

This is among the most commonly used Vim commands to get to the first non-blank character in a line.

20. $

This command will take the cursor at the end of the current line.

21. b

The lowercase b command lets you move back by tokens.

22. w

This command helps you move forward by tokens.

23. B

The uppercase variant of b lets you move back by words.

24. W

This command will let you move forward by words.

A token is any sequence of digits, letters, or underscores; whereas a word is any non-blank sequence that is separated by whitespace.

25. ctrl+u

This Vim command is basically a Page Up command. However, it moves the screen by half and holds onto the current cursor position.

26. ctrl+d

The Page Down variant of the above command. Functions in the same way.

27. G

Prefix the G command with a number to jump directly to a specific line number. Suppose, if you have line numbering enabled and are writing a shell script, you can go to the 10th line by merely typing 10G.

28. #

Given, # is the number of a specific line, entering this command will take you to that line directly. It’s one of the most used Vim commands to jump from line to line.

29. “

This command (two back ticks) takes you wherever you just were.

30. )

You can go-to at the start of the following sentence with this command.

31. (

Go-to at the beginning of the earlier sentence.

32. }

Used for going to the beginning of the next text block.

33. {

Takes cursor at the beginning of the previous text block.

Vim Commands for Editing Texts


Vim combines a significant number of powerful yet flexible editing features that lets users edit their documents seamlessly while paving the path to a versatile workflow. The power of Vim comes from the fact that you can combine many of such Vim commands together to solve your custom needs. This section of the guide covers some elementary Vim commands used in everyday text editing. Continue reading to find out more useful Vim commands for editing.

favorite vim commands

 

34. yy

The yy command lets you copy an entire line. It’s something you’ll often employ during your time with Vim.

35. yw

This is one of the most widely used Vim commands for copying a word across the editor.

36. y$

One of my all-time favorite Vim commands, it gives users the ability to copy texts from the current position of the cursor to the end of a line.

37. v

The v command can be used to highlight a single character at a time in combination with the movement keys (arrows/ h j k l).

38. V

Almost the same as the above one, but instead of a word, this command will highlight an entire line.

39. p

You can paste the contents of your clipboard to the unnamed register with this handy little command.

40. d

This is among the most used Vim commands for deleting highlighted texts.

41. dd

Want to delete an entire line with a single Vim command? The dd command is specially created for this purpose.

42. dw

You can delete a single word pretty quickly with the dw command.

43. D

One of the most powerful Vim commands ever, the D command deletes everything from the current cursor location to the end of the line.

44. d0

This command is used for deleting everything from your cursor’s current position to the beginning of the line.

45. dgg

You can use this command to delete everything from your cursor’s current position to the beginning of the file.

46. dG

This command will wipe out everything from your cursor’s current position to the end of the file.

47. x

Use the x command whenever you need to delete a single character.

48. u

The u command is among the most widely used Vim commands for many to undo the last operation. Combining with a postfix allows users to undo multiple actions. So, u# undo’s the last # number of actions.

49. ctrl+r

Use the above command to redo the last undo operation.

50.  .

The dot (.) command is one of those useful Vim commands that decreases your workload significantly by repeating the last action whenever you need such functionality.

51. cc

You can use the cc command to change line(s) by clearing and entering the insert mode at the same time. The cursor is placed at the current level of indentation.

Useful Vim Commands for Replacing Texts


Apart from the generic command and insert modes, Vim has another mode called the visual mode. You can highlight and change a particular portion of your text document in this mode. But where’s the fun in that, huh? Using a select set of Vim commands can achieve you the same result, just a bit faster. Below are some of my favorite Vim commands for changing texts on the fly.

52. r

The r command is a pretty handy tool when it comes to changing a single character. Follow it with <char>, and it will change the current character under the cursor with <char>.

53. R

The capital R opens the insert mode, but instead of inserting texts, you can replace them with this command.

54. ~

The tilda(~) command is pretty useful when you need to change the case of a character in your document. Follow it with a number to flip that many characters.

55. t<char>

Enter t<char> to select up to but not including the next <char> on a particular line.

56. f<char>

Press f<char> to select up to and including the next <char> on a line.

57. i<char>

Want to select everything in between a set of parentheses or some other unique character? Type i<char> to select everything that sits between two consecutive <char>.

58. a<char>

This command is identical to the previous one but includes the <char> at both ends of text.

Most Used Vim Commands for Searching Through A Document


The searching functionality is of greater importance to any versatile Linux text editor. Vim offers exceptionally powerful commands for searching through a document. It’s one of the most powerful areas of this innovative text editor. Glance over the below Vim commands to search through your document effectively.

Vim Code Editor

59. /

The slash command is the single most used command for searching through huge text files in Vim. Just type / and follow it with the texts you want Vim to search for you and look out at the bottom corner of the console.

60. /\c

The \c option, when piped to the search (/) command, lets users search for texts in a case sensitive manner. Wise utilization of this command can save hours of hard work.

61. ?<pattern>

This is among the most useful Vim commands for searching previous texts for a given <pattern>.

62. n

The n command searches in the direction of your last search. Use this command if you know in which direction your search item is.

63. N

Almost identical to the above command, but searches in the opposite direction of your last search.

64. :%s/[pattern]/[replacement]/g

The above command utilizes regular expression for searching every occurrence of [pattern] and replaces it with [replacement] without asking for confirmation.

65. :%s/[pattern]/[replacement]/gc

Same as the previous command but asks for confirmation before replacing each instance of [pattern] with [replacement].

66. :s/[pattern]/[replacement]/g

Instead of replacing every single instance of [pattern] on your file, this Vim command will replace only those [pattern] that are in the current line with [replacement].

67. :bufdo /[pattern]

This is among those powerful Vim commands that let users search for [pattern] in every currently opened buffer. It will enhance your productivity and decrease search time significantly.

68. :g/string/d

This is among those useful Vim commands that will come in handy whenever you want to delete every line that contains string from your document.

Linux Command Cheat Sheet for Working With Multiple Files in Vim


Editing in the terminal is fun and alright. But, where’s the edge of terminal editors if you can’t edit multiple files with them. Luckily, as an iconic text editor, Vim lets you work with multiple documents in a pretty neat way. The ability to split the screen when working with multiple files at the same time is something Vim has been offering even before the concept of the split screen became mainstream. Now, you should slowly start to realize why this legendary editor is hailed in such high regards.

vim editor

69. :sp [filename]

Use this command to create a new file and split the console screen horizontally in order to show the two different buffers.

70. :vsp [filename]

The functionality of this Vim command is, in essence, identical to the above command, but instead of splitting the console horizontally it splits the screen vertically.

71. :bn

This Vim command will switch your editor to the next buffer. It’s among those few fundamental Vim commands without which you won’t be able to work with multiple documents in Vim.

72. :bp

Identical to the earlier command, but switches to the previous buffer instead of going next.

73. :bd

Use this Vim command when closing a specific buffer. Make sure to save your data using appropriate Vim commands.

74. :ls

This is one of the handy Vim commands that will present users with a list of all open buffers.

75. ctrl+ws

If you want to split your Vim windows horizontally, then this is the command you’re looking for.

76. ctrl+wv

Instead of splitting the windows horizontally, this Vim command will split it vertically.

77. ctrl+ww

Utilize this command to switch between multiple windows directly from the command mode.

78. ctrl+wq

You can use this handy Vim command to quit a particular window.

79. ctrl+wh

This command will move the location of your cursor to the left window.

80. ctrl+wl

Same as the previous command, but instead of moving the cursor left, this command will point to the right window.

81. ctrl+wj

Use this command whenever you want to move a window beneath your existing one.

82. ctrl+wk

Same as above, but takes the cursor to the window above the current one.

Useful Vim Commands When Working With Multiple Tabs


Vim offers a variety of Vim commands to open and navigate a plethora of tabs right from the terminal. You can use these useful Vim commands whenever you are working with multiple files simultaneously. We encourage new Vim users to glance over such commands as they will often come in handy after you’ve mastered the basic Vim commands and start to do heavyweight staffs with it.

vim commands in action

 

83. :tabnew

You can use the :tabnew command to create a new tab and work with some other document while not leaving the current file.

84. gt

The gt command will show you the next tab opened by you.

85. :tabfirst

The above command will show you the first tab you’ve got opened in a particular session.

86. :tablast

Same as the previous command, but instead of showing the first tab it will show the last tab.

87. tabm n(position)

This powerful Vim command will come in handy whenever you feel the need to re-arrange your existing tabs.

88. tabdo %s/foo/bar/g

You can utilize the above command whenever you want to execute a command in every opened tab at the same time.

89. :tab ball

This Vim command is one of my favorite Vim commands, and it puts each open files in tabs.

90. :new abc.txt

This is among those Vim commands that lets you open a new file named abc.txt in a new window without exiting the current document.

Miscellaneous Vim Commands


As Vim offers plenty of Vim commands, we are unable to cover every single one of them categorically. That’s why in this section we’ll overview some useful Vim commands that are used by veteran users for a wide array of purpose.

other Vim Commands

91. :w

Pressing this Vim command in the command mode saves your current document but do not exist the existing session.

92. :q

This command will exit the current session without saving your changes. Note that you will see the E37 error if you have unsaved changes in your document. In such scenarios, you need to override this command and use q! instead.

93. :help [command]

The help command performs a search operation on the command you’ve typed and shows relevant information on them right in the console.

94. :e [file]

This command will open a file named [file] and create a new one if it doesn’t exist in your filesystem already.

95. :w [filename]

Use this command to save your existing document directly into a new file named [filename].

96. :stop

Writing this command in the command mode will suspend your current Vim session. You can also do this by pressing ctrl+z at the same time.

97. :browse e

Use this command whenever you want to invoke the graphical file explorer from your Vim console.

98. :%!fmt

Writing this command will align each line of your current file.

99. !}fmt

Use this whenever you need to align all lines at the present position of your cursor.

100. :set autoindent

This is one of the most used Vim commands you will use during your time with Vim. It sets autoindent for your current session.

Ending Thoughts


Vim has reached to the massive popularity it enjoys today among veteran Unix users not only because of its powerful editing capabilities but also for the vast array of versatile commands it offers. Mastering such useful Vim commands is not a child’s play, and we strongly suggest you do not try to memorize each of them individually. Instead, try to pick a few commands you can use right away and apply those directly in your next editing session. Only by practically using them, you will be able to master these different Vim commands. Hopefully, this guide fulfills your intro to Vim and provides the insights you were looking for.

LATEST POST

linux camera software

21+ Linux Camera Software: IP, Webcam, CCTV & Security Camera Software

Linux is a strong open source platform where every type of necessary software tools are available for both the beginners and professionals. If you...
Top 10 Android Emulators for Linux To Enjoy Android Apps in Linux

Top 10 Android Emulators for Linux To Enjoy Android Apps in Linux

Since smartphone came into our life, it has been influencing almost every spectrum of our socio-cultural movements. As a Linux power user, being able...
fractal software

Best 15 Fractal Software for Linux For Beginners and Professionals

Are you seriously seeking to know about some fantastic fractal software for Linux? It may seem to be a common and normal thing to...

MOST COMMENTED

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Choosing the best platform - Linux or Windows is complicated. Because both the system is versatile and capable of doing many mission-oriented and regular...
Most Stable Linux Distros

Most Stable Linux Distros: 5 versions of Linux We Recommend

At the very beginning, I would like to mention why the term ‘Stable’ comes in relation to Linux OS or distro. Because there are...
Best Things To Do After Installing Linux Mint

15 Best Things To Do After Installing Linux Mint 19 “Tara”

Linux Mint is one of the best Linux distros for newcomers, especially who comes from other Operating Systems like Windows and MacOS. Linux Mint...

Hand-Picked Related Post

LEAVE A REPLY

Please enter your comment!
Please enter your name here