Is there a way to move an item together with underlying text in a structural way?
* Header
** Subheader
some text
I want to move Subheader together with some text in a structural way. So I tried M-UP/DOWN when I'm on Subheader but it only moves the Subheader not the "some text" as well.
Note: I prefer not to cut paste yank text as it's not structural.
There is org-cut-special (bound to C-c C-x C-w), org-copy-special (bound to C9c C-x M-w) and org-paste-special (bound to C-c C-x C-y):
they are analogous to Cut/Copy/Paste but they operate on subtrees.
Also, you might try looking at the Org menu when you are editing an org-mode file. The above commands and quite a few more are under the Edit structure menu.
Related
I am writing my own emacs cheat sheet.
So I want to copy function descriptions from emacs help.
For example, in this screen shot, I want to copy the "org-shifttab" function description:
The "pattern" field filters a list of functions.
Pressing TAB displays the description of the selected function.
But moving the yellow cursor out of the "pattern" field removes the display of the function's description.
How to copy the function's description to the clipboard?
I am running Emacs 25.2.1 on Fedora 25.
You have a *Help* buffer now with the contents that you're looking for. You can either press enter to go to that help buffer, or use C-x b to switch to it.
From there, you can mark and copy the contents of the buffer as usual (C-x h M-w).
Is there any tricky ways to do this: in my text files I have a list of words, one word a line. I want search the word new-word in the lists with C-s. In order to search it I need to type the word in the minibuffer, if the new-word isn't exist in the lists, I want to insert it in the list. It seems that I have to retype the word in the normal buffer, is there any ways to remember the word that I have just typed in the minibuffer and copy it into the normal buffer?
Pressing RET immediately after C-s allows you to input the string using the normal minibuffer prompt which supports editing and history of past searches. In that mode you can use the regular buffer commands, such as C-SPC, M-w and C-y, to copy contents from the search minibuffer and paste it into a regular buffer, or vice versa.
In Emacs, a user would usually copy/cut text as follows:
Move the cursor to the beginning of the text to be copied/cut with one of the move-cursor commands (e.g. C-p, C-n, C-f, C-b, M-f, M-b, etc.)
Set a mark with C-spacebar (in Emacs this command is also called set-mark)
Move to the end of the text to be copied/cut using move-cursor commands.
Copy M-w or Cut C-w the text from the mark to the current cursor location
Move the cursor to the place where the copied/cut text is to be inserted
Paste the text with C-y
Starting in R2009a, MATLAB supports customizable keyboard shortcuts, including a pre-defined Emacs layout.
My question is: Does MATLAB support a set-mark command such as C-spacebar (step 2. above)?
Thanks
No, MATLAB currently doesn't support set-mark.
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...
I want to select or highlight a block in Emacs without using the mouse, but doing it from the keyboard like Vim's visual mode. What is the easiest way to do this from a keyboard?
If I understand the question correctly, it is not about rectangular regions originally.
C-Spc puts a mark at the current position.
Wherever your cursor is afterwards, the text between the last mark and the current position is "selected" (you can highlight this by activating transient-mark-mode, but this will also mean that marks have to be deleted when you don't want highlight).
You can operate on that region with commands like:
C-w . . Kill region. This deletes and puts the region into the kill ring.
C-y . . Yank. This inserts the last snippet from the kill ring.
M-y . . Cycle kill ring. Immediately after C-y, this replaces the yanked part by the other snippets in the kill ring.
M-w . . Save region into kill ring. Like C-w, but doesn't delete.
This is just the basic usage. Marks have other uses, too. I recommend the tutorial (C-h t).
Take a look at region-rectangle in Emacs.
In short, you start selection like usual with Control-Space, then kill region with Control-x r k and paste (or yank) killed block with Control-x r y.
Emacs 24.4 now has rectangle-mark-mode. Use Ctrl + X, Space to invoke it.
Although C-SPC is a common way to start marking something from
wherever your point is, there are often quicker/easier ways that don't
involve explicitly moving to start/end points...
Built-in selection shortcuts
M-h — an important means to mark a paragraph. A "paragraph"
often means a block of code.
C-M-h and C-M-# — for marking sexps and defuns,
respectively. This works for several languages, not just lisps.
hold down shift — another slick way to highlight during
movement. E.g., M-S-f selects forward a whole word. This is
shift-select-mode,
and it is enabled by default in Emacs 24+. On some (non-chiclet)
keyboards, you should be able to hold down C-S- with a single
pinky.
You can press any of these repeatedly to grow the selection.
There are also a few special ways to mark things:
C-x h — mark the whole buffer
C-x SPC — enter rectangle mark mode
(NOTE: use C-g often to cancel marking while
experimenting.)
Add-ons
There are a few add-on packages that improve selecting regions and
things. These are all play nicely together and fit different use
cases. Use them all!
expand-region:
Expand region increases the selected region by semantic units. Just
keep pressing the key until it selects what you want. C-= is a
recommended binding for it. Hit it a few times to get what you
need.
easy-kill: Use M-w and
a mnemonic to select different types of things, like words, sexps,
lists, etc.
zop-to-char:
Like zap-to-char, but provides nice selection and other
menu-driven actions.
diff-hl: Highlight uncommitted changed regions. Use diff-hl-mark-hunk to select/mark a hunk.
symbol-overlay: Select symbol at point with a keystroke (M-i). Then you can do other things with it, like copy, search, jump, replace, etc.
Use Control-Space to set a mark and move your cursor.
The transient-mark-mode will highlight selections for you. M-x transient-mark-mode.
You can setup Emacs to enable this mode by default using a customization. M-x customize-option RET transient-mark-mode.
... and in case you are using Ubuntu and Ctrl + space is not working for you: you need to clear the Intelligent Input Bus (IBus) "next input method" key binding, as in
run ibus-setup and change the key binding for
"next input method" to something else (or delete it entirely by
clicking the "..." button and then the "Delete" button).
The quote is taken from an answer to a Stack Overflow question.
To expand answer of Edin Salkovic, if you use CUA mode, you can use Ctrl + Enter to begin a visual block selection. There are plenty of shortcuts to control block selection described in the documentation of CUA.
With Emacs 25, simply press Ctrl + Space and then move your cursor wherever you want to highlight/select the region of text which interests you. After that, you may need these commands:
Ctrl + W for cutting.
Alt + W for copying.
Ctrl + Y for pasting.