How to replace '_' by space in emacs - emacs

I have a text file which I am only able to look that there is an underscore between some words only using emcas editor but not other editors such as vi. I do not know how to use emacs but I wanted to replace these underscores "_" by space in the emacs editor automated fashion. How can I do that ?

I believe that those underscore aren't really underscore, but non breaking space (U+00A0 unicode char), that Emacs show as underscore with a different color. You probably don't need to replace them, but if this is really needed, just use M-x replace-string and kill and yank one of those non-breaking space in the string to be replaced.

Hit the M-x key-combination (that is, hold meta key - alt on windows - and hit x) type replace-string and hit enter. You can then type [underscore] enter [space] enter.
In Emacs notation:
M-x replace-string RET _ RET " "

Should the previous answer not solve it: Remember that as a coding system error. Check with C-x = if it's char 95.
If not, check variables coding-system-for-read, coding-system-for-write, buffer-file-coding-system
Finally, get emacs core developers at help-gnu-emacs#gnu.org

Related

Emacs lisp, How to make a newline in IELM?

Even the basic things seem to be hidden behind weird shortcut-combinations.
How can I (hopefully without too many c-m-x-c combinations) create a simple new line?
return evaluates the current line
With C-j. That said, if you have paredit enabled, it should do all the newlines you need automatically.
In my case it was M-j.
I'm currently trying out SpaceMacs, not sure if that has anything to do with it.
Even the basic things seem to be hidden behind weird shortcut-combinations.
If you don't want RET to have contextual behaviour, you can M-x customize-option RET ielm-dynamic-return.
How can I ... create a simple new line?
Only a newline? C-qC-j is the normal way to enter a newline in places where RET does something else. (More generally you can use C-q to insert any character that isn't self-inserting for the current buffer.)
If you want newline + indentation (which is what RET does when contextually appropriate), then M-j will do that (noting that if you are in a comment at the time then the new line will also default to a comment).

Github code preview looks odd

On GitHub
why does the code look like this?
It looks fine in all the code editors out there
Ctrl+M characters present in a file in linux, when originally the file came from Windows environment.
You may need to remove Ctrl+M characters, when you import a text file from MS-DOS (or MS-Windows), and forget to transfer it in ASCII or text mode. Here are several ways to do it; pick the one you are most comfortable with.
The easiest way is probably to use the stream editor sed to remove the ^M characters. Type this command: % sed -e "s/^M//" filename > newfilename
To enter ^M, type CTRL-V, then CTRL-M. That is, hold down the CTRL key then press V and M in succession.
You can also do it in vi: % vi filename
Inside vi [in ESC mode] type: :%s/^M//g
To enter ^M, type CTRL-V, then CTRL-M. That is, hold down the CTRL key then press V and M in succession.
You can also do it inside Emacs. To do so, follow these steps:
Go to the beginning of the document
Type: M-x replace-string RET C-q C-m RET RET
where "RET" means and C-q and C-m mean .
Courtesy: https://its.ucsc.edu/unix-timeshare/tutorials/clean-ctrl-m.html

Replace text literally without regular expression in Emacs evil-mode

In vim, I could use :%sno/[abt]//g to remove all text of "[abt]" literally (as explained here).
I tried the same command in evil-mode, but it complains it doesn't understand the sno command, so how can I do the same thing in evil-mode?
To my knowledge, evil does not (yet?) support the "magic/no magic" regexp options (actually, it only does a smallish subset of ex functionality, so I don't think % will work either). As #Ehvince's answer suggests, the standard Emacs way to do the replace is with query-replace or query-replace-regexp. If you'd like to stick to evil, just escape the square brackets with a backslash:
:s/\[abt\]//g
NB: backslash escapes in Emacs often bite people coming from other environments or programming languages; have a look at the bottom of this manual node on the backslash for more information.
You would use the emacs command query-replace bound to M-%:
M-% [abt] RET <nothing> RET
and then approve each occurence with y or all with !.
The doc is at C-h f query-replace.
query-replace-regexp is bound to C-M-%.

How to write comma character in a SLIME EMACS window

How can I write a "," (comma) character in the SLIME emacs window? The , key brings up the SLIME command prompt automatically.
Thanks, a Lisp beginner
, only triggers REPL shortcut selection when input at the beginning of a line. In all other cases, you can input a comma by typing ,.
In the case of Common Lisp, since as long as you don't modify the reader, , can only occur within a quasi-quoted expression, this should not be a significant restriction.
If it really is a problem, refer to Deokhwan Kim's answer.
You can insert , by C-q, (Control-q and then comma). C-q is bound to quoted-insert, which can be generally used whenever you want Emacs to read a next input character and insert it instead of invoking a command bound to the input character.

gnu screen - changing the default escape command key to ALT-X?

In GNU screen, I want to change the default command binding to Alt-s (by tweaking .screenrc) instead of the default C-a, the reason is I use emacs hence GNU screen binds the C-a key, sending "C-a" to the emacs becomes tedious (as #Nils said, to send "C-a" I should type "C-a a"), as well as "C-a" in bash shell, and I could change the escape to C- but some of them are already mapped in emacs and other combinations are not as easy as ALT-s . If anyone has already done a ALT key mapping, please do let me know.
It is possible to work around :escape command limitations using registers and :bindkey command. Just put this in .screenrc:
# reset escape key to the default
escape ^Aa
# auxiliary register
register S ^A
# Alt + x produces ^A and acts as an escape key
bindkey "^[x" process S
## Alt + space produces ^A and acts as an escape key
# bindkey "^[ " process S
See http://adb.cba.pl/gnu-screen-tips-page-my.html#howto-alt-key-as-escape
From my reading of man screen it seems like the only meta character that screen can use for the command binding is CTRL:
escape xy
Set the command character to x and the character generating a literal
command character (by triggering the "meta" command) to y (similar to
the -e option). Each argument is either a single character, a two-character
sequence of the form "^x" (meaning "C-x"), a backslash followed by an octal
number (specifying the ASCII code of the character), or a backslash followed
by a second character, such as "\^" or "\\". The default is "^Aa".
If there is some mapping that you don't use in emacs, even if it's inconvenient, like C-|, then you could use your terminal input manager to remap ALT-X to that, letting you use the ALT binding instead. That would be a little hackish though.
I'm an Emacs and screen user as well. Although I rarely use Emacs in a terminal -- and as such in a screen session -- I didn't want to give up C-a for the shell either (which uses Emacs key bindings). My solution was to use C-j as the prefix key for screen, which I was willing to sacrifice. In Emacs programming modes it is bound to (newline-and-indent) which I bound to RET as well, so I really don't miss it.
By the way: I know this is an advise rather than an answer, but I felt this would be valuable enough to post nevertheless.
To make Alt+X the default prefix for commands and free C-a, add the following lines to .screenrc:
escape ^||
bindkey "^[x" command
As a side effect C-| will be command prefix too. If you need this keys to be free too, then fix "escape ^||" accordingly.
Screen doesn't have any shorthand syntax for alt bindings, but you can give it the octal code directly. For instance on my machine, Alt-x has the hex code F8, or 370 octal, so putting
escape \370x
in my screenrc changed the escape code to alt-X
Tested and works with screen 4.00.03 on Linux.
You may have to change the escape, since I think this may depend on things like your language and codeset, etc: how I found out what my escape code was was to type
$ echo -n ^QM-x | perl -ne 'printf "%lo\n", ord($_)'
^Q is the quoted-insert command for readline (it inserts what you type directly without trying to interpret it) and M-x was a literal Alt-X.
Fellow emacs user here.
The best solution I've found is a ~/.screenrc file with the following:
# C-a :source .screenrc
escape ^gg
Live updated here: https://gist.github.com/1058111
See also: http://ubuntuforums.org/showthread.php?t=498675
Something I have had for years in my .screenrc:
escape ^Zz
which is now hardwired in muscle memory for me.
Somehow I ended up having to share a screen with someone else's config, and now I keep stopping processes all the time (bash ^Z)... Not funny...