• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • 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

CodeSamplez.com

Programming, Web development, Cloud Technologies

You are here: Home / Development / A Collection Of Frequently Used Vim Commands

A Collection Of Frequently Used Vim Commands

October 13, 2014 by Rana Ahsan Leave a Comment

vim tips

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.

Share If Liked

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)

You may also like

Filed Under: Development Tagged With: tips, vim

About Rana Ahsan

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

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,774 other subscribers

Follow Us

  • Twitter
  • Facebook

Top Posts & Pages

  • How To Work With JSON In Node.js / JavaScript
    How To Work With JSON In Node.js / JavaScript
  • PHP HTML5 Video Streaming Tutorial
    PHP HTML5 Video Streaming Tutorial
  • How To Work With C# Serial Port Communication
    How To Work With C# Serial Port Communication
  • Facebook C# API Tutorials
    Facebook C# API Tutorials
  • LinQ Query With Like Operator
    LinQ Query With Like Operator
  • Using Supervisord Web Interface And Plugin
    Using Supervisord Web Interface And Plugin
  • Get Facebook C# Api Access Token
    Get Facebook C# Api Access Token
  • Generate HTTP Requests using c#
    Generate HTTP Requests using c#
  • Getting Started With UDP Programming in Java
    Getting Started With UDP Programming in Java
  • Utilizing Config File In C#.NET Application
    Utilizing Config File In C#.NET Application

Recent Posts

  • Building Auth With JWT – Part 2
  • Building Auth With JWT – Part 1
  • Document Your REST API Like A Pro
  • Understanding Golang Error Handling
  • Web Application Case Studies You Must Read

Tags

.net angularjs apache api audio auth authenticatin aws c# cloud server codeigniter deployment docker doctrine facebook git github golang htaccess html5 http javascript jwt linq mysql nodejs oop performance php phpmyadmin plugin process python regular expression scalability server smarty socket.io tfs tips unit-test utility web application wordpress wpf

Footer

Archives

Follow Us

  • Twitter
  • Facebook

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,774 other subscribers

Copyright © 2023