I tried to follow this to replace a character with newline in Spacemacs but that key combination replaced it with a space instead of newline.
How to replace a character with a newline in Emacs?
How can this be accomplished in Spacemacs?
It is supposed to work exactly the same with Spacemacs (C-q C-j will replace with a newline).
You can check if your keys are correctly mapped with the describe-key command (C-h k):
C-q runs the command quoted-insert
and
C-j runs the command electric-newline-and-maybe-indent (result with my Spacemacs)
Related
In every single other program I have ever used in the last 15 years across windows, osx and linux, I enter a tilde by pressing, the tilde key and then space. The Portuguese keyboard has a dedicated key for tilde where it is the primary character (no need for shift), it is used to compose ã and õ by pressing tilde then a or o. In emacs pressing tilde does nothing and posts "dead-tilde is undefined". How can I make emacs write a '~' when I press the '~' key in pt layout ?
Edit:
I think this is a better solution: It should match your experience in other applications where ~o gives õ and ~ followed by a space gives ~.
Tell Emacs you wish to use the portuguese-prefix input method. Interactively, you can do M-x set-input-method RET portuguese-prefix RET. To make this permanent, add something like this to your config file:
(set-input-method 'portuguese-prefix)
Original answer:
self-insert-command doesn't seem to work well with dead keys.
Try this instead:
(defun my-insert-tilde ()
(interactive)
(insert "~"))
(global-set-key (kbd "<dead-tilde>") #'my-insert-tilde)
add
(require 'iso-transl)
to Emacs init file (init.el). With this line tilde+space prints a tilde, and tilde+a prints ã.
This seems to be due to "Emacs and some input method managers (ibus and SCIM) don’t work together".
The emacs docs for C-m key (ie. C-h k C-m) displays the following
newline is an interactive compiled Lisp function in `simple.el'.
(newline &optional ARG)
Insert a newline, and move to left margin of the new line if it's blank.
If `use-hard-newlines' is non-nil, the newline is marked with the
text-property `hard'.
With ARG, insert that many newlines.
Call `auto-fill-function' if the current column number is greater
than the value of `fill-column' and ARG is nil.
But it does not say newline is in the context of dos ("\r\n") or unix ("\n").
Internally, Emacs stores a Unix newline, i.e. "\n", in its buffers, similar to what most C programs do when reading text files. If there is a "\r" in an Emacs buffer, it will be displayed as ^M.
On the other hand, Emacs remembers the newline convention used for each opened file. If you open a file with "\r\n" line breaks, modify it, and save it, then Emacs will convert all newlines back to "\r\n".
I have a list of lines like this:
a+
b+
c+
d+
e+
f+
... you get the idea...
I want to end up with a+b+c+d+e etc
I was trying with emacs but couldn't work out how to do such a thing. anyone any ideas?
One thing that does work is
c-m-% [paste in selected after + on one line to beginning of next row] [nothing]
There must be something to insert for carriage return?
How about simply replacing EOLs by nothing?
M-%C-q C-jRETRET
Explanation:
M-% : query-replace
C-q : quote the following character
C-j : end-of-line character
first RET : validate the search string
second RET : validate the (empty) replacement string
Do you have a buffer with those lines in it? In that case, you could create a simple macro:
F3 ;; record macro
C-e ;; end of line
C-d ;; delete newline
F4 ;; save macro
Then either press F4 repeatedly until you're done, or do C-0 F4 to do it all in one swoop.
Have you tried just `M-q' ? The spacing is different, and it will use several lines if you have many of those thingies, but otherwise, it seems like a funny alternative.
M-x
replace-regexp
RET
C-q C-j
RET
RET
How can I detect CR and/or LF in Emacs? Since I want to i-search CRLF, I prefer simpler way (e.g. no or less regex). Only relevant web page I've found is this but c-q c-j didn't work.
Thanks!
Environment) GNU Emacs 22.3.1 (i386-apple-darwin9.8.0, Carbon Version 1.6.0), but I also want to know how to do this on linux (Ubuntu).
C-s to start i-search, then C-q C-j should work. Control-Q quotes the next character as a literal, and control-J is a literal linefeed ("LF" or newline).
If you're dealing with a file that has carriage returns (CRLF line endings), Emacs will automatically use a DOS buffer file coding system and convert them to just linefeeds when loaded, and reconvert them to CRLFs when saved. If you really want carriage returns in your buffer, run M-x revert-buffer-with-coding-system unix. Then carriage returns will be displayed in your buffer as ^M. In this case, you can search for them with C-s to start i-search, then C-q C-j C-q C-m.
I am trying to replace a character - say ; - with a new line using replace-string and/or replace-regexp in Emacs.
I have tried the following commands:
M-x replace-string RET ; RET \n
This will replace ; with two characters: \n.
M-x replace-regex RET ; RET \n
This results in the following error (shown in the minibuffer):
Invalid use of `' in replacement text.
What's wrong with using replace-string for this task? Is there another way to do it?
M-x replace-string RET ; RET C-q C-j.
C-q for quoted-insert,
C-j is a newline.
There are four ways I've found to put a newline into the minibuffer.
C-o
C-q C-j
C-q 12 (12 is the octal value of newline)
C-x o to the main window, kill a newline with C-k, then C-x o back to the minibuffer, yank it with C-y
Don't forget that you can always cut and paste into the minibuffer.
So you can just copy a newline character (or any string) from your buffer, then yank it when prompted for the replacement text.
More explicitly:
To replace the semicolon character (;) with a newline, follow these exact steps.
locate the cursor at the upper left of buffer the containing text you want to change
Type m-x replace-string and hit Return
The mini-buffer will display something like this:
Replace string (default ^ -> ):
Type in the character you want to replace. In this case, ;
and hit Return
The mini-buffer will display something like this:
string ; with:
Now execute C-q C-j
All instances of semicolon will be replaced a newline (from the cursor location to the end of the buffer will now appear)
There is a bit more to it than the original explanation says.
Switch to text mode:
M-x text-mode
Highlight the block to indent.
Indent: Ctrl + M </kbd>
Switch back to whatever mode...
Inline just:
C-M-S-% (if the binding keys are still the default) and then
replace-string ^J.