Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swap items in comma separated list

Tags:

vim

Frequently, e.g. when I write Latex code, I come across the task to rearrange items of a list that are separated by commas. This is quickly done if both items are not at the at the beginning or the end of the list. But if they are at the margins, one has to take extra care of the separating comma.

As an example consider

\cite{GirR84, Tar00, Tem77}.

Is there a smart way in vim to put, e.g., the last item to the front or to the middle position?

like image 981
Jan Avatar asked Feb 06 '13 10:02

Jan


People also ask

How do you convert a list to a comma separated string?

Approach: This can be achieved with the help of join() method of String as follows. Get the List of String. Form a comma separated String from the List of String using join() method by passing comma ', ' and the list as parameters. Print the String.

What is a comma separated list example?

For example, C{:,1} is a comma-separated list if C has more than one row. A comma-separated list is produced for a structure array when you access one field from multiple structure elements at a time.

How do I create a comma separated list in Excel?

Type the formula =CONCATENATE(TRANSPOSE(A1:A7)&",") in a blank cell adjacent to the list's initial data, for example, cell C1. (The column A1:A7 will be converted to a comma-serrated list, and the separator "," will be used to separate the list.)


1 Answers

I actually made a plugin to deal with a similar situation called argumentative.vim. (Sorry for the plug.)

Argumentative.vim provides the following mappings:

  • [, and ], motions which will go to the previous or next argument
  • <, and >, to shift an argument left or right
  • i, and a, argument text objects. e.g. da,, ci, or yi,

So with this plugin you move to the argument in question and then do a <, or >, as many times as needed. It can also take a count e.g. 2>,.

If you have Tim Pope's excellent repeat.vim plugin installed <, and >, become repeatable with the . command.

like image 138
Peter Rincker Avatar answered Oct 10 '22 06:10

Peter Rincker