Saturday, February 22, 2020

10 most useful command in VI Editor in Unix

1) finding form up "/" for ClOrdID , use n and shift n for navigation.
2) finding form bottom "?" looking for Execution Report 35=R
3) find and replace
Vi Replace Command

One other shortcut that might be worth mentioning is that 1,$ and % both indicate all the lines in the file. Therefore,

    :1,$s/search_string/replacement_string/g
and

    :%s/search_string/replacement_string/g


How to remove ^M from unix files using VI editor

1) ^M is DOS line break charater which shows up in unix files when uploaded from a windows file system in ascii format.
To remove this, open your file in vi editor and type
:%s/(ctrl-v)(ctrl-m)//g
and press Enter key.
Important!! - press (Ctrl-v) (Ctrl-m) combination to enter ^M character, dont use “^” and M.
2) Your substitution command may catch more ^M then necessary. Your file may contain valid ^M in the middle of a line of code for example. Use the following command instead to remove only those at the very end of lines:
:%s/(ctrl-v)(ctrl-m)$//g

3) In some flavors of vi (e.g. RedHat), vi does it for you with:
:set fileformat=unix

4) the simplest way is to use the command dos2unix

5) If you wan to use space in file name the inclose the name in between quotes

''

4) Seeing command history in Vim
5) saving data and quiting
6) Inserting data
7) deleting data
8) cut copy past, pasting above line and below line
9) opening multiple file in VI and navigating between them
10) using ctrl+Z for suspending process
11) running bash commands from VI
12) Shortcut of keyboard  also work in VI editor  , like my favorite shortcut ctrl+w worked there.
Ctrl +R is act as Redo in VI editor.

VI mein agar yadi kisi directory ke name mein / hai aur wo aapko replace karna hai to usko escape kar do with \     e.g. \/ .
2.Abhijit told me how to open another rfile in VI and then navigate between that  ^filename for opening the file and then :e #1 , :e #2 for navigating the file , we did this before by opening five files together while doing CST morning check and then using  :n for navigating to next file.

Also for opening VI in readonly mode use the option  “VI –R “ option.
In VIM we can use :help for getting help or :help fixdel for a specifc thing.
How to execute shell commands inside vi ?
!command , or select an ara using V/v and hit ! and then type the command and the selected area will lbe deleted ,fed into the command and replaced with the output of the command.

If we are doing something in VI and wanted to go shell without closing the vi then we can use command “!sh” and go to the shell finish the work, do exit and comes back to vi. ! is used to execute shell commands from shell e..g !date.
• After doing ls –l abc.txt if you want to open abc.txt you can use vi !$ (last argument)

10 most useful VI shortcut
-----------------------------
CTRL + R -- Redo
yy -- yank
dd -- delete , 5dd
p and shift+P - Paste
5. how do you get visual block in VI , you can get the visual block by pressing ctrl+V and then use yy to copy the selcted block , it can be use to copy a region from VIM into the windows clipboard without using the mousse , V(move) + y or lower case v for sections of lines or Ctrl+v for blocks.
:e for opening a new file from inside VI
VI - R for opening a file in readonly mode.




No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.