SHELL

GVIM Commands

Admin
November 17, 2020
4 min read

GVIM commands and their usages

If you are working on Linux platform then you must have to use the VIM editor to open, read and edit a file. In VLSI we all work on Linux platform and have to deal with scripts which we run, log files which we get after script gets executed, report files from where we query the design status etc etc. Again, I hate doing manual efforts when I work so lets understand the commands which one can use while working with VIM editor.

  • If one file is opened and we need to open a file to compare with this, then use below command.

tabe gvim <filename.tcl>

  • If you have opened the gvim and want to replace some string, then use below command.

:%s/old_string/new_string
:%s/old_string/new_string/g
:%s/old_string/new_string/gc

Here “g” represents the replacement and “c” represents conditional replacement.

  • If you want to append a string at all the lines in the file, open gvim and use below command.

:%s/$/<String to be append>/g

  • If you want to prepend any string at the beginning of all lines present in the file, then use below command.

:%s/^/<String to be append>/g

  • If you want to delete the lines other than a particular string, then use below command. This will delete all the lines in a file and will keep the lines contains ERROR.

:g!/ERROR/d

  • Simillar to above if you don’t want to keep lines which contains particular string then use below command. The difference between the above and below command is “!” sign.

:g/ERROR/d

  • If you have all the lines column and wants to change it to row, then use below command.

:%s/\n/ /

  • If one wants to split the file horizontally then use below command.

:sp file2.tcl

  • If one wants to split the file vertically then use below command.

:vsp file2.tcl

  • If one wants to show the line number, then use below command.

:su nu

  • If you want to hide the line numbers, then use below command.

:su nonu

  • If you want to jump at some particular line, then use below command.

:n

Where n can be any number.

Share the Article