Reading notes of Learning the vi and Vim Editors


* Notes of Learning the vi and Vim Editors

repeat last command                             :: .

Movements                                       :: w W b B e E ( ) { } [[   0 ^ n| $ gg G 200G
move to char                                    :: fx Fx tx Tx   (; continue forward and ' for backward)
move on screen                                  :: H M L 2H 
Actions                                         :: d c y

append at line end                              :: A
insert at line begin                            :: I
delete char                                     :: x X

open line up and down                           :: o O
paste up and line                               :: p P
delete line and insert                          :: S   //same as ddi or cc
(number prefix)write 50 *                       :: 50i*

set-mark in vi                                  :: mx (x for any letter)
goto mark                                       :: `x

delete line                                     :: dd
delete from cursor to end                       :: D
undo                                            :: u U
redo                                            :: ctrl+R

center current line                             :: Z.

paste from named delete buffer                  :: "3p
yank to named buffera                           :: "a4yy
append to named buffer a                        :: "A4yy
paste from named buffer                         :: "ap

paste                                           :: p P
single char                                     :: x r

search                                          :: / ? n N
line-matches-regex                              :: g/pattern/p
line-non-matches-regex                          :: g!/pattern
replace once                                    :: s/old/new
emit another replace in command mode            :: &
replace all occurs in line                      :: s/old/new/g
replace all occurs in file                      :: %s/old/new/g    (% stands for all lines, like 1,% prefix to s command 1,%s/old/new/g)
replace with confirm                            :: s/old/new/gc
only do replace in line matches patterns        :: :g/pattern/s/old/new/g
add () to lines                                 :: :%s/.*/(&)/              (& stands for whole match line)
replace with regex                              :: :%s/\(this\) or \(that\)/\2 or \1/g
replace Fortran to FORTRAN                      :: %s/Fortran/\U&/      (also has \L for lowercase)

save buffer before replace                      :: :w
revert buffer to last saved state               :: e!

edit another file foo                           :: :e foo
switch files in vi                              :: :n :rewind :last

line info                                       :: ctrl+G

append to word end                              :: ea
delete to file end                              :: dG
change to line end                              :: c$ C
goto line 100                                   :: 100G
toggle line number                              :: :set nu  :set nonu

split window                                    :: :split :vsplit
move between windows                            :: ^wj ^wk ^wh ^wl


[emacs] copy until char (like zap-to-char)


Today, When we doing a story with a piece of XML like this:


I feel not convenient to copy out the S-123456789

So I wrote a new copy-without-selection function copy-to-char function (like zap-to-char):
(defun copy-to-char (arg char)
  "Copy until char like zap-to-char"
  (interactive "p\ncZap to char: ")
  (let ((start (point)))
      (copy-region-as-kill start (progn
                         (search-forward (char-to-string char) nil nil arg)
(global-set-key (kbd "C-c c") 'copy-to-char)