Sunday 9 July 2017

How to display or hide line numbers in vi or vim text editor

Background

Line number come in very handy when you are working with any Text Editor. However if you take vi or vim editor then line numbers are hidden by default. In this post we will see how we can turn it on.


How to display or hide line numbers in vi or vim text editor

This post assumes you are a vim user and are aware of basic usage. Like for example when you need to save and quit data in vim you-
  • press escape followed by :wq
or if you want to exit without saving
  • :q!
 vi support a lot of commands to use and  options to be set by using colon (:)

To show line numbers in vi simple type below are pressing escape -
  • :set number OR
  • :set nu
 To hide it you can type -
  • :set nu! OR
  • set nonumber





This you need to do every time you launch into vi editor. To make it default edit your file at location ~/.vimrc and append following line at the end -

  • set number
NOTE : You can create this file if it does not exist already.

Now you will always get line numbers when you launch vim editor.




 Now that we have seen how to hide and display line numbers in vim editor lets see how we can jump to a particular line in vim -

How to jump to a particular line in vim

This is also fairly simple. Once you have launched vim you can simply move to any line number using following command -
  • : linenumber
Eg.
  • :6


 You can ever jump directly to your line number immediately as you open vim. To do that use following command while opening vim -
  • vi +linenumber filename
Eg.
  •  vi +6 test.txt
This should open your file and move to the linenumber you have provided.


General Info

vim provides a lot of configurable options to set. To see them all type following command -
  • :set all

To see everything that you have set so far you can type following command -
  • :set
For me it is as follows -



Related Links

No comments:

Post a Comment

t> UA-39527780-1 back to top