I would like to associate a keyboard binding in Emacs (e.g. C-c a) that automatically starts an ansi-term window with a shell that I have pre-specified in my .emacs file (without prompting anything)
For reference, there are two threads in StackOverflow that address similar problems:
Remote ssh connection from within Emacs
Emacs: Default binary to run with M-x ansi-term
but it isn't obvious to me how to combine the ideas in those threads to get an answer to my question.
(global-set-key (kbd "C-c a") '(lambda () (interactive) (ansi-term "/bin/zsh")))
I suggest you to use multi-term. As its name implies, it lets you deal with multiple term using ansi-term.
Here is a small configuration:
(require 'multi-term)
(eval-after-load "multi-term"
'(setq multi-term-program "/bin/bash"
term-unbind-key-list '("C-x"
"C-h"
"M-x"
"C-z")
term-term-name "xterm-256color"))
(global-set-key (kbd "C-c a") 'multi-term-next)
My whole configuration for multi-term is
here
(compilation-shell-minor-mode is really nice).
Related
I have installed the multiple-cursors package but, I cannot manage to work properly. Only one cursor can be modified, the rest of the cursors do nothing.
I have configured my .emacs file for the multi-cursors package as is shown below:
(require 'multiple-cursors)
(global-set-key (kbd "C-c m c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
Can anybody help with this?
Thanks.
My crystal ball tells me that once upon a time the original poster was presented with an interactive question asking him/her whether to perform the same command for all cursors; and, the O.P. answered the question with a "no". Whereupon the Multiple Cursors package added an entry to the mc/lists-file, which has a default location of: (locate-user-emacs-file ".mc-lists.el") -- see https://github.com/magnars/multiple-cursors.el/blob/master/multiple-cursors-core.el#L652
The O.P. should open up the above-mentioned file and see if his/her prior choice should be manually removed. The file contains something like this:
;; This file is automatically generated by the multiple-cursors extension.
;; It keeps track of your preferences for running commands with multiple cursors.
(setq mc/cmds-to-run-for-all
'(
my-custom-function-one
org-self-insert-command
))
(setq mc/cmds-to-run-once
'(
mime-preview-scroll-down-entity
my-custom-function-two
))
(provide '.multiple_cursors)
How to do something like this: auto execute commands (split-window-right) (follow-mode) (visual-line-mode) after opening a file.
One way to do it is to write your own "open file" command:
(defun my-find-file ()
"Like `find-file', but splits screen and enables Follow Mode."
(interactive)
(call-interactively #'find-file)
(follow-delete-other-windows-and-split)
(visual-line-mode 1))
You can bind it to C-x C-f:
(global-set-key (kbd "C-x C-f") #'my-find-file)
I've used follow-delete-other-windows-and-split rather than split-window-right and follow-mode and the latter doesn't work that well when a frame already contains multiple windows.
Also, you might consider enabling visual-line-mode using other mechanisms like mode-specific hooks or global-visual-line-mode.
I want to set a key binding to insert the date into the buffer. I have written the following lisp in my .emacs file. Using date as an example:
;;put the date
(global-set-key
(kbd "C-c C-d")
(shell-command "date" (current-buffer))
)
The key binding works okay when I use other commands like 'next-line, but shell-command will put it into the *scratch* buffer when the .emacs is read and leaves it at that.
Maybe I need to use shell-command-on-region.
For the general case of inserting any output of a shell command to the current buffer, you can use the in-built keyboard chords:
C-u M-! <shell-command>
which runs the same shell-command function, and also inserts the output back at the point in the current buffer.
The entire key-stroke itself can be saved as a macro (and perhaps assigned to a shortcut) for easier invocation of common shell commands.
A friend of mine at work helped me.
(defun put-the-date ()
(interactive)
(insert (shell-command-to-string "date")))
(global-set-key
(kbd "C-c C-d")
'put-the-date
)
I'd like to map a command in emacs to a key-binding. I want the command Control-l to have the same effect as the command Alt-x goto-line followed by a return (since that command first needs a return to be invoked and then a line number).
I modified the init file as follows:
(define-key (M-x goto-line) '\C-l)
but that didn't work. The error was that define-key was being given more than 1 arguments.
Does anyone know how to reset key-bindings in emacs?
Thanks!
M-g g is the default shortcut for goto-line. You might want to try that.
To redefine C-l use:
(global-set-key (kbd "C-l") 'goto-line)
Easiest way to customize lots of keybindings is to install John Wiegley's bind-key module, which is a part of use-package Lisp package. Solution in your init.el:
(require 'bind-key)
(bind-key "C-l" 'goto-line)
Minor modes keys usually override global keys, so if you don't want such behavior, use function bind-key* instead. The package is on MELPA, if you don't know what is it, quickly learn about Emacs package management (should take you 2 minutes to set up MELPA as your repository).
The main problem with keybindings in Emacs is that minor modes keys often override your custom ones. In vanilla Emacs people workaround by creating a minor mode for your own keybindings. If you really wanna understand how Emacs keys work, read Key Bindings # Emacs Manual and Keymaps # Elisp Manual carefully.
I have set as (global-set-key (kbd "C-x g") 'goto-line). You can use that or (global-set-key (kbd "C-l") 'goto-line). I would personally do not touch the C-l key from its default behavior.
If you must use M-x define-key, use
(define-key global-map (kbd "C-l") 'goto-line). The 1st argument to define-key is a KEYMAP.
I've tried various version to no avail:
(global-set-key (kbd "C-<space>") 'tempo-complete-tag)
(global-set-key [C-space] 'tempo-complete-tag)
I'm using CUA mode and running Emacs on Ubuntu, version: GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0)
of 2009-09-27 on crested, modified by Debian
When I run tempo-complete-tag manually it tells me it is bound to C-space but C-space still runs cua-set-mark (or if CUA is disable, set-mark-command).
How can I rebind the C-space shortcut in Emacs to a command I decide?
C-h k (key) will tell you how Emacs refers to a given key (which is "C-SPC" in this instance). (global-set-key (kbd "C-SPC") 'tempo-complete-tag) will do what you want.
I always use the (kbd) function for key-bindings, as it allows you to refer to the key the same way it is typically written everywhere else.
Do keep in mind that C-SPC is a standard set-mark-command binding! Personally I'd pick something different :)
Also keep in mind that "global-set-key" will only do what you want, if your mode doesn't override it. I'm too lazy to load tempo to see if it does indeed override C-SPC, but it might well do so, in which case, you want to put this in your .emacs:
(add-hook 'tempo-mode-hook
(lambda ()
(local-set-key (kbd "C-SPC") 'tempo-complete-tag)
))
Alternative syntax for key binding is via vector:
(global-set-key [?\M-\ ] 'cycle-spacing)
(global-set-key [?\C-\ ] 'tempo-complete-tag)