vim/vi
Saturday, October 27 2007 at 18:30, posted by Norman
WednesDay, October 1 2008 at 18:30, updated by Norman
Vi is a very good and popular editor under Linux. I was not a big fan of it before, but after a few years of using it. Finally I felt it is better than emacs in general. Here is a configuration file(~/.vimrc) that I am using now.
In normal mode:
| :e filename | open file. |
| :range s[ubstitute]/pattern/string/cgiI | For each line in the range replace a match of the pattern with the string where: c Confirm each substitution g Replace all occurrences in the line (without g - only first). i Ignore case for the pattern. I Don't ignore case for the pattern. This command replaces every search_string on the current line with replacement_string. rang can be numbers or %: whole file. |
| <UP> or <DOWN> arrow | command history |
| i | start editing at current position |
| a | start editing after cursor | o | start editing at next line |
| /string | search string. |
| v | Visual mode |
| CTRL-V | Visual block mode |
| mx | Mark current cursor position |
| `x | Go to marked position |
| . | Repeat last command |
| xG | Go to line x, go the the end of the file is no x |
| 0 | Go to the beginning of the line |
| <ENTER> | Go to the beginning of the next line |
In Visual Mode:
= indent selected area(very useful)
My .vimrc file
"set up the back up dir
let myuid=substitute(system('id'), '^uid=\([0-9]*\)(.*', '\1', "")
let vimtdir=$HOME . '/vimtmp'
if isdirectory(vimtdir) == 0
let vimtdir=$HOME
endif
if myuid == "0" && osys =~ "SunOS"
let vimtdir='/var/vimtmp'
endif
set backup
let &backupdir=vimtdir
set history=100
"set number
"set nowrap
""" color
set background=dark
if exists("syntax_on")
syntax reset
endif
hi clear
set noerrorbells
set novisualbell " don't blink
set gcr=a:blinkon0
""" space
set tabstop=3
set shiftwidth=3
"set softtabstop=3 " unify
"set expandtab ""use space
set laststatus=2
""" cmd
set showcmd
set nowarn
set ignorecase
"set smartcase
set showmatch
set mat=5
set wildmenu
set statusline=%F%m%r%h%w\ [%04l,%04v][%p%%]\ [LEN=%L]\ [ASCII=\%03.3b]\
"set ai " autoindent
"set si " smartindent
set cindent " do c-style indenting
set so=5
"" table keymaping
map <F2> <ESC>:tabnew<SPACE>
map <F3> <ESC>:%s/
map <F4> <ESC>:q<CR>
map <F5> <ESC>:make<CR>
map <F6> <ESC>:cnext<CR>
map <F7> <ESC>:clist!<CR>
map <F8> <ESC>:make -f<SPACE>
map <F9> <ESC>:tabn<CR>
imap <F2> <ESC>:tabnew<SPACE>
imap <F3> <ESC>:%s/
imap <F4> <ESC>:q<CR>
imap <F5> <ESC>:make<CR>
imap <F6> <ESC>:cnext<CR>
imap <F7> <ESC>:clist!<CR>
imap <F8> <ESC>:make -f<SPACE>
imap <F9> <ESC>:tabn<CR>
emacs
Saturday, October 27 2007 at 18:30, posted by Norman
Wednesday, October 1 2008 at 22:30, updated by Norman
Emacs is very powerful, but I only use it as a editor. Here is the configuration file(~/.emacs) I am using now. I got most parts of it from the internet. I put them here so next time when I want them, I don\'t have to google again. I feel it easy for people from Windows to learn this than vi. Just need to remember about 5 key combinations, then you can start. So it really fit for people from Windows
CTRL+x CTRL+f: open file. The cursor should go to the last line, status bar. then just input the file name.
CTRL+x CTRL+s: save file.
CTRL+x CTRL+c: exit emacs, it will ask you to save files if any files are changed.
CTRL+s: search, after input the string you want to search, continue press CTRL+s will find all in the current buffer.
In Windows, my favorite editor was UltraEdit, which is super powerful, column mode, edit remote files... It can do everything and everybody can fall in love with it if he/she is willing to pay. But now I love Notepad++ more. It is also powerful, light weight and full of features. I like it's coding style more than UltraEdit. And it is free!
Here is the configuration files for emacs and vi/vim(only used them in Linux/UNIX although they all have windows versions)
My .emacs file
;; .emacs
;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)
;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))
;; enable visual feedback on selections
;;(setq transient-mark-mode t)
;; default to better frame titles
;;(setq frame-title-format
;;(concat "%b - emacs@" system-name))
;; default to unified diffs
(setq diff-switches "-u")
;; added by Norman Zeng
;;
;; use F3 key to kill current buffer
(global-set-key [f3] 'kill-this-buffer)
;; disable startup message
(setq inhibit-startup-message t)
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(auto-compression-mode t nil (jka-compr))
'(blink-cursor-mode nil t)
'(case-fold-search t)
'(column-number-mode t)
'(current-language-environment "English")
'(default-input-method "chinese-py-punct")
'(display-time-mode t t)
'(global-font-lock-mode t nil (font-lock))
'(show-paren-mode t nil (paren))
'(transient-mark-mode t))
;; display the current time
;;(display-time)
;; Show column number at bottom of screen
;;(column-number-mode 1)
;;;; show bracket matching
(require 'paren)
(show-paren-mode t)
;; set tab and indent size
(setq default-tab-width 3)
(setq-default c-basic-offset 3)
;; goto line function C-x C-g
(global-set-key [ (control x) (control g) ] 'goto-line)
;; alias y to yes and n to no
(defalias 'yes-or-no-p 'y-or-n-p)
;; undo and redo functionality with special module
;;(require 'redo)
;;(global-set-key (kbd "C-x C-r") 'redo)
;;(global-set-key [ (control x) (r)] 'redo)
(global-set-key [ (control x) (control u)] 'undo)
;; highlight matches from searches
(setq isearch-highlight t)
(setq search-highlight t)
(setq-default transient-mark-mode t)
;;(when (fboundp 'blink-cursor-mode)
;;(blink-cursor-mode -1))
;; Pgup/dn will return exactly to the starting point.
(setq scroll-preserve-screen-position 1)
;;; Pretty colors
;;(global-font-lock-mode 1)
;;add following line if emacs start slow
(modify-frame-parameters nil '((wait-for-wm . nil)))
(set-default-font "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1")
;;(set-default-font "-misc-fixed-medium-*-normal--18-120-100-100-c-90-iso10646-1")
(setq default-frame-alist
'(
;; frame width and height
(width . 110)
(height . 50)
)
)
;;;(set-background-color "dark")
;;;(set-foreground-color "green")
(set-cursor-color "green")
;;; set paste to cursor
(setq mouse-yank-at-point t)
;; setup scroll mouse settings
;;(defun up-slightly () (interactive) (scroll-up 5))
;;(defun down-slightly () (interactive) (scroll-down 5))
;;(global-set-key [mouse-4] 'down-slightly)
;;(global-set-key [mouse-5] 'up-slightly)
;;(defun up-one () (interactive) (scroll-up 1))
;;(defun down-one () (interactive) (scroll-down 1))
;;(global-set-key [S-mouse-4] 'down-one)
;;(global-set-key [S-mouse-5] 'up-one)
;;(defun up-a-lot () (interactive) (scroll-up))
;;(defun down-a-lot () (interactive) (scroll-down))
;;(global-set-key [C-mouse-4] 'down-a-lot)
;;(global-set-key [C-mouse-5] 'up-a-lot)
;(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
;; )