Install vim from source on CentOS

To install vim from source on CentOS server, run

This will install latest version of vim. You can start it with command

To get it work with “vi” command, i removed preinstalled vim editor with command

Now create a symlink with

Comment multiple lines in vim

To comment multiple lines in vim, first select the line in visual mode.

To change mode to visual mode, type

Now use j/k keys to select lines of text you need to comment.

To comment

To comment, use :norm command.

This will insert # to start of every line.

When you type :norm, in visual mode, you will see

Uncomment

To uncomment, select the lines in visual mode. Then run

this will delete first chars from every selected lines.

Method 2

You can use CTRL + V, this will select first char only.

To comment

1) Get into VISUAL_BLOCK mode by pressing CTRL + V
2) use j/k keys to select lines to comment.
3) Press SHIFT + I, now type #
4) Press ESC

To uncomment

1) Get into VISUAL_BLOCK mode by pressing CTRL + V
2) use j/k keys to select lines to comment.
3) Press x

Vim 8 goes Visual Mode on right click

Vim 8 shipped with Fedora 25 and Debian 9 when you mouse right click or use middle button to insert text to vim editor, it just go VISUAL mode.

This is because default changes in Vim 8.

Solution 1

The solution is to press SHIFT key before using mouse.

SHIFT + right mouse button = you will get paste option for copied text.

SHIFT + middle mouse button (press mouse wheel) = selected text will be pasted to vim.

SHIFT + INSERT = paste.

Solution 2

use vim.tiny, this can be activated by running

Example

Solution 3

Run command

to make this permanent, edit ~/.vimrc file, add

See vi