emacs , org-mode change
[dotfiles.git] / emacs.d / config / init-key-binding.el
1 ;; This  file is for some global key binding
2
3
4
5
6 (require 'key-chord)
7
8 (setq key-chord-two-keys-delay 0.2)
9
10 ;; from emacs conference 2015 workshop
11 (defun keychord-keymap (keychord bindings)
12   (setq keymap (make-sparse-keymap))
13   (dolist (binding bindings)
14     (define-key keymap (car binding) (cdr binding)))
15   (key-chord-define-global keychord keymap))
16
17
18 (defun switch-to-previous-buffer ()
19   "Switch to previously open buffer. Repeated invocations toggle between the two most recently open buffers."
20   (interactive)
21   (switch-to-buffer (other-buffer (current-buffer) 1)))
22
23
24
25
26 ;; main keymap
27 (keychord-keymap "ss"
28                  '(("j" . helm-mini)
29                    ("k" . find-file)
30                    ("o" . delete-other-windows)))
31
32 ;; misc
33 ;; eval-buffer
34 ;; packet-list-install
35 ;; 
36
37
38 ;; for some helm key mapping
39 (key-chord-define-global "sj" 'helm-mini)
40 (key-chord-define-global "sk" 'helm-find-files)
41
42 ;;
43 (key-chord-define-global ";w" 'save-buffer)
44 (key-chord-define-global ";s" 'split-window-below)
45 (key-chord-define-global ";v" 'split-window-right)
46 (key-chord-define-global ";q" 'delete-window)
47
48 ;(key-chord-define-global "x0" 'other-window)
49 ;(key-chord-define-global "x1" 'delete-other-windows)
50
51
52 ;; same  set ESC ESC as a prefix key map
53 ;; Windows
54 ;(global-set-key (kbd "<escape> M-a") 'find-file)
55 (global-set-key (kbd "<escape> M-o") 'delete-other-windows)
56 (global-set-key (kbd "<escape> M-h") 'other-window)
57 (global-set-key (kbd "<escape> M-j") 'find-file)
58 (global-set-key (kbd "<escape> M-k") 'find-file)
59 (global-set-key (kbd "<escape> M-l") 'find-file)
60
61
62 ;; project
63 (global-set-key (kbd "<escape> M-n") 'find-file)
64 (global-set-key (kbd "<escape> M-m") 'find-file)
65 (global-set-key (kbd "<escape> M-p") 'find-file)
66 (global-set-key (kbd "<escape> M-u") 'find-file)
67 (global-set-key (kbd "<escape> M-y") 'find-file)
68 ;(global-set-key (kbd "<escape> <escape>") 'find-file)
69
70
71 (key-chord-define-global "JJ" 'save-buffer)
72 (key-chord-define-global "HH" 'save-buffer)
73 (key-chord-define-global "KK" 'save-buffer)
74 (key-chord-define-global "LL" 'save-buffer)
75 (key-chord-define-global "LL" 'save-buffer)
76 (key-chord-define-global "UU" 'save-buffer)
77 (key-chord-define-global "II" 'save-buffer)
78 (key-chord-define-global "OO" 'save-buffer)
79 (key-chord-define-global "NN" 'save-buffer)
80 (key-chord-define-global "MM" 'save-buffer)
81 (key-chord-define-global "PP" 'save-buffer)
82 (key-chord-define-global "YY" 'save-buffer)
83
84
85
86
87 (key-chord-define minibuffer-local-map "qq" "\C-g")
88
89
90 (key-chord-define minibuffer-local-map "jj"  'keyboard-escape-quit)
91 (key-chord-define minibuffer-local-ns-map "jj"  'keyboard-escape-quit)
92 (key-chord-define minibuffer-local-isearch-map "jj"  'keyboard-escape-quit)
93 (key-chord-define minibuffer-local-completion-map "jj"  'keyboard-escape-quit)
94 (key-chord-define minibuffer-local-must-match-map "jj"  'keyboard-escape-quit)
95 (key-chord-define minibuffer-local-must-match-filename-map "jj"  'keyboard-escape-quit)
96 (key-chord-define minibuffer-local-filename-completion-map "jj"  'keyboard-escape-quit)
97 (key-chord-define minibuffer-local-filename-must-match-map "jj"  'keyboard-escape-quit)
98
99
100
101 (key-chord-mode 1)
102
103 ;;;;;;;;;;;;;(provide 'init-keychord)
104
105
106 (setq mac-command-modifier 'super) ; make cmd key do Meta
107
108 ;; super key for elscreen tabs
109 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
110 (global-set-key (kbd "s-t") 'elscreen-create)
111 (global-set-key (kbd "s-n") 'elscreen-next)
112 (global-set-key (kbd "s-p") 'elscreen-previous)
113 ;;(global-set-key (kbd "s-k") (lambda () (interactive) (elscreen-kill (elscreen-get-current-screen))))
114 ;;(global-set-key (kbd "s-d") (lambda () (interactive) (elscreen-kill (elscreen-get-current-screen))))
115 ;; C-c C-d
116
117 (global-set-key (kbd "s-`") (lambda () (interactive) (elscreen-goto 0)))
118 (global-set-key (kbd "s-1") (lambda () (interactive) (elscreen-goto 1)))
119 (global-set-key (kbd "s-2") (lambda () (interactive) (elscreen-goto 2)))
120 (global-set-key (kbd "s-3") (lambda () (interactive) (elscreen-goto 3)))
121 (global-set-key (kbd "s-4") (lambda () (interactive) (elscreen-goto 4)))
122 (global-set-key (kbd "s-5") (lambda () (interactive) (elscreen-goto 5)))
123 (global-set-key (kbd "s-6") (lambda () (interactive) (elscreen-goto 6)))
124 (global-set-key (kbd "s-7") (lambda () (interactive) (elscreen-goto 7)))
125 (global-set-key (kbd "s-8") (lambda () (interactive) (elscreen-goto 8)))
126
127 ;; super key for windows
128 (global-set-key (kbd "s-l") 'split-window-below)
129 (global-set-key (kbd "s-h") 'split-window-right)
130 (global-set-key (kbd "s-i") 'other-window)
131 (global-set-key (kbd "s-j") 'delete-other-windows)
132
133 (global-set-key (kbd "s-k") (lambda () (interactive)
134                               (split-window-right)
135                               (other-window 1)
136                               (ido-find-file)))
137                                 
138                               
139
140
141 ;(global-set-key (kbd "M-g M-w") 'other-window)
142
143 ;;----------------------------------------------------------------------------
144 ;; C-o prefix binding for some File/Buffer switching/openning
145 ;;
146 (global-unset-key "\C-o")
147 ;;(global-set-key (kbd "C-o C-o") 'keyboard-quit);; same as C-g to quit
148 ;;; c-o c-o swith to normal mode 
149 (global-set-key (kbd "C-o C-o") 'evil-normal-state)
150 ;;(global-set-key (kbd "C-o C-o") 'fiplr-find-file)
151 (global-set-key (kbd "C-o C-f") 'ido-find-file)
152 (global-set-key (kbd "C-o C-n") 'recentf-ido-find-file)
153 (global-set-key (kbd "C-o C-j") 'ido-switch-buffer)
154 ;(global-set-key (kbd "C-o C-j") 'ido-find-file)
155
156
157 (global-set-key (kbd "C-o C-g") 'ggtags-find-file)
158 (global-set-key (kbd "C-o C-t") 'ggtags-find-tag-dwim)
159
160 (global-set-key (kbd "M-g M-g") 'magit-status)
161
162
163 (defun recentf-ido-find-file ()
164   "Find a recent file using Ido."
165   (interactive)
166   (let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
167     (when file
168       (find-file file))))
169
170
171 ;;----------------------------------------------------------------------------
172 ;; M-g prefix binding for some commands
173 ;;
174
175
176
177 (provide 'init-key-binding)