CodeSamplez.com

Programming, Web development, Cloud Technologies

  • Facebook
  • Google+
  • RSS
  • Twitter
  • Home
  • Featured
    • C# Tutorials
      • LinQ Tutorials
      • Facebook C# API Tutorials
    • PHP Tutorials
      • CodeIgniter Tutorials
    • Amazon AWS Tutorials
  • Categories
    • Programming
    • Development
    • Database
    • Web Server
    • Source Control
    • Management
    • Project
  • About
  • Write
  • Contact
Home Development A Collection Of Frequently Used Vim Commands

A Collection Of Frequently Used Vim Commands

Rana Ahsan October 13, 2014 Leave a Comment


 A Collection Of Frequently Used Vim Commands    

I am not a hardcore Vim/Vi user. But this tiny piece of editor is very much helpful for certain cases, such as editing files on remote server instance while connected via terminal/ssh. Thus, I have occasionally used this whenever needed. However, I felt that, as I don’t use it very frequently, I often forget how to do a certain task in it and I need to google it every time I am in such situation. So, I decided to note down the commands whenever I use one and aggregate the vim commands, so that I can find it more quickly in one place if I forget in future. So, more or less this blog post is for my self reminder. However, if you are in a situation like me, you can bookmark this post and may be this can help you as well!

Entering To And Exit From Edit Mode:

If you want to write or modify something, its necessary to go into edit mode as by default its in read-only mode. To do so, just press ‘i’ to jump into edit mode and press ‘Esc’ to get out of edit mode.

i # edit mode
Esc # exit from edit mode

Most of the other commands below will assumes you are not in edit mode. So, make sure to be in that state before trying another command.

Show/Hide Line Number:

By default when vi open a file, there is no line number shown. If we need to show the line number for easy navigating purpose or so, the following command can help us achieving so.

#Show line number
:set number
#Hide line number
:set nonumber

Go To Specific Line Number:

If in some point, we need to navigate to a specific line number, which might be useful in case of a large file, the following command will be helpful.

:123

Search text:

If we need to search for a specific word/text, we can do it by entering the following commands:

/{text}
#(to navigate to next item)
n

Save a file with sudo command:

Sometimes, we forget to open a file as root or the owner, thus we open it as read-only, but later me decide to edit it. After making the changes, if you try to write the content with “:w”, it will fail because of the permission issue. Then, we will have to choose alternative way to write our changes instead of the painful “reverting->exit->open as owner/root, make the changes again->save” process. Use the command below:

:w !sudo tee % > /dev/null

delete all texts in vi:

To delete all contents of a file, or from current line to the end of the file, we can use the commands below:

shift v #to select current line
shift g #jump to eof
d  #delete texts

Or if you are trying to delete a smaller chunk, follow the selection procedure described below in copy/cut section and press ‘d’.

Copy-Cut/Paste:

Copy/Cut/Paste is also a frequently used operation we need while writing/editing a file. Here are the series of commands you will need to perform in order to successfully copy/cut something and paste them somewhere else while on vim editor.

# select starting point
v
//use arrows to move up/down/left/right
d #to cut 
#or 
y # to copy 
p #paste

Go To End Of File:

In case we are just reading a file which is large and our concerned area is only the end. You will most likely want to jump to the end of the file in that case. It’s easy as pressing capital ‘G’.

# go to end of file
G

Is Any Major Vim Command Missing?

Well, initially the list contains only the commands I remembered so far I need to use often. There might be others that you have in mind/use often to make your days easier. Let me know about those and I will add them to the above list.

Related

Filed Under: Development Tagged With: tips, vim

About Rana Ahsan

Rana is a passionate software engineer/Technology Enthusiast.
Github: ranacseruet

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Email Subscription

Never miss any programming tutorial again.

Popular Tutorials

  • How To Work With JSON In Node.js / JavaScript
  • PHP HTML5 Video Streaming Tutorial
  • How To Work With C# Serial Port Communication
  • LinQ Query With Like Operator
  • Facebook C# API Tutorials
  • LinQ To SQL Database Update Operations In C#
  • Using Supervisord Web Interface And Plugin
  • Tutorial On Uploading File With CodeIgniter Framework / PHP
  • Utilizing Config File In C#.NET Application
  • Getting Started With Smarty Template Engine

Recent Tutorials

  • Building Auth With JWT – Part 1
  • Document Your REST API Like A Pro
  • Understanding Golang Error Handling
  • Web Application Case Studies You Must Read
  • Getting Started With Golang Unit Testing
  • Getting Started With Big Data Analytics Pipeline
  • NodeJS Tips And Tricks For Beginners
  • Apple Push Notification Backend In NodeJS
  • Web Based Universal Language Translator, Voice/Text Messaging App
  • How To Dockerize A Multi-Container App From Scratch

Recent Comments

  • S. Chalisque on PHP HTML5 Video Streaming Tutorial
  • Armorik on Generate HTTP Requests using c#
  • iswaps on PHP HTML5 Video Streaming Tutorial
  • TAKONDWA on PHP HTML5 Video Streaming Tutorial
  • rorenzo on PHP HTML5 Video Streaming Tutorial

Archives

Resources

  • CodeSamplez.com Demo

Tags

.net apache api audio aws c# cache cloud server codeigniter deployment doctrine facebook git github golang htaccess html5 http image java javascript linq mysql nodejs oop performance php phpmyadmin plugin process python regular expression scalability server smarty ssh tfs thread tips ubuntu unit-test utility web application wordpress wpf

Copyright © 2010 - 2022 · CodeSamplez.com ·

Copyright © 2022 · Streamline Pro Theme on Genesis Framework · WordPress · Log in