Author Avatar

Shweta Singh

2

Share post:

No matter, what profile, a developer or a QA, we are working on or at what stage of software release we are contributing, changing or accessing the files in production is something we can never escape from. But does production environments have useful IDEs or any editor to make our life easier??

Even though I am a Front End developer and I could not escape from accessing the files even after deploying the build. Changing the files and testing if it will work always helps. Here comes, VIM, the editor which no matter how much we try, we cannot ignore it.

Here, without getting a lot deeper, I have tried to list down the most common and useful operations that we would like to do on a file,using VIM.

All commands starting with a colon(:) are used in Escape mode. i.e press escape key to go into the mode and then type command.

1. Open / Create a file in Vim

shwetas@dell:~ $ vi the-coders-stop.js 

2. Edit an opened file

Once File opened. Press i

This will open the file in edit mode. With insert mode displaying at the bottom.

INSERT implies edit mode is on

3. Jump to a line number in file

In esc mode, :[line number]

e.g. :1 for line number one or :100 for line 100

:3 will take the cursor to the line with closing curly brackets

4. Copy and Paste text in edit mode

Copy => Select text and press Ctrl + Insert
Paste => Shift + Insert

5. Delete number of lines from a point

Press esc and then [number of lines]dd  

e.g in esc mode, 200dd will delete the next 200 lines

cursor is at line 2, and typed 2dd, therefore line 2 and 3 gets deleted

6. Delete entire content of the file

In `esc` mode,

i) Jump to line number 1 using point 3. i.e :1
ii) Delete the maximum number of lines you think the file has using point 5.

e.g 2000dd

:1 followed by 10dd (since file doesn’t have more than 10 lines) deletes all content

7. Close an opened file without any unsaved changes

In esc mode, type :q

8. Close opened or the newly created file with the changes done

In esc mode, :wq

9. Close the opened file without the unsaved changes

In esc mode, :q!

10. Search a text

type /[the text] and press Enter.
Keep pressing n to go to next occurence and shift+n to the previous.
Searching hello word occurrences

Thanks for reading!! I hope it helps. Please share and leave your valuable comments and feedbacks below.

5 simple examples to understand Elasticsearch aggregation
Golang gRPC communication made easy!

Discussion

Leave a Reply