Commenting or Uncomment a Block of Text in Vi

- - posted in Technical | Tagged as vi,commenting,visualblock,vim,vieditor | Comments

Sometimes we do want to comment or uncomment a block of lines together in VI editor. I struggle sometimes, so here are some tips.

For Uncommenting a block of text is almost the same:

Put your cursor on the first # character, press `CtrlV (or CtrlQ for gVim)`, and go down until the last commented line and press x, that will delete all the # characters vertically.

For Commenting a block of text is almost the same:

* First, go to the first line you want to comment, press `Ctrl + v`. This will put the editor in the VISUAL BLOCK mode.
* Then using the arrow key and select until the last line and Now press `Shift + I` , which will put the editor in INSERT mode.
* Then press '#' character. This will add a hash to the first line.
* Then press Esc (give it a second), and it will insert a '#' character on all other selected lines.

For the stripped-down version of vim shipped with debian/ubuntu by default, type : s/^/# in the third step instead.

Reference: Stackoverflow





Gravatar of Ashwani Kumar

Recent posts


Subscribe



Your Feedback encourages me




Learning and Developments

One Month Rails



, 2FA, AWS AWS, Active Authenticator Directory, Facebook Flash, Forwarding, GOD,Chat,Coffee Github,Feedback,Repo Google Google,Search HAProxy, IOT, IP-block JQuery LetsEncrypt Load MQ MQTT, Messaging Octopress Octopress, OpenVpn OpenVpn, PI, Plugin Plugin, Port Raspberry, S3, SSH, Shell,Commands Soapui, Tag Tag, Tree, Tunneling XML XML, XServer, Xming ajax, angular, animated architecture architecture, azure balancing cloud, commenting, connectivity datapower datatables diagrams diaspora dropdown geocoding grep, hashicorp, ipaddress, ipv6, java, java,python mysql nokogiri, octopress-migration octopress-plugin oidc openapi, openssl powershell proxy rails, repo reviews ruby, script scripts, security, sharepoint shell spiffe spire spring springboot, ssh, swagger, telnet, vault vi, vieditor vim, visualblock, webattacks windows,cleanup windowsxp workload identity