structure bullets lists in org doc - emacs

I am working on editing the following text
3. Series
a. creating a series
- dict
- ndarray
- scalar
- lists
b. slicing
The desired edited result is
3. Series
a. creating a series
- dict
- ndarray
- scalar
- lists
b. slicing
Get it down with a cumbersome steps line by line
1) cursor on head of line a.creating a sereis, invoking C-2 space
2) cursor to head of next line, invoking C-u space
3) repeat step 2 to line -list
4) repeat step 1 to line b.slicing
Detoured by that, because the straightforward operations do not work
1) place cursor on front of line and invoke Tab, they stay still.
2) do batch operations to select them all then invoking C-2 space, also take no effects.
Is it possible to get the job done with an easy solution?

You can enable letters to be used as plain text lists in org-mode:
https://emacs.stackexchange.com/a/32743
Use M-RET when inserting elements and M- arrow keys for adjusting structure of the current item or region. (S-M- arrow keys to include nested items). Additionally, C-x TAB followed by arrows for manually adjusting indent of regions.

Related

VSCode select next occurrence of variable

In VSCode on Mac, I can use the keyboard shortcut Cmd + D to select the next occurrence of my currently highlighted text.
For example, if I highlight the variable order on line 1 in the below code, hitting Cmd + D causes order_form on line 2 to be partially highlighted, and hitting Cmd + D again causes order to be highlighted on line 3.
1. order = "Some string"
2. order_form = create_form()
3. return "Here is your order: " + order
However, I just want to select the actual variable order on lines 1 and 3 (i.e. excluding the text that is part of the variable order_form)
What keyboard shortcut can I use to just highlight the actual variables named order on lines 1 and 3?
The Ctrl+D functionality uses the current Find widget settings "behind the scenes" - whether that Find widget is visible or not.
So you would get the behaviour you want if the Whole Word option was enabled in that Find widget first before you began Ctrl+D'ing.
Alternatively, as the demo below shows when you place your cursor on the word you want order you can then hit Alt+W which will toggle the Whole Word option on and off. Note the little box that opens in the top right of the editor that shows only the Find options.
Then all your find next occurrences with Ctrl+D will find only what you want with that Whole Word option still enabled.
If you want to skip any of those occurrences, you can use the command
Add Selection To Previous Find Match
editor.action.addSelectionToPreviousFindMatch
(which you would have to make your own keybinding for). Just trigger that command to skip the next possible match - so follow this order:
Ctrl+D on the first order
Alt+W to enable whole word matching
trigger the command Add Selection To Previous Find Match
Ctrl+D to select the next order
It sounds like a bit of a hassle but they are common commands to know - to skip the next match and to toggle Whole Word matching.
[That little box that opens with the Find options is a little glitchey in that it seems to sometimes also enable the case sensitivity option as well - which isn't a problem in your example.]

How to put cursor on every other line (on alternate lines)

How can I put cursor on every other line (on alternate lines).
For example, I want to put cursor on line 1,3,5,7....
How can I do that?
I know I can do that by AltClick. But there are too many lines and an easier way will be very helpful.
You can do this with a regex:
Find: ^(.*\n){1}.*$
With focus on the find input, hit Alt+Enter. It will select all those matches - every two lines. Or if focus is in the editor, hit Ctrl+Shift+L - it'll do the same thing.
Home to put cursor at beginning of those selections. (If you have spaces or tabs at the beginning of a line, just hit Home until you are at the beginning.)
UpArrow or DownArrow to move those cursors where you want.
Obviously this scales pretty easily:
Find: ^(.*\n){2}.*$ for every third line, ^(.*\n){3}.*$ for every fourth line, etc.
You can use the extension Select By and use the command Place cursor based on line number, uses boolean expression (selectby.lineNr)
In the expression box of the command type
(n-1)%2==0
If you want to limit the number of cursors add an extra criterion
(n-1)%2==0 && n<100
If you place the cursor on line 1 you can use
c+2k
Read the extension page for other possibilities
You can set key binding for often use expressions.
Edit
Feature suggestion by #blueray
In v1.8.0 I have added inselection.
If you want to limit the cursors to the current selection(s) you can use the expression
c+2k && inselection

Indent multiple lines in Emacs

I am looking for shortcuts or functions to add one tab to all lines in the selection. Also how to reduce one tab to all lines in the selection?
There are multiple references for this. But I could not find one that mimics use of tab and shift-tab on selected text as in regular editors like geany. There one can select multiple lines and then use tab or shift-tab to move text left and right till one finds it best.
I found C-x tab <left> or <right> : this moves all lines in the selection to left or right one space at a time. C-5 C-x tab move it 5 spaces but then stops. But I want these lines to move tab spaces at a time while keeping the selection so that I can repeat or undo the process. How can I do that?
Basically, I need a function which I can call after selecting some lines. It should:
Detect the selected lines
On pressing a key (say 1 on num pad) it should move selected text to left by 5 spaces (and keeping the selection)
On pressing another key (say 3 on num pad), it should move selected text to right by 5 spaces (and keep selection)
The function should end on pressing ENTER.
Can above ability be added to C-x tab shortcut, which works exactly like that (with left and right keys) but it moves selected text only one space at a time.
I am looking for shortcuts or functions to add one tab to all lines in the selection.
First select a region.
C-SPC [set-mark-command]
Select region of lines, with the mark at beginning of first line and the point at the beginning of last last line (or vice versa), and then
C-x r t [string-rectangle]
C-q TAB [quoted-insert]
I found C-x TAB <left> or <right>: this moves all lines in the selection to left or right one space at a time.
Did you see on option for hitting S-<left> and S-<right>? That should do it for you, Shift + Right, perhaps only depending on what mode you are in and whether indent-tabs-mode is enabled.
If you use evil-mode, you have the key > that indents the current line or the selection to one level, according to the mode. I don't know how to make it insert tabs. By a quick look at the documentation by keywords (C-h d indent tab RET) it looks like we have the variable indent-tabs-mode:
indentation can insert tabs if this is non nil
More generally, this doesn't seem to suit your requirements but nearly in that it helps on indenting multiple lines in a row and repeatedly: indent-tools (on melpa) (my toy). It's meant for indentation-based files (so yaml, python,…) and it gives an hydra (which helps to repeat the actions) with the commands: indent or de-indent the current block of indentation, the paragraph, etc, and the same to comment, delete, fold, and move around blocks of indentation.

emacs + vimpulse-visual-mode + "linewise" text selection

Is it possible to make visual-line-mode (one after pressing V from normal mode) conduct as if first mark was in the beginning of the first line of selection and second mark - end of the last line?
For an example, currently after V, j and M-x comment-dwim:
here<cursor>is a
simple example
becomes
here;; is a
;; simp
le example
whereas desired result is often:
;; here is a
;; simple example
Of course, one can write a wrapper for comment-dwim, but I suspect/hope that there is a more correct solution.
Thank you in advance.
Doesn't V (vimpulse-visual-toggle-line) already do that?
Linewise selection will select whole lines. (I use this all the time)
The behaviour you're talking about will occur if you're using v (vimpulse-visual-toggle-char).
comment-dwim calls comment-or-uncomment-region to perform the actual commenting on the marked region. There is no option to extend the region to beginning of the first line and/or end of the last line. You will have to write a wrapper or advice comment-or-uncomment-region to achieve the effect you want.

Swapping 2 columns with Emacs

I have 2 columns, separated by comma. How can I swap those columns with Emacs?
I have the following:
column 1,column2
x1,x2
y1,y2
f1,f2
and I want it like this:
column2,column 1
x2,x1
y2,y1
f2,f1
Use M-x query-replace-regexp and then:
\(.+\),\(.+\)
as replace regexp and
\2,\1
for replacement.
In Emacs, you need to escape grouping parentheses with \. So, above regexp would be usually written as
(.+),(.+)
which means that you want everything before comma in first group and everything after comma in second group.
\2,\1
means: write second group, then comma, then first group.
While you can apply techniques given by other people, you can also use the org-mode tables.
Once you convert the data into org-mode table, it is very easy to swap the columns by simple keystrokes. You can have M-x org-mode, select the region then do M-x org-table-convert-region, and then M- on the right most column. I am not sure, how to export the data as CSV, but that should be very easy for you with replace-regexp. This can be helpful: http://www.gnu.org/software/emacs/manual/html_node/org/Tables.html#Tables
Similar to the answer given by #darioo, type the following into the top of your buffer:
(query-replace-regexp "\\(.*?\\),\\(.*\\)" "\\2,\\1")
Then, put your cursor at the end of this line and press ctrl-x, ctrl-e.
You will have an interactive search-and-replace for which you press the space bar to make the change, and press ctrl-g to quit. If you press ! (exclamation mark) then the search will cease being interactive and take place on all matching text.
If you want to reverse the changes then press M-x (usually ESC followed by x) and type undo and press enter.
Emacs has a rectangular selection mode, see for example: http://emacs-fu.blogspot.com/2008/12/working-with-rectangular-selections.html
Even better, if you enable cua-mode, entering Ctrl-Enter will put you in rectangle selection mode that is very easy to use.
http://trey-jackson.blogspot.com/2008/10/emacs-tip-26-cua-mode-specifically.html
Use a macro !
Go to the first line of the buffer
Start recording a macro (F3)
Move to the beginning of the line (^a)
Search for comma (^s ,)
Transpose (M-t)
Move cursor down one line
Stop recording macro (F4)
Select the rest of the lines and:
M-x apply-macro-to-region-lines
UPDATE: This doesn't work properly if you have multiple words in a column. Looking for a more general solution...