Comment\Uncomment a Line
Few useful commands for commenting\uncommenting lines in emacs. Taken from the Emacs tutorial. Sure, I can go back to the manual, but I want to ducument and keep them here, for quicker reference.
M-;Insert or realign comment on current line; if the region is active, comment or uncomment the region instead (comment-dwim).
C-u M-;Kill comment on current line (comment-kill).
C-x ;Set comment column (comment-set-column).
M-jLike RET followed by inserting and aligning a comment (comment-indent-new-line). See Multi-Line Comments.
Mastering this command takes me one step further into Emacs, as it used to be one of those functionalities that keep drawing me back to Sublime Text.
Quick reload of init.el file
I'm constantly customizing my emacs. I have an
init.el file, but most
of the configuration in a more literal way, in an org config
When I make changes to Emacs settings, I need to reload the init file
activate the changes. So far, I typed
C-x C-f to find the init file
M-x [RET] eval-buffer to reload it. Repeating this flow
hundreds of times became annoying.
A quick inquery in IRC, and now
I know that I can call
load-file and give it the name of the file I
would like to load. Having a function to load a file, means that I can
wrap it with my own function, and reload my init file with a customized
And with the help of this answer at stack-overflow, I came up with the following shortcut to reload my Emacs configuration:
(global-set-key (kbd "<f6>") (lambda() (interactive)(load-file "~/.emacs.d/init.el")))
New line bellow
I wondered if there's a command to creat a new line bellow the line my point is on. Here's what I found in superuser:
C-e C-m - go to the end of the line, create a new line and move the
point to that line.
C-e C-j - same as the command above, only that the point will indent
There is also a keybind for creating a new line above the current line,
and move the point to that line -
Quick Open a specific file
Now days I start most of my writing in my draft file. I need a quick way to access this file, whether I'm in Emacs or any other application. I know Emacs has the concept of registers, which are special memory slots, that can be accessed with a command. Those registers can store any type of data, such as strings, integers, files and paths.
Google's first search result was EmacsWiki. Again, it proved to be a great source of information, had I wanted to confuse myself. So I passed. The second result was from Emacs tutorial, which again proved to be clear, concise and informative.
Here are the commands for storing a filename in and loading it from a register:
(set-register r '(file . name))
(set-register ?r '(file . "~/Dropbox/Notes/posts/pages/posts_drafts.org"))
To load this file, I should type
C-x r j r
In the code examples above,
r is the name of the register. It can be
replaced with any character.
And to see what's stored in a specific register:
M-x view-register RET r
r is the register I'm querying.
M-l Convert following word to lower case (downcase-word).
M-u Convert following word to upper case (upcase-word).
M-c Capitalize the following word (capitalize-word).
C-x C-l Convert region to lower case (downcase-region).
C-x C-u Convert region to upper case (upcase-region).