Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:50:24+00:00 2026-05-14T05:50:24+00:00

Given the following code sample: uint8_t i, in, ni; i = in = 2;

  • 0

Given the following code sample:

uint8_t i, in, ni;
i = in = 2; ni = 1;
while (2 == i > ni) in++;

How can I replace i, in, and ni, respectively with either in, ni, and i or inni, inin, and nini using emacs, vi, *nix commands, or anything else?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:50:25+00:00Added an answer on May 14, 2026 at 5:50 am

    If I’m not mistaken, the solutions provided so far (using Perl and Vim) do not work correctly when any of the replacements is among the latter words to be replaced. In particular, none of the solutions works for the first example: “i” would be replaced with “in”, which would then be incorrectly replaced with “ni” and then back to “i” by the subsequent rules, while it should stay as “in”.

    The substitutions cannot be assumed independent and applied in succession; they should be applied in parallel.

    In Emacs, you can do this:

    M-xparallel-replace,

    and at the prompt, enter

    i in in ni ni i.

    The replacements will happen between the cursor and the end of buffer, or in a region if one is selected.

    (Provided you have this definition in your ~/.emacs.d/init.el🙂

    (require 'cl)
    (defun parallel-replace (plist &optional start end)
      (interactive
       `(,(loop with input = (read-from-minibuffer "Replace: ")
                with limit = (length input)
                for (item . index) = (read-from-string input 0)
                                then (read-from-string input index)
                collect (prin1-to-string item t) until (<= limit index))
         ,@(if (use-region-p) `(,(region-beginning) ,(region-end)))))
      (let* ((alist (loop for (key val . tail) on plist by #'cddr
                          collect (cons key val)))
             (matcher (regexp-opt (mapcar #'car alist) 'words)))
        (save-excursion
          (goto-char (or start (point)))
          (while (re-search-forward matcher (or end (point-max)) t)
            (replace-match (cdr (assoc-string (match-string 0) alist)))))))
    

    Edit(2013-08-20):

    A few enhancements:

    1. For the special case that only two items are given, perform a swap instead (ie, replace with each other);
    2. Ask for confirmation for each replacement in the same manner as query-replace.
    (require 'cl)
    (defun parallel-query-replace (plist &optional delimited start end)
      "Replace every occurrence of the (2n)th token of PLIST in
    buffer with the (2n+1)th token; if only two tokens are provided,
    replace them with each other (ie, swap them).
    
    If optional second argument DELIMITED is nil, match words
    according to syntax-table; otherwise match symbols.
    
    When called interactively, PLIST is input as space separated
    tokens, and DELIMITED as prefix arg."
      (interactive
       `(,(loop with input = (read-from-minibuffer "Replace: ")
                with limit = (length input)
                for  j = 0 then i
                for (item . i) = (read-from-string input j)
                collect (prin1-to-string item t) until (<= limit i))
         ,current-prefix-arg
         ,@(if (use-region-p) `(,(region-beginning) ,(region-end)))))
      (let* ((alist (cond ((= (length plist) 2) (list plist (reverse plist)))
                          ((loop for (key val . tail) on plist by #'cddr
                                 collect (list (prin1-to-string key t) val)))))
             (matcher (regexp-opt (mapcar #'car alist)
                                  (if delimited 'words 'symbols)))
             (to-spec `(replace-eval-replacement replace-quote
                        (cadr (assoc-string (match-string 0) ',alist
                                            case-fold-search)))))
        (query-replace-regexp matcher to-spec nil start end)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following MSDN sample code, why can't I define the Action delegate inline:
Given the following code below, how can I have it modified such that it
Given the following code, is there a way I can call class A's version
In the university we were given the following code sample and we were being
The following code was been given from our school as a sample for circular
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Given the following sample code: $(document).ready(function(){ $(:input).blur(function(){ alert(The input type is: ); //How would
I am using the following code to send a sample message from the content
Given this following sample code which clones a table row, sets some properties and
Given the following sample code; class Program { static void Main(string[] args) { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.