Work in Progress
Documentation in the repl or evaluating
I was expecting something like
(doc apply) to work in all namespaces, any pointers on why that would throw error?
dan sutton [11:00 PM]
that is conveniently loaded for you in the initial user ns but not in others so it doesn't conflict with things you might define there
, in the repl and there's an option to
require-repl-utils in the current ns
this is just sugar for something like
(require '[clojure.repl :refer [doc source ...])
Prashanth Iyer [11:04 PM] @dpsutton the docs doesn’t work for me even in the initial user ns.
dan sutton [11:04 PM]
are you setting an initial ns other than ns
you could try
m-x cider-repl-require-repl-utils as well
SPC c l - comment line
C-M j - new commented line underneath
SPC ; i i comment indented
SPC ; p a comment paragraph
M-; - Emacs comment line
lisp mode - structured editing
Create a new separate expression either side of the current expression
SPC k ( - create a new empty expression,
(), before the current expression
SPC k ) - create a new empty expression,
(), after the current expression
clojure refactor - thread macro
The more nested expressions and expression has, then the trickier it can be for the developer to understand what it is doing.
Using the thread macro you can organise your nested expressions sequentially, which can aid in understanding
clj-refactor has functions to convert an expression to use a thread-first or thread-last macro
(defn make-chips [potatoes] (bag-up (drain (fry (slice potatoes)))))
Place the cursor on the expression starting with
bag-up and press
, r t f to change the expression to use the thread first macro
(defn make-chips [potatoes] (-> potatoes slice fry drain bag-up))
Vim text tips
insert multiple characters using a combination of a number followed by
i. For example, to add a line of ; character, type the number of characters to insert, press
i to enter insert mode, press the character you want to repeat, then escape back to vim normal mode,
42 i ; ESC
M-; - Start an empty line with a comment
;; or add a comment at the end of the line
Commit Amend will allow you to edit the commit message of the latest commit (hopefully you haven't pushed this commit to a shared repository).
Open Magit status
SPC g s then
c for commit and
a for amend. Edit the commit message and make it even better. Then create the new commit using
, , or
If you change your mind, cancel the amend using
, k or
Did you know, you can type simple elisp expressions in eshell without any parentheses or quotes (for string args)
open eshell and try:
setq line-spacing 100 or
list-buffers t or
org-agenda DONE T
functional callisthenics in Clojure
keep side effects at the top level (api calls, db calls)
no mutable state (except where its necessary) functions with only one argument (well only if its a collection) implicit recursion over explicit recursion tail recursion everything named use intermediate values (local name bindings) dont abbreviate
Configure autocomplete to use a key or a delay
Sometimes autocomplete is a bit slow in Clojure.
is it possible to trigger the autocomplete popup with a key ? i find the popup useful some of the time, but having it trigger automatically drives me nuts...
@ag i seem to be using company, rather than auto-complete so i have
company-idle-delay - i'd much rather have the popup be manual though - if i want auto-complete then i know and want it quickly, if i don't want it i don't ever want it to appear
ag [5:24 PM]
Ideas for intro to Spacemacs
Visual mode substitute approach with S
- In normal mode, select the test you wish to surround.
Scuts the text and puts you in insert mode
- type the opening character that will surround the text (or open & close characters if not using smartparens)
ESCto switch back to normal mode
pto paste the text that was originally highlighted
visual mode with gS (normal mode)
- select the text to surround
gSprompts to type in the character to use for the surround (surround-region)
- insets opening & closing charaters, however inserts a new lines before and after the selected text
- vim video tutorials - http://derekwyatt.org/vim/tutorials/
You can change a surrounding with cs
You can delete a surrounding with ds
C-M k - kills sexp / balanced expression
C-M SPC - selects sexp / balanced expression
autocompletion for external libraries
if you wish autocompletion to work for external libraries (and jumping to definition) you should make sure that the libraries in question have been added to the repl.
Libraries get added when you
- evaluate the whole buffer in a namespace
- evaluate the namespace expression
- evaluate a
useexpression with that library in the REPL (either REPL buffer or in a file).
vim stuff for undo-tree
Vim editing style, naturally:
j and k to navigate through the tree up and down.
h and l to switch branches.
Emacs editing style:
n and p to navigate through the tree up and down.
f and b to switch branches.
both editing styles:
q or C-g to quit and leave in current state.
C-q to abort changes.
Note: Undo-Tree is a very powerful package and has lots of useful/cool features that are comprehensively explained only in its source code embedded documentation, which could be visualized by calling:
M-x finder-commentary <RET>
Or take a look at the Online Undo-tree documentation
Other useful commands:
d Toggle diff display.
t Toggle display of time-stamps.
s Toggle keyboard selection mode.
, and < Scroll left
. and > Scroll right
Perform a visual selection and then press J
C-x u shows visual undo tree
typical copy / cut and paste approach
in normal mode, select the region you want to cut, this puts you into select mode. Then press
d to cut (delete) the selected text or
y to copy (yank into kill ring). This will put you back into normal mode.
Move the cursor to where you want to paste the text with
normal & insert mode
C-j - insert new line after cursor
Spacemacs saves the bookmarks in ~/.emacs.d/.cache/bookmarks, and the recent files lise in ~/.emacs.d/.cache/recentf. You can copy these two files somewhere outside of ~/.emacs.d, and copy them back in after re-installing.
In fact, there might be more files in ~/.emacs.d/.cache that you'd like to save. I suggest backing up the entire ~/.emacs.d/.cache and restoring what you miss after re-installation.
For completeness, I'll mention that the locations of these two files are controlled by the variables bookmark-default-file and recentf-save-file.
from spacemacs gitter channel
C-S-backspace -- kill-whole-line
(org :variables org-enable-reveal-js-support t org-enable-github-support t org-enable-bootstrap-support t )
SPC t h s is bound to spacemacs/toggle-syntax-highlighting. the / evil-ex-search-forward highlighting seems to be visible
removed with SPC s c spacemacs/evil-search-clear-highlight
here's also SPC t I which enables aggressive-indent, it indents automatically.
Indenting text in vim mode https://stackoverflow.com/questions/235839/indent-multiple-lines-quickly-in-vi
Indentation = Indent according to rules
== indent current line << move current line indent to left
Change surrounding symbols c s ' "
Evil undo delete should be finer
Evil ex commands - the : commands like q for quit
does anyone know what face is for the current symbol when automatic-highlight is on? SPC t h a? nevermind, I think I found it: ahs-plugin-whole-buffer-face
Deleting structured text in vim
For vanilla evil-mode,
di[ will do it, ie
With evil-cleverparens you could also use
dif since cleverparens adds the
f (form) text-object.
Well, for deleting in parens it would be
di(. Similarly you can do
", and some others.
delete-around-[) does the same thing, but includes the brackets.
If you haven't read this, it was something that fundamentally changed how I vim. Just a really key insight. https://yanpritzker.com/learn-to-speak-vim-verbs-nouns-and-modifiers-d7bfed1f6b2d
Buffer management in evil mode
Source code - Clojure
Some key sequences I use all the time:
SPC TABis like
:bpin vim: switch to the previous buffer.
SPC b b- switch to a buffer by fuzzy matching on the name.
SPC p f- find a file with fuzzy matching in the current project.
:A- switch between test and implementation (in some languages anyway).
SPC b d deletes the current buffer, which keeps the set of buffers you're matching against with
SPC b b manageable. Similarly,
SPC p k deletes all buffers for the current project. Although, you probably don't need to be as concerned about open buffers as I am. :-)
:A did seem to work for me in clojure. Ended up finding out that
SPC p T is
SPC p a is
projectile-find-other-file (which goes to the src file if you're in a test file)
SPC p a toggles between
Madeline & powerline
SPC t m t - toggle mode line
There are other modeline toggles under
SPC t m that you might explore.
@cpmcdaniel if it's the separators between the things in the modeline that is bothering you, you can change the separator in our
.spacemacs... I set mine to
(setq powerline-default-separator nil powerline-center-theme t)
copy from helm buffer
Use Spacemacs as the $EDITOR for git commits?
Spacemacs can be used as the $EDITOR (or $GIT_EDITOR) for editing git commits messages. To enable this you have to add the following line to your dotspacemacs/user-config:
I am starting to use spacemacs and org-mode for academic writing, so I use pandoc, which you will probably want to use. I have written a beginner's guide to spacemacs for academic writing and a cheat sheet that you might find useful: https://ontologicalblog.wordpress.com/2016/10/14/an-absolute-beginners-guide-to-spacemacs-for-academic-writing/
- Agenda files
(with-eval-after-load 'org (setq org-agenda-files '("c:/Users/USERNAME/Dropbox/Notes/")))
working with buffers
When you want a window to stay put, use
SPC w t. It calls the function
I use it to make sure REPL and shell windows don't accidentally get taken over by new buffers.
When I start up the spacemacs buffer shows a list of recent files. Is there a command to open everything in that list?
quicknir @quicknir 02:25
SPC f r
so, with helm you can mark multiple things and act on all of them
C-k to move the cursor up and down in the list of recent files.
C-SPC to mark individual files or mark every listed file with
M-a and then hitting enter should open everything
Scrolling In vim mode
C-y - scroll down the buffer so you can see more text at the top of the buffer
C-e - scroll up the buffer so you can see more text further down
C-l - toggle between centering the current line, moving the current line to the top of the buffer and the original position
? How to jump to a line number or jump the cursor a number of lines
Manipulating case of text
Case Conversion Commands
Emacs has commands for converting either a single word or any arbitrary range of text to upper case or to lower case.
Convert following word to lower case (downcase-word).
Convert following word to upper case (upcase-word).
Capitalize the following word (capitalize-word).
Convert region to lower case (downcase-region).
Convert region to upper case (upcase-region).
M-l (downcase-word) converts the word after point to lower case, moving past it. Thus, repeating M-l converts successive words. M-u (upcase-word) converts to all capitals instead, while M-c (capitalize-word) puts the first letter of the word into upper case and the rest into lower case. All these commands convert several words at once if given an argument. They are especially convenient for converting a large amount of text from all upper case to mixed case, because you can move through the text using M-l, M-u or M-c on each word as appropriate, occasionally using M-f instead to skip a word.
When given a negative argument, the word case conversion commands apply to the appropriate number of words before point, but do not move point. This is convenient when you have just typed a word in the wrong case: you can give the case conversion command and continue typing.
If a word case conversion command is given in the middle of a word, it applies only to the part of the word which follows point. (This is comparable to what M-d (kill-word) does.) With a negative argument, case conversion applies only to the part of the word before point.
The other case conversion commands are C-x C-u (upcase-region) and C-x C-l (downcase-region), which convert everything between point and mark to the specified case. Point and mark do not move.
The region case conversion commands upcase-region and downcase-region are normally disabled. This means that they ask for confirmation if you try to use them. When you confirm, you may enable the command, which means it will not ask for confirmation again. See Disabling. c
Function refers to the thing that you are calling when you hit a key or series of keys. For example j in normal modeis mapped to the function evil-next-line. In elisp these usually look like strings of hyphenated words. spc spc opens helm M-x and lets you search for functions by name and execute them. Note that functions may also be refered to as sexps (symbolic expressions). Buffers
Buffers are like tabs in your browser. You open them from files on your computer instead of from the internet, and they stay open until you close them. Hit spc b b to see a searchable list of your open buffers, and recently opened buffers. spc b B opens a list of buffers organized by major mode. spc b d deletes the buffer you are currently in. As you can most the spc b commands are related to buffers. But buffers arent necessarily just files you open, they can also be generated by emacs (like the helm mini buffer (spc b b) you use to search buffers) to do useful things. The Mode Line
At the bottom of the window, you will see the mode line. Its got some handy information in it. From left to right it shows you:
Your window number. The color indicates what evil mode you are in (normal, insert, etc) A little * indicator if your file has been modified since it has been saved. Buffer size. Buffer name (same as file name if you have opened from file). Major mode. Minor modes.
On the far right is info about where you are in a buffer. Move around whth hjkl and watch it if you dont get it at first. Major Modes
This is how emacs organizes important sets of functionality. Each buffer will have one major mode at a time. It can customize anything about emacs so that it suits the buffer you are working with. There is a mode for editing C#, a mode for editing latex, a mode for viewing files (dired-mode), a mode for searching (helm-major-mode), a mode for emulating a terminal (term-mode). You can see what major mode you are in at the bottom of each buffer in your mode line. Usually this is automatically set depending on which buffer you are in. Major modes specific functions are on the , key (also spc m). Minor Modes
Minor modes are smaller sets of custom behavior that can work together. A major mode will automatically set a bunch of relevant minor modes, but you can toggle them with spc t. For example spc t n toggles a minor mode for line numbers. You can hover over the symbols in the modeline with your mouse to see what minor mode each represents. spc h d m (help describe mode) opens a comprehensive list of your active minor modes. Move your cursor to one and hit enter to get more information.
Side Note: The information opens in a split buffer titled help. Many of these buffers that are meant to be temporary can be closed quickly with q. Layers
Everything so far (except specific key bindings) applies to emacs in general. Layers, however, are a spacemacs specific term. Layers are meant to be a simple way for you to customize your configuration by adding only one line to your .spacemacs file. See the list to see what are available. Check out the latex layer for example. The .spacemacs file
Hit spc f e d (file emacs dotfile) to open this file. This is where you can customize everything. Find the dotspacemacs-configuration-layers line. You can use / in normal mode to start searching for it and enter when you have it. Add latex in that list. It should look like this:
dotspacemacs-configuration-layers '( latex other-layer other-layer)
Now spacemacs will load that layer on startup for you, which includes a major mode for editing latex and a bunch of commands. You can now either restart emacs, or hit spc f e R(file emacs reload) to reload your config. Now if you hit spc f f (file find) and open a latex file you should have some syntax highlighting and latex specific commands on your , key.
Why Vim ?
Cut the Mouse - One of the main wins for Vim has always been that it is an editor that lets you keep your hands on the keyboard. Reaching for the mouse slows you down, and while I never really had a problem with that in the past (I spend more time thinking and reading than I do writing code), now that I’ve experienced 2 months with my hands on the keyboard I do find myself noticing (annoyingly) when I am forced to reach for the mouse.
Fast Navigation - Moving around inside files in most windows editors involves a lot of home/end/up/down arrow key. Having search and tag based navigation makes getting around within a file much faster. Finding the right file is also easier with the commandt plugin, influenced by Textmate on the Mac, this fuzzy file finder is not typically available in traditional windows editors (last time I looked)
Split Windows - Splitting windows into panes and navigating around them is a killer feature that I use all the time to see multiple files at once, or multiple areas of the same file at once. In the past I used tabs heavily, but I now prefer split panes that I can manage without reaching for the mouse.
Effort vs Reward
Ok. So I have a theory…
Vim proponents will tell you that the effort you spend learning vim will pay dividends in the long run once you know how to use it properly. After 60 days I can say that I agree with that opinion.
However, if I spent this much effort learning any editor I think it would pay dividends in the long run. The difference is that Vim forces you to go through this pain, whilst other editors work ‘out the box’ and so most programmers are not inclined to learn the power of those editors.
For example, I think UltraEdit, TextMate, even Visual Studio are pretty good editors, but since they all pretty much just work out of the box, its easy to ignore their advanced features and not spend the time customizing and configuring them.
I wonder if I spent 60 days really learning UltraEdit if I couldn’t get the same positives I described here ? Hmmm, a future article maybe? Conclusion
I’m still using Vim after 60 days, and I plan to continue using it for the foreseeable future as long as I can keep taking a little time here and there to dig deeper, customize a bit more, learn how to overcome the negatives and build upon the positives.
Vim seems to be so powerful that I could be learning it forever. Here’s a list of some of the things I want to spend time on in the future.
Movement - I need to learn more code related movement commands like % match Sessions - Both sessions.vim and sessionman.vim seem to struggle with NERDTree and the quickfix window Cut & Paste - I need to learn more about vim registers so I can manage my cut & paste better, errr, sorry, I mean yank & put Undo & Redo - I think I spend too much time in insert mode so when I undo it tends to be more than I’d like HJKL - Maybe I should remap to swap the J and K keys and try again! More Plugins - There are many more plugins I would like to take the time to check out, and perhaps build some of my own.
SPC p p - switch to another project that spacemacs knows about
A fast way to browse files and directories
use vim keybindings to navigate
j / k -- up / down current directory l -- into the currently selected directory h -- up to parent directory q -- quit
some configuration to consider
(ranger :variables ranger-ignored-extensions '( "mkv" "iso" "mp4" "avi" "mp4" "mkv" "zip" "rar" "exe" "ps" "webm" "png" "jpg" "jpeg" "tif" "tiff" "ics" "dmg" "swf" "gz" "m4a") ranger-max-preview-size 4 ;; Megabyte ranger-cleanup-eagerly t )
SPC s e
iedit-mode (aka interactive-edit-mode) gives you the power to edit instances of the same text string in a buffer. It’s quite similar to multiple cursors, although if you’re used to working with multiple cursors, it’s likely you’ll prefer that.
IEdit defaults to selecting all matches, and then allows you to reduce and expand the matches in various ways, so the workflow is in the opposite direction.
I use iedit often as a quick interactive replace all, and multiple cursors for anything in between that and more complicated regexp search replace.
In conjunction with wgrep-mode (that is a writeable grep mode, which works with most grep alternative tools as well) iedit-mode can become a poweful way to edit a string across many files and review the changes before you save them.
To install it use M-x package-install iedit
Once installed you can start it with C-; (M-x iedit-mode)
Note, this doesn’t work in a terminal so in that case I’d bind it to C-c ;
Spacemacs has a binding for IEdit mode on it’s SPACE leader (SPC s e)
Multiple cursor options in spacemacs
Inter-file Navigation SPC b b open Helm mini-buffer SPC f f Helm find files, is less useful than SPC p f Projectile find files SPC p p Projectile find project
Using the Ranger layer (file manager) invoked using SPC a r (applications ranger) Consier using Unimpaired layer (tpope quick cycling) Consider using Fasd layer to complement Fasd
Intra-file Navigation SPC s s SWOOP! opens a copy of the buffer then elides lines that don’t match the search you type, allowing you to navigate the top buffer by selecting lines in the swoop buffer
Window navigation SPC
Editing Select some text, then s
Help SPC h d invokes “help describe”, providing access to multipe ways of find help SPC f e h is canonical spacemacs help
Checking SPC t s turns on syntax checking
Future layers to explore OrgMode + Capture mode Abbrev mode
Editorconfig layer to manage things like indent and such