How to do a project-wide find and replace in Spacemacs? - spacemacs

I'm trying to do a project-wide find/replace in Spacemacs. I tried this:
SPC s a p
Type the text I want to replace.
C-c C-e
At this point Spacemacs tells me text is read-only. What am I missing to be able to preform the edit operation?

Use SPC p R to use projectile-replace which runs interactive query-replace on all files in the project.

Related

How to make buffers writable in spacemacs?

Whenever I try to edit an existing file with spacemacs, I get "buffer is read-only". How do I give spacemacs the permission to edit any buffer on a Mac?
Press SPC SPC, type read-only-mode and select/call it. This will toggle the "read-only" status of the current buffer.
Alternatively, use shortcut SPC b w.
You can also try the following shortcut:
C-x C-q runs the command read-only-mode

How to disable rainbow-delimiters for Spacemacs?

I've added dotspacemacs-excluded-packages '(rainbow-delimiters) at my .spacemacs file. (This is the only instance of the rainbow-delimiters at the whole file.) I've restarted Spacemacs and nothing happened. I still have the delimiters in a different color, which depends on my cursor position.
You can disable rainbow-delimiters-mode with
SPC t C d

Spacemacs: Search for file in multiple projects

I know I can use "SPC p f" to search for a file in the current project, which means git repository for me. Now, in my current project we have multiple git repos, and I'd like to search for files in all of them. Luckily, they all reside in the same directory (e.g. ~/projects/x/).
Is there a command in Spacemacs that lets me search for files in all the git repos under ~/projects/x?
I believe you can do it with SPC s f. When you activate it:
Prompts you to select a directory to search
Allow you to enter a search string, showing results in the HELM window
In general, SPC s shows all keybindings for general search, where f is for files.
I dug through the available helm commands again and found helm-projects-find-files, which does exactly what I want.
I put this in ~/.spacemacs into the function dotspacemacs/user-config:
(setq-default helm-locate-project-list (list "~/projects"))
(spacemacs/set-leader-keys "fm" 'helm-projects-find-files))
For searching in those files, you can use spacemacs/helm-project-smart-do-search-in-dir:
Put this somewhere in ~/.spacemacs:
(defun mine/search-in-projects ()
"Search in all my projects (i.e. what is checked out in ~/projects)"
(interactive)
(spacemacs/helm-project-smart-do-search-in-dir "~/projects"))
And this in ~/.spacemacs into the function dotspacemacs/user-config:
(spacemacs/set-leader-keys "sm" 'mine/search-in-projects)
(I used SPC-sm as key combination because the project name starts with an "m").
Oh, I just realized I can just put a marker that projectile respects (like a .projectile file) into my ~/projects/x directory. Now I can switch to the ~/projects/x project, and still am able to also narrow it to specific sub-projects by selecting e.g. ~/projects/x/p1/.
So all I needed to do was:
touch ~/projects/.projectile
Update: I realized that when doing this, I can't narrow down to a sub-project. So it's not really the best answer.
You can put this in your .spacemacs to bind SPC p f to search all projects.
(spacemacs/set-leader-keys "pf" 'helm-projectile-find-file-in-known-projects)

How can I create a new file with a simple way in spacemacs?

Currently, I know that I can create a new file with the following ways:
c key in Neotree
SPC ' in shell layer, and use the touch xxx command
I am wondering whether there is a simple way (something like SPC f xxx) or not.
Thanks.
Yes, you can use SPC f f, enter the name of the new file and then select the line starting with [?] (which is the default if no other file matches).
Note you can also use this to create files in non-existing subfolders, like SPC f f my/sub/folder/file.txt RET.
If you are using the standard vim like keybindings,
:e /path/to/file
works opens a file ( which doesn't have to exist before )
:x
saves the file and closes the buffer and
:w
saves without closing.

How to auto-indent code in the Atom editor?

How do you auto-indent your code in the Atom editor? In other editors you can usually select some code and auto-indent it.
Is there a keyboard shortcut as well?
I found the option in the menu, under Edit > Lines > Auto Indent. It doesn't seem to have a default keymap bound.
You could try to add a key mapping (Atom > Open Your Keymap [on Windows: File > Settings > Keybindings > "your keymap file"]) like this one:
'atom-text-editor':
'cmd-alt-l': 'editor:auto-indent'
It worked for me :)
For Windows:
'atom-text-editor':
'ctrl-alt-l': 'editor:auto-indent'
The accepted answer works, but you have to do a "Select All" first -- every time -- and I'm way too lazy for that.
And it turns out, it's not super trivial -- I figured I'd post this here in an attempt to save like-minded individuals the 30 minutes it takes to track all this down. -- Also note: this approach restores the original selection when it's done (and it happens so fast, you don't even notice the selection was ever changed).
1.) First, add a custom command to your init script (File->Open Your Init Script, then paste this at the bottom):
atom.commands.add 'atom-text-editor', 'custom:reformat', ->
editor = atom.workspace.getActiveTextEditor();
oldRanges = editor.getSelectedBufferRanges();
editor.selectAll();
atom.commands.dispatch(atom.views.getView(editor), 'editor:auto-indent')
editor.setSelectedBufferRanges(oldRanges);
2.) Bind "custom:reformat" to a key (File->Open Your Keymap, then paste this at the bottom):
'atom-text-editor':
'ctrl-alt-d': 'custom:reformat'
3.) Restart Atom (the init.coffee script only runs when atom is first launched).
Package auto-indent exists to apply auto-indent to entire file with this shortcuts :
ctrl+shift+i
or
cmd+shift+i
Package url : https://atom.io/packages/auto-indent
I prefer using atom-beautify, CTRL+ALT+B (in linux, may be in windows also) handles better al kind of formats and it is also customizable per file format.
more details here: https://atom.io/packages/atom-beautify
You can just quickly open up the command palette and do it there
Cmd + Shift + p and search for Editor: Auto Indent:
This works for me:
'atom-workspace atom-text-editor':
'ctrl-alt-a': 'editor:auto-indent'
You have to select all with ctrl-a first.
This is the best help that I found:
https://atom.io/packages/atom-beautify
This package can be installed in Atom and then CTRL+ALT+B solve the problem.
On Linux
(tested in Ununtu KDE)
There is the option in the menu, under Edit > Lines > Auto Indent or press Cmd + Shift + p, search for Editor: Auto Indent by entering just "ai"
Note: In KDE ctrl-alt-l is already globally set for "lock screen" so better use ctrl-alt-i instead.
You can add a key mapping in Atom:
Cmd + Shift + p, search for "Settings View: Show Keybindings"
click on "your keymap file"
Add a section there like this one:
'atom-text-editor':
'ctrl-alt-i': 'editor:auto-indent'
If the indention is not working, it can be a reason, that the file-ending is not recognized by Atom. Add the support for your language then, for example for "Lua" install the package "language-lua".
If a File is not recognized for your language:
open the ~/.atom/config.cson file (by CTRL+SHIFT+p: type ``open config'')
add/edit a customFileTypes section under core for example like the following:
core:
customFileTypes:
"source.lua": [
"conf"
]
"text.html.php": [
"thtml"
]
(You find the languages scope names ("source.lua", "text.html.php"...) in the language package settings see here)
If you have troubles with hotkeys, try to open Key Binding Resolver Window with Cmd + .. It will show you keys you're pressing in the realtime.
For example, Cmd + Shift + ' is actually Cmd + "
You could also try to add a key mapping witch auto select all the code in file and indent it:
'atom-text-editor':
'ctrl-alt-l': 'auto-indent:apply'
I was working on some groovy code, which doesn't auto-format on save. What I did was right-click on the code pane, then chose ESLint Fix. That fixed my indents.
If you are used to the Eclipse IDE or the Netbeans, you can use the package eclipse-keybindings (https://atom.io/packages/eclipse-keybindings):
This Atom package provides Eclipse IDE key mappings for Atom. Currently, the Eclipse shortcuts are directly mapped to existing Atom commands.
To format all lines from a file, just use: Ctrl+Shift+F.
Ctrl+Shift+i worked for me in PHP under Windows ... but some files did not react. Not being the brightest it took me a while to work out that it was the include files that were the problem. If you are using echo(' ... PHP ...') then the PHP does not get re-formatted. To get over this, create a temporary PHP file, say t.php, copy the PHP part into that, reindent it (Ctrl+Shift+i ... did I mention that?) and then copy the newly reformatted PHP back into the original file. Whilst this is a pain, it does give you correctly formatted PHP.