summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2017-06-27 22:50:12 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2017-06-27 23:02:02 (GMT)
commitc8be7f9ae91a463d94121891d0ec1b70b3c9f667 (patch)
tree2a138df8bf5340456348c58b7b62b7f3845e001b
parentfac8416e0200cd1c3a0fb7a6ff26d5a86cd73f4b (diff)
downloaddot-files-c8be7f9ae91a463d94121891d0ec1b70b3c9f667.zip
dot-files-c8be7f9ae91a463d94121891d0ec1b70b3c9f667.tar.gz
dot-files-c8be7f9ae91a463d94121891d0ec1b70b3c9f667.tar.bz2
emacs/vimrc/tmux.conf: improve working under tmux
Set $TERM to 'screen', and adjust vim/emacs accordingly.
-rw-r--r--emacs99
-rw-r--r--tmux.conf8
-rw-r--r--vimrc146
3 files changed, 196 insertions, 57 deletions
diff --git a/emacs b/emacs
index 15465a2..40229f1 100644
--- a/emacs
+++ b/emacs
@@ -210,3 +210,102 @@
(require 'jump-char)
(global-set-key [(meta m)] 'jump-char-forward)
(global-set-key [(shift meta m)] 'jump-char-backward)
+
+;; Correctly handle SHIFT/CTRL+Arrows inside TMUX
+;; from: https://github.com/dhellmann/emacs-settings/blob/master/lisp/tmux-settings.el
+;; https://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
+;; This requires:
+;; 1. "setw -g xterm-keys on" in ~/.tmux.conf
+;; 2. "$TERM == 'screen*' inside tmux
+
+;; http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
+;; Keybindings for inside tmux, requires
+;; setw -g xterm-keys on in .tmux.conf
+(if (string-prefix-p "screen" (getenv "TERM"))
+ (progn
+ (let ((x 2) (tkey ""))
+ (while (<= x 8)
+ ;; shift
+ (if (= x 2)
+ (setq tkey "S-"))
+ ;; alt
+ (if (= x 3)
+ (setq tkey "M-"))
+ ;; alt + shift
+ (if (= x 4)
+ (setq tkey "M-S-"))
+ ;; ctrl
+ (if (= x 5)
+ (setq tkey "C-"))
+ ;; ctrl + shift
+ (if (= x 6)
+ (setq tkey "C-S-"))
+ ;; ctrl + alt
+ (if (= x 7)
+ (setq tkey "C-M-"))
+ ;; ctrl + alt + shift
+ (if (= x 8)
+ (setq tkey "C-M-S-"))
+
+ ;; arrows
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
+ ;; home
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
+ ;; end
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
+ ;; page up
+ (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
+ ;; page down
+ (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
+ ;; insert
+ (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
+ ;; delete
+ (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
+ ;; f1
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
+ ;; f2
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
+ ;; f3
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
+ ;; f4
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
+ ;; f5
+ (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
+ ;; f6
+ (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
+ ;; f7
+ (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
+ ;; f8
+ (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
+ ;; f9
+ (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
+ ;; f10
+ (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
+ ;; f11
+ (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
+ ;; f12
+ (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
+ ;; f13
+ (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
+ ;; f14
+ (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
+ ;; f15
+ (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
+ ;; f16
+ (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
+ ;; f17
+ (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
+ ;; f18
+ (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
+ ;; f19
+ (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
+ ;; f20
+ (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
+
+ (setq x (+ x 1))
+ ))
+ )
+ )
diff --git a/tmux.conf b/tmux.conf
index 1ef0dd6..b6dec34 100644
--- a/tmux.conf
+++ b/tmux.conf
@@ -1,8 +1,10 @@
# Set the terminal (for colors + CTRL-arrows)
-set-option -g default-terminal "xterm"
-#set-option -g default-terminal "screen-256color"
+# by default, tmux sets $TERM to 'screen' - no need to change it.
+###set-option -g default-terminal "screen-256color"
-# Pass CTRL-Keys
+# Pass CTRL/SHIFT-arrows correctly
+# (for both VIM and Emacs, this requires extra configuration in .vimrc/.emacs)
+# To handle these keys if $TERM=="screen*"
set-window-option -g xterm-keys on
# Start numbering at 1
diff --git a/vimrc b/vimrc
index db717c9..c108565 100644
--- a/vimrc
+++ b/vimrc
@@ -1,3 +1,5 @@
+
+" Get used to moving with h/j/k/l
" See http://vimcasts.org/blog/2013/02/habit-breaking-habit-making/
"noremap <Up> <NOP>
"noremap <Down> <NOP>
@@ -29,8 +31,8 @@ set clipboard=unnamedplus
set makeprg=make " Use this program for ":make" command
set colorcolumn=78 "Highlight too-long lines
-set exrc " enable per-directory .vimrc files
-set secure " disable unsafe commands in local .vimrc files
+set exrc " enable per-directory .vimrc files
+set secure " disable unsafe commands in local .vimrc files
" Shift-tab to unindent
" for command mode
@@ -62,14 +64,15 @@ set wildmenu
" For Markdown files,
" use F5 to render them to HTML with GitHub CSS
-au BufRead,BufNewFile *.md set ts=4 sw=4 et nolist nowrap ai colorcolumn=75
-au BufRead,BufNewFile *.md map #5 :!mdpd.sh %
+" au BufRead,BufNewFile *.md set ts=4 sw=4 et nolist nowrap ai colorcolumn=75
+" au BufRead,BufNewFile *.md map #5 :!mdpd.sh %
" GNU Savannah wiki markdowns
-au BufRead,BufNewFile *.mdwn set ts=4 sw=4 et nolist nowrap ai colorcolumn=75
+" au BufRead,BufNewFile *.mdwn set ts=4 sw=4 et nolist nowrap ai colorcolumn=75
" HTML
-au BufRead,BufNewFile *.html set ts=2 sw=2 et nolist nowrap ai
-
+" au BufRead,BufNewFile *.html set ts=2 sw=2 et nolist nowrap ai
+" For Perl files
+" au BufRead,BufNewFile *.pl command! PC execute "!perl -c %"
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
@@ -77,15 +80,15 @@ if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
endif
" Only do this part when compiled with support for autocommands
-if has("autocmd")
- " In text files, always limit the width of text to 78 characters
- autocmd BufRead *.txt set tw=78
- " When editing a file, always jump to the last cursor position
- autocmd BufReadPost *
- \ if line("'\"") > 0 && line ("'\"") <= line("$") |
- \ exe "normal! g'\"" |
- \ endif
-endif
+"if has("autocmd")
+" " In text files, always limit the width of text to 78 characters
+" autocmd BufRead *.txt set tw=78
+" " When editing a file, always jump to the last cursor position
+" autocmd BufReadPost *
+" \ if line("'\"") > 0 && line ("'\"") <= line("$") |
+" \ exe "normal! g'\"" |
+" \ endif
+"endif
if has("cscope")
set csprg=/usr/bin/cscope
@@ -119,12 +122,14 @@ endif
" F1 - Turn off Search Pattern Highlighting
-map #1 :nohlsearch
-map! #1 :nohlsearch i
+map #1 :nohlsearch
+map! #1 :nohlsearch
+
" F2 - Save file
-map #2 :w
-map! #2 :w i
+map #2 :w
+map! #2 :w
+
" CTRL-C as copy to X11 clipboard
map <C-c> "+y<CR>
@@ -132,40 +137,42 @@ map <C-v> "+P<CR>
" F3 - Show Registers
-map #3 :reg
-imap #3 :reg
-"map O1;2R :cp
-"map! #3 :cn
-"map! O1;2R :cp
+map #3 :reg
+imap #3 :reg
+"map O1;2R :cp
+"map! #3 :cn
+"map! O1;2R :cp
" F4/Shift-F4 - Next/Previous error (from 'make' output)
-" Ctrl-F4 - show error list
+" Ctrl-F4 - show error list
"
" Note:
" <S-F4>, <C-F4> doesn't work on my terminal...
" replaced with corresponding escape sequences
-map <F4> :cn
-map O1;2S :cp
-map O1;5S :QFix
-map! <F4> :cn
-map! O1;2S :cp
-map! O1;5S :QFix
+map <F4> :cn
+map O1;2S :cp
+map O1;5S :cl
+map! <F4> :cn
+map! O1;2S :cp
+map! O1;5S :cl
" F6/Shift-F6 - Next/Previous buffer
-map <F6> :bn
-map <S-F6> :bp
-map <C-F6> :ls
-map! <S-F6> :bp imap! <F6> :bn imap! <C-F6> :ls
+map <F6> :bn
+map <S-F6> :bp
+map <C-F6> :ls
+map! <S-F6> :bp
+imap <F6> :bn
+imap <C-F6> :ls
" Also, Control-PageUp/Down do prev/next buffer
-map [5;5~ :bp
-map [6;5~ :bn
-imap [5;5~ :bp
-imap [6;5~ :bn
+map [5;5~ :bp
+map [6;5~ :bn
+imap [5;5~ :bp
+imap [6;5~ :bn
" F7 - make
-map #7 :make
-map! #7 :make
+map #7 :make
+map! #7 :make
" make 'Y' yank until the end of the line
map Y y$
@@ -176,22 +183,53 @@ map <C-]> :GtagsCursor<CR>
"Map Control-Baclspace to delete-previous-word
"in gnome-terminal, this requires a special patch the libvte9 (0.17)
-"map!  <C-O>b<C-O>dw
-"map  bdw
+map!  <C-O>b<C-O>dw
+map  bdw
"Map Control-Delete to delete-word under cursor
-"map! [3;5~ <C-O>dw
-"map [3;5~ dw
-
-"Map CTRL-Arrow-keys to next-word, prev-word
-map  b
-map  w
+map! [3;5~ <C-O>dw
+map [3;5~ dw
+
+
+" Vim will usually automatically set up its handling of these keys when TERM
+" is xterm-something, but it skips this since TERM is screen-256color. You can
+" manually configure these keys in your ~/.vimrc like this:
+" (from: https://superuser.com/a/402084)
+if &term =~ '^screen'
+ "Map CTRL-Arrow-keys to next-word, prev-word
+ map  b
+ map  w
+ map  5k
+ map  5j
+
+ "Map CTRL-Arrow-keys in INSERT mode, too
+ map!  <C-O>b
+ map!  <C-O>w
+ map!  <C-O>5k
+ map!  <C-O>5j
+ "
+
+ "Shift-Arrow keys (in normal mode) starts VISUAL SELECT mode and selects a word/line
+ nmap  vb
+ nmap  vw
+ nmap  vk
+ nmap  vj
+
+ " Shift-Arrow-keys (in visual select mode) just move a word/line
+ vmap  b
+ vmap  w
+ vmap  k
+ vmap  j
+endif
-"Map CTRL-Arrow-keys in INSERT mode, too
-map!  <C-O>b
-map!  <C-O>w
+" Load windows-like behavior:
+" shift+arrows mark characters ("SELECT" mode, similar to "VISUAL" mode)
+" CTRL+C,V,X = copy,paste,cut (also CTRL+INS,CTRL+DEL)
+" CTRL+Q is now enter literal character (like original CTRL-V)
+" CTRL+S is save file (even in insert mode)
+"so /usr/share/vim/vim70/mswin.vim
+"behave mswin
" Disable Markdown folding
" https://github.com/plasticboy/vim-markdown
let g:vim_markdown_folding_disabled=1
-