emacs - shortcuts for horizontal and vertical split - emacs

I am switching to emacs from vim and in my .vimrc, I have the following shortcuts for horizontally and vertically splitting the screen:
" Create window splits easier. The default
" way is Ctrl-w,v and Ctrl-w,s. I remap
" this to vv and ss
nnoremap <silent> vv <C-w>v
nnoremap <silent> ss <C-w>s
How could I do this in emacs?

Welcome to Emacs -- I see from a couple of prior questions that you're using evil, the Vim emulation layer. Here's the short version:
(define-key evil-normal-state-map "vv" 'split-window-horizontally)
(define-key evil-normal-state-map "ss" 'split-window-vertically)
Have a look at the EmacsWiki page on evil, as well as the (sadly outdated) Evil manual.
I'd also suggest browsing through the evil source code to get a sense of how to do things like binding keys by using the find-library function. M-x find-library RET evil and M-x find-library RET evil-maps should get you started.

Unless you're planning to use some vim-emulation mode for Emacs, such as evil-mode, you might be interested in the standard way of doing window splits:
C-x 2 -- split-window-below (vertical split)
C-x 3 -- split-window-right (horizontal split)
C-x 0 -- delete-window (deletes the current window)
C-x 1 -- delete-other-windows (makes the current window fill the frame)

Related

Emacs: (next-line) and (previous-line) behaves incorrectly

I have added the following code in my .emacs file:
(global-set-key (kbd "C-i") 'previous-line)
(global-set-key (kbd "C-k") 'next-line)
After that I start Emacs and push C-x C-b to open *Buffer List* buffer. Then I push C-x o to make it active.
After these actions I try my new keybindings and they work strangely! C-i prints No buttons! at the bottom of the frame. C-k moves the point to the next line but prints D at the previous one.
Any suggestions?
If you ask emacs to tell you what the keys are bound to, using C-h c C-k RET and C-h c C-i RET in your Buffer List buffer, you will be told that
C-k runs the command Buffer-menu-delete
TAB runs the command forward-button
Just because you bound those keys to other functions in the global key map does not mean that those bindings are active in any particular buffer, because there may be other keymaps in force that take precedence over the global map.
This is a large subject and you must proceed with caution (in particular, note that C-k is somewhat destructive: it marks the buffer for deletion - but it is conceivable that in a different buffer with a different mode, the map in force might make it much more destructive).
You can read about keymaps in the emacs manual.

Why org-clock-out and org-toggle-ordered-property have the same key-bind C-c C-x o?

I find that org-clock-out and org-toggle-ordered-property have the same key-bind C-c C-x o.
And also with org-clock-in and org-insert-columns-dblock, the same C-c C-x i.
Sometimes this really messed up. How to make it not get me wrong?
I don't really know that ordered properties are, but I am using the clocking feature.
I don't like multi-key chords so I'm using org-speed-commands-user for this purpose:
(setq org-speed-commands-user
'(("i" . org-clock-in)
("o" . org-clock-out)))
Now to clock into a heading, I move to its beginning with C-a.
This is where org speed commands come in effect: any single letter or digit can
be bound to a command.
And I use this code to quickly get to a position where org speed commands
become active:
(define-key org-mode-map (kbd "C-a")
(lambda()(interactive)
(if (looking-at "^[^*]")
(re-search-backward "^*")
(org-beginning-of-line))))
Also, don't forget that you can clock in/out from the agenda with I/O.
The standard key bindings for org-clock-in/out are C-C C-x C-i and C-c C-x-C-o respectively.
The keybindings do not overlap (although they are similar).
If they overlap when you launch Emacs, please check your ~/.emacs/~/.emacs.d/init.el to ensure you haven't changed the bindings.

How to scroll up in Emacs ansi-term

I've been Googling around and looking at Emacs built-in help but I have yet to determine how to scroll up (or down) in Emacs ansi-term.
I'm using Emacs 23.3.1, OS X, in iTerm2. Thanks!
Edit: I've noticed most the advice people give me doesn't work in ansi-term but does work in eshell. I have since moved to eshell.
In general, if you don't need full screen terminal emulation, shell or eshell are better choices.
However, if you decide to stick with ansi-term, press C-c C-j to go into line mode. Then you can move around normally with the usual cursor movement keys. Press C-c C-k to get back into char mode to interact with the terminal.
Alternatively, you can scroll backwards a screen at a time with C-c C-v and just enter text to scroll back to the terminal input point.
Take a look at the Emacs documentation on term-mode (most of which applies equally to ansi-term) for more information.
Shift-page up/down (in Emacs-speak, S-prior/S-next) will work using the default bindings.
(While the normal C-h m/C-h b don't work to see mode information and bindings in this mode, you can still use C-c M-x describe-mode/describe-bindings, or depending on your setup, use F1 or the help key instead of C-h.)
install evil-mode at first, press C-z to switch to vim key binding.
You can use C-f, C-b to scroll up and down
you can use 20% to jump to to the top 20% of the buffer
you can use /, ?, #, * to search the text in the buffer.
all the grep/filter commands now usable (occur, swiper, helm-swoop, .... just name a few)
you can narrow/widen the buffer
you can yank text
Have you tried: Page up, up arrow, Ctrl-V,Alt-V
For ansi-term, I have this in my .emacs:
(add-hook 'term-mode-hook
(function
(lambda ()
(define-key term-raw-map [?\C-c prior] 'scroll-down)
(define-key term-raw-map [?\C-c next] 'scroll-up))))
Then I can use C-c pgup and C-c pgdn to scroll.
I was having the same issue but with multi-term (zsh), and after reading the response from #muffinista (the C-v did not work for me) but the Alt-v worked to go 1 page, after that you can use the normal C-p and C-n to scroll up and down.
This worked for me, but it depends a lot on which term you are using and key bindings you might have.
Up and down are Ctrl-P and Ctrl-V. There's a whole long list here

How to invoke the buffer list in Emacs

I usually type M-x buffer-menu to switch buffers in Emacs. How can I do this with a shorter command? Its quite a long string to type.
Thanks!
You can use C-x b to change buffers. You have to enter the first few letters of the buffer name, and of course you can use completion. If you press TAB (the most useful key in Emacs), a list of (matching) buffers appears. You can click in this list to switch to a buffer.
You can bind buffer-menu to a key. Pick a key that's not used for another command — let's say f12 — and add the following line to the file ~/.emacs:
(global-set-key (kbd "<f12>") 'buffer-menu)
There are many other interfaces to changing buffers in Emacs, and they can be significantly more efficient than C-x b and C-x C-b. Since this tends to be a very personal choice, I recommend you experiment with a few and keep the one(s) you feel most comfortable with.
C-x C-b
As stated here
I'd highly recommend switching to a mode designed for efficient buffer switching.
If your version of Emacs is recent enough (22+):
M-x ido-mode
and then:
C-x b
to switch buffers, with incremental substring matching, C-s and C-r rotate forward and backwards through the matches.
If you have an older version of Emacs, it should have:
M-x iswitchb-mode
and then, as with ido-mode:
C-x b
opens up the minibuffer to let you choose the buffer to switch to.
Bind C-x C-b to buffer-menu. There is no sense leaving it bound to list-buffers. list-buffers is just a eunuch version of buffer-menu. ;-)
And you might want to try this: http://www.emacswiki.org/emacs/BufferMenuPlus
Try bs-show (in my opinion a way better than C-x C-b). You can bind it to F9 by adding this to .emacs:
(global-set-key (kbd "<f9>") 'bs-show)

Rebinding C-c to C-c

I'm using Viper, and I want to change its C-c and C-g to the original emacs functions. I can rebind C-g with (define-key viper-vi-global-user-map "C-g" 'keyboard-quit), but how can I rebind C-c, since it's a prefix key?
Thanks!
It may make sense for you to run M-x viper-set-expert-level with an argument of 2 ("Master"). As the viper-mode documentation explains:
2 -- MASTER: C-c now has its standard
Emacs meaning in Vi command state, so
most Emacs commands can be used when
Viper is in Vi state.
As you master viper-mode, you're meant to increase your expert-level setting gradually over time, making more Emacs features available to you (or, as the Viper documentation puts it, "To use Emacs productively, you must reach level 3 or higher").
The original binding for C-c can be set with the following:
(define-key viper-vi-global-user-map (kbd "C-c") 'mode-specific-command-prefix)
The info page for this is Prefix Keys.