Alternatively you could put in specific line numbers (e.x. The “%” at the beginning tells it to match all lines.The first command finds the word “wibble” and puts two big arrows around it, not very useful but a good example: Lets look at this command: :% s/\(wibble\)/ -> \1 <- /g But did you know that it comes with regex support out of the box? Vim has an inbuilt stream editor, this enables you to modify lines in a quick and replicable manner. Manually this job would have taken half an hour, with Macros, just five mins. Quickly creating a macro that runs a search, go to next line, delete. I needed to delete the second key that matched the word “frank”. Simple to learn, but when you combine it with other commands, you can quickly build something amazing.įor example – I had a JSON blob containing a list of different SSH keys multiple times. Then to run the macro: # To run the "j" quickly re-run the last macro, you can double tap or just hold it. J # or any other character you want to trigger it Here’s how to start recording your custom macro: q # Start recording They are a sequence of Vim inputs and commands that you can re-run at the touch of a button. Macros are incredibly simple and just as powerful. You can also use visual block mode to quickly delete a large area of text. ctrl vĮnd # Move the cursor to the end of the line - This works even if the line endings are different lengthsĬtrl shift a # Enter append insert mode Vim has a much quicker approach using visual blocks: ctrl v # Enter visual block mode and using your arrow keys select all of the lines you wish to editĪ very similar method can be used to append text to lines. *tap**tap**tap**tap**tap**tap**tap* the sound of a colleague commenting out a code block. Phew I was worried I might need to leave vim for a second then. Of course if you already know the file name, just open it directly: :open filename Well you can get to that menu another way: :Exploreįrom this menu you can use your arrow keys to select and open up new files for editing. Have you ever accidentally opened a directory in vim? if you had, you would be pleasantly surprised that it creates a nice interface to find and start editing the file you meant. I assume you know the basics, If you don’t I recommend starting here. All of this means that a good text editor is a must. Here at Dogsbody Technology we are connected to servers, editing files and improving configs every day. This blog post lists out my top five Vim tips and tricks to bring your Vim game to the next level.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |