Results 1 to 6 of 6

Thread: Search and replace in Vim

  1. #1
    Join Date
    Jul 2009
    Posts
    127

    Search and replace in Vim

    Hello all,

    I installed Linux operating system and I am getting some command related problem in one of the editor in Linux named Vim. how do you do a search and replace? I am unable to find it in the help menu and it's driving me nuts.

    If you all have any idea for vim, could someone walk me through it.Help would be appreciated.

    Many thanks

  2. #2
    Join Date
    Jan 2008
    Posts
    3,388

    Search and replace in Vim

    The vim is one of the powerful editor in Linux which is mostly used by system administrator.

    It is very typical to use to create the text files,the normal desktop user getting so much complexity to use it because it is fully dependent on the command line argument.Every operation are being started by the command,from writing to editing the file.

    The find and replace is also depends on the command based.To find the word and replace it ,you can use the command -

    :%s/s->/t->/g<CR>

  3. #3
    Join Date
    May 2008
    Posts
    4,085

    Search and replace in Vim

    The Vim editor uses the :s (substitute) command for search and replace operation .Using same operating systems, gvim contains the Find and Replace sub-menu in the Edit menu.

    The search operation is performed as follows-.

    /string - Search forward for occurrence of string in text
    ?string - Search backward for occurrence of string in text
    n - Move to next occurrence of search string
    N - Move to next occurrence of search string in opposite direction

  4. #4
    Join Date
    Apr 2008
    Posts
    3,267

    Search and replace in Vim

    Search and replace in Vim

    The :substitute command is used for searching the text pattern and you can replace with another text string using the slash in your command line argument.

    There are so many options can be passed with the command but I am going to list those which are commonly used for simple searching and replacing operation.

    :%s/Roll/pen/g

    The statement will Find each occurrence of 'Roll', and replace it with 'pen'.

    :%s/Roll/pen/gc

    The above will Change each 'Roll' to 'pen' before a message for confirmation.

  5. #5
    Join Date
    Apr 2008
    Posts
    3,522

    Case Search and replace in Vim

    During the search operation,You need only those string to search and replace which is exactly the same string that you entered for search.

    There are some relative advance command for that.You have to just put some advance options.One of the case sensitive matching example is given below -

    Code:
    :%s/\<word1\>/word2/gc
    :%s/word1/word2/gci
    :%s/word1/word2/gcI
    
    The first statement will change only whole words which is exactly matching 'word1' to 'word2' and then would ask you for confirmation.the second will change each 'word1' (case insensitive) to 'word2' with confirmation where as the third statement will do the same as second.

  6. #6
    Join Date
    Apr 2008
    Posts
    3,295

    Range Searching and replacing

    Range Searching and replacing

    The words in your file can be searched using the match in Vim editor.There are some few option for range searching and replacing the word contents of your file.The statement as a command would be as follow to search and replace the word.

    Code:
    :%s/foo/<c-r><c-w>/g
    It Replaces each occurrence of 'foo' with the word under the cursor.The option
    <c-r><c-w> specifies that you have to press Ctrl-R then Ctrl-W. The word under the cursor will be inserted whatever you typed it.

Similar Threads

  1. How to implement search and replace list in OpenOffice?
    By He_Man in forum Windows Software
    Replies: 7
    Last Post: 19-02-2012, 12:15 PM
  2. Noob question - phpadmin search and replace sql query - Please HELP
    By jackpotsoftware in forum Software Development
    Replies: 1
    Last Post: 18-10-2011, 04:00 PM
  3. Replies: 6
    Last Post: 08-06-2011, 11:36 PM
  4. Replies: 4
    Last Post: 24-05-2009, 11:13 PM
  5. cmd command search and replace
    By blindsleeper in forum Operating Systems
    Replies: 2
    Last Post: 27-11-2008, 03:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,255,342.27884 seconds with 17 queries