important vim commands

important VIM commands

Important VIM commands for daily usage

Important VIM commands is selected vim commands that every programmer shall have by heart.

By far important vim commands might be those we use in everyday programming life. But there more to it.

What is vim

Vim is a smart text editor for linux distros. It allows plugs ins for different usages. Basically, it pretty much knows most of programming languages you open with it.

Important vim commands will allow you to have a fast and productive usage of VIM while working on it.

Why should I use vim

You should use vim because it is cool. Really it is cool. Apart from being cool, it is light weight and almost available in most linux distributions.

Vim allows having third party plugins that will allow you to do multiple tasks from coloring to memory based copy and more.

Vim is programming language friendly. If you are working on java, it will highlight the keywords for you. Same for PHP or javascript or almost for lots of languages.

how it install vim

Usually VIM will come with most of the linux flavors:

If you are on Ubuntu installing vim on ubuntu will be
Continue reading important VIM commands

find and replace in vi vim

Search and replace in vim

Find and replace text strings in vim file

It is one of the most frequent task you might do while working on vim.

Here are some of the most used ones

1. Find and search a single string and replace the first occurrence only
:s/search/replace/g

The above code would search for “search” and replaces it with “replace” and it would do it only once

2. Find all occurrences of the string and replace those
:%s/search/replace/g

In this case all strings in the file with “search” would be replaced by “replace”

3. Find and ask for confirmation before changing it
:%s/search/replace/gc

It would do the usual task but this time it would ask for confirmation before it changes it.

You can do search and replace in vi or vim using the above command being on vim. Don’t forget to be out of the update mode otherwise you would just be writing the above commands.

Vim not syntax highlighting in sudo/root huh..

So I had to deal with the server issue and I ssh into it. Then opened the file looked at it and wanted to change the content, I had to be on root and I noticed the syntax highlighting was off..
Here are the steps I took to check what went wrong.
Basically when I am sudo-ing the user has changed a bit. So the configuration per that user is the area of focus.
Also, there could be multiple installations and vanilla versions for the vim as well, so check which one the sudo is using

sudo which vim

I was able to locate the right vim the sudo was using and I applied that one to fix the issue

:insert not working for pasting on Vim editor

I will not explain how useful vim is, if you a developer on the *nix systems, then that is number one tool to tuck into your toolbox.

Now you want to paste huge text into vim and it looks all wacky, and the insert mode is not handling it.. here is what you would do..

Open your vim with

vi filename.ext

then do

:set paste

This will allow your vim to be in the paste mode and you can dump all you have without any problem then change the mode using esc and save it as :w