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

  • SEARCH
  • Home
  • 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 7598615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:27:08+00:00 2026-05-30T22:27:08+00:00

(NOT a possible duplicate of Swap text around equal sign :) Very often I

  • 0

(NOT a possible duplicate of Swap text around equal sign 🙂

Very often I find myself swapping things around. Which is a pain in the ass.

Let say just after I write this piece of code

tmp = realloc (words, sizeof (char **) * (*count + 1));

I notice there are just too many asterisks in a row, don’t like it, and want to swap the two factors around the multiplication asterisk.

Or, I write

#if !defined(_CONSOLE_H_) && defined (__MINGW32__)

but I suddenly realize that defined (__MINGW32__) must come first for some reason.

I think it would be cool if I could do something like this:

(On a character x, [x] indicate cursor position. <S> stands for this hypothetic “swap around” command)

#if [!]defined(_CONSOLE_H_) && defined (__MINGW32__)

command: vf&<S>$ => select from cursor to pivot (the word &&), and swap the selection around with the text till end of line.

Or, for the former example:

tmp = realloc (words, [s]izeof (char **) * (*count + 1));

command: v3f*<S>f) => select from here to third *, swap with text forward to ).

For me, it would be incredibly useful. Is there something like this out there, or I have to write my own plug-in?

Thanks!

EDIT –

As @ib. says in the comments to his answer, I need to be more specific as to what is the pivot.

The pivot could also be a character, for example here:

static char ** tokenize_input (char * input, PDWORD count);

I may want to swap the two arguments around the ",". More precisely, the ", ".

So maybe I’ll need two commands:

<s> - char-wise - the pivot is the last character of the selection;
<S> - word-wise - the pivot is the last word of the selection.

Thanks!
(ps. what about the last Word? 🙂

  • 1 1 Answer
  • 0 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-30T22:27:10+00:00Added an answer on May 30, 2026 at 10:27 pm

    This seems to work here, let me know how it does:

    function! Swap(...) "{{{
      let start_v = col("'<")
      let end_v = col("'>")
      let mv = ''
      let isMv = 0
      while !isMv
        let char = s:GetChar()
        if char == '<Esc>'
          return ''
        endif
        let mv .= char
        let isMv = s:IsMovement(mv)
        echon mv."\r"
      endwhile
      if isMv == 2
        return ''
      endif
      exec "normal! ".end_v.'|'.mv
      let lhs = '\%'.start_v.'c\(.\{-}\S\)'
      if !a:0
        let pivot = '\(\s*\%'.(end_v).'c.\s*\)'
      else
        let pivot = '\(\s*'.a:1.'*\%'.(end_v).'c'.a:1.'\+\s*\)'
      endif
      let rhs = '\(.*\%#.\)'
      exec 's/'.lhs.pivot.rhs.'/\3\2\1/'
    endfunction "Swap }}}
    
    function! s:GetChar() "{{{
      let char = getchar()
      if type(char) == type(0) && char < 33
        return '<Esc>'
      elseif char
        let char = nr2char(char)
      endif
      return char
    endfunction "GetChar }}}
    
    function! s:IsMovement(mv) "{{{
      let ft = a:mv =~ '^\C\d*[fFtT].$'
      let ft_partial = a:mv =~ '^\C\d*\%([fFtT].\?\)\?$'
      let right = a:mv =~ '^\d*[l$|;,]\|g[m$]$'
      let right_partial = a:mv =~ '^\d*\%([l$|;,]\|g[m$]\?\)\?$'
      if !right_partial && !ft_partial
        return 2
      endif
      return ft || right
    endfunction "IsMovement2Right }}}
    
    " Use last char as pivot. e.g.: the comma in the given example.
    vmap <silent> <leader>s1 :<C-U>call Swap()<CR>
    " Use \S\+ (WORD) as pivot. e.g.: &&
    vmap <silent> <leader>ss :<C-U>call Swap('\S')<CR>
    " Use \w\+ as pivot.
    vmap <silent> <leader>sw :<C-U>call Swap('\w')<CR>
    

    No need to press enter to specify the movement now. The ‘pivot’ always includes any surrounding whitespace and it can be defined with a single character class given as argument to Swap() in the mapping.

    If you want to see it highlighted, check https://gist.github.com/1921196

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I tell Linux not to swap out a particular processes' memory?
Possible Duplicate: Error: could not find function … in R Well, I am new
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
Possible Duplicate: Activity not started, its current task has been brought to the front
Possible Duplicate: Object reference not set to an instance of an object errors when
Possible Duplicate: Can not connect to Oracle via VBA - Driver's SQLSetConnectAttr Failed I
Possible Duplicate: cmake is not working in opencv c++ project I have a huge
Possible Duplicate: Why is the destructor not called for the returned object from the
Possible Duplicate: SmartGWT Dialog title not set correctly I have a problem, is that
Possible Duplicate: Mysql: Perform of NOT EXISTS. Is it possible to improve permofance? Is

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.