editor:vim
差異處
這裏顯示兩個版本的差異處。
| 兩邊的前次修訂版前次修改 下次修改 | 前次修改 | ||
| editor:vim [2010/01/07 21:08] – wenpei | editor:vim [2016/01/02 00:07] (目前版本) – sars | ||
|---|---|---|---|
| 行 82: | 行 82: | ||
| | :r < | | :r < | ||
| | :n |下個檔案| | | :n |下個檔案| | ||
| + | |||
| + | ====== Insert Mode ====== | ||
| + | ===== 自動補齊 ===== | ||
| + | http:// | ||
| + | |||
| + | | C-x C-l |行補齊| | ||
| + | | C-x C-n |以目前檔案做關鍵字補齊| | ||
| ====== tabs ====== | ====== tabs ====== | ||
| 行 122: | 行 129: | ||
| 另一種,會出現分割視窗。 | 另一種,會出現分割視窗。 | ||
| :TOhtml | :TOhtml | ||
| + | |||
| + | ===== 清除 html tag ===== | ||
| + | %s/< | ||
| ====== 在文件前加上行號 ====== | ====== 在文件前加上行號 ====== | ||
| 行 131: | 行 141: | ||
| ====== Plugins ====== | ====== Plugins ====== | ||
| + | ===== Vundle ===== | ||
| + | https:// | ||
| + | |||
| + | 管理外掛的工具 | ||
| + | |||
| + | ===== vimagit ===== | ||
| + | https:// | ||
| + | |||
| + | 和 git 結合方便操作 git | ||
| + | |||
| ===== snipMate ===== | ===== snipMate ===== | ||
| http:// | http:// | ||
| 行 155: | 行 175: | ||
| http:// | http:// | ||
| + | |||
| + | ===== nerd tree ===== | ||
| + | http:// | ||
| + | |||
| + | Allows you to explore the file system and open files and directories directly from vim. | ||
| ====== Reference ====== | ====== Reference ====== | ||
| Vim Cookbook:http:// | Vim Cookbook:http:// | ||
| - | ===== COSCUP 2009 by c9s ===== | + | COSCUP 2009 by c9s:http:// |
| - | http://www.slideshare.net/c9s/vim-hacks | + | |
| + | Vim Hacks (OSSF) by c9s:http:// | ||
| + | |||
| + | ===== vimrc ===== | ||
| + | http:// | ||
| + | |||
| + | < | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Maintainer: amix the lucky stiff | ||
| + | " | ||
| + | " | ||
| + | " Version: 3.3 - 21/01/10 01:05:46 | ||
| + | " | ||
| + | " Blog_post: | ||
| + | " | ||
| + | " Syntax_highlighted: | ||
| + | " | ||
| + | " Raw_version: | ||
| + | " | ||
| + | " | ||
| + | " How_to_Install: | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " How_to_Upgrade: | ||
| + | " | ||
| + | " | ||
| + | " Sections: | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " Plugins_Included: | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => General | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Sets how many lines of history VIM has to remember | ||
| + | set history=300 | ||
| + | |||
| + | " Enable filetype plugin | ||
| + | filetype plugin on | ||
| + | filetype indent on | ||
| + | |||
| + | " Set to auto read when a file is changed from the outside | ||
| + | set autoread | ||
| + | |||
| + | " With a map leader it's possible to do extra key combinations | ||
| + | " like < | ||
| + | let mapleader = "," | ||
| + | let g:mapleader = "," | ||
| + | |||
| + | " Fast saving | ||
| + | nmap < | ||
| + | |||
| + | " Fast editing of the .vimrc | ||
| + | map < | ||
| + | |||
| + | " When vimrc is edited, reload it | ||
| + | autocmd! bufwritepost vimrc source ~/ | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => VIM user interface | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Set 7 lines to the curors - when moving vertical.. | ||
| + | set so=7 | ||
| + | |||
| + | set wildmenu "Turn on WiLd menu | ||
| + | |||
| + | set ruler " | ||
| + | |||
| + | set cmdheight=2 "The commandbar height | ||
| + | |||
| + | set hid " | ||
| + | |||
| + | " Set backspace config | ||
| + | set backspace=eol, | ||
| + | set whichwrap+=<,>, | ||
| + | |||
| + | set ignorecase " | ||
| + | |||
| + | set hlsearch " | ||
| + | |||
| + | set incsearch "Make search act like search in modern browsers | ||
| + | |||
| + | set magic "Set magic on, for regular expressions | ||
| + | |||
| + | set showmatch "Show matching bracets when text indicator is over them | ||
| + | set mat=2 "How many tenths of a second to blink | ||
| + | |||
| + | " No sound on errors | ||
| + | set noerrorbells | ||
| + | set novisualbell | ||
| + | set t_vb= | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Colors and Fonts | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | syntax enable " | ||
| + | |||
| + | " Set font according to system | ||
| + | if MySys() == " | ||
| + | set gfn=Bitstream\ Vera\ Sans\ Mono:h13 | ||
| + | set shell=/ | ||
| + | elseif MySys() == " | ||
| + | set gfn=Bitstream\ Vera\ Sans\ Mono:h10 | ||
| + | elseif MySys() == " | ||
| + | set gfn=Monospace\ 10 | ||
| + | set shell=/ | ||
| + | endif | ||
| + | |||
| + | if has(" | ||
| + | set guioptions-=T | ||
| + | set background=dark | ||
| + | set t_Co=256 | ||
| + | set background=dark | ||
| + | colorscheme peaksea | ||
| + | |||
| + | set nu | ||
| + | else | ||
| + | colorscheme zellner | ||
| + | set background=dark | ||
| + | |||
| + | set nonu | ||
| + | endif | ||
| + | |||
| + | set encoding=utf8 | ||
| + | try | ||
| + | lang en_US | ||
| + | catch | ||
| + | endtry | ||
| + | |||
| + | set ffs=unix, | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Files and backups | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Turn backup off, since most stuff is in SVN, git anyway... | ||
| + | set nobackup | ||
| + | set nowb | ||
| + | set noswapfile | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Text, tab and indent related | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | set expandtab | ||
| + | set shiftwidth=4 | ||
| + | set tabstop=4 | ||
| + | set smarttab | ||
| + | |||
| + | set lbr | ||
| + | set tw=500 | ||
| + | |||
| + | set ai "Auto indent | ||
| + | set si "Smart indet | ||
| + | set wrap "Wrap lines | ||
| + | |||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => Visual mode related | ||
| + | """""""""""""""""""""""""""""" | ||
| + | " Really useful! | ||
| + | " | ||
| + | vnoremap < | ||
| + | vnoremap < | ||
| + | |||
| + | " When you press gv you vimgrep after the selected text | ||
| + | vnoremap < | ||
| + | map < | ||
| + | |||
| + | |||
| + | function! CmdLine(str) | ||
| + | exe "menu Foo.Bar :" . a:str | ||
| + | emenu Foo.Bar | ||
| + | unmenu Foo | ||
| + | endfunction | ||
| + | |||
| + | " From an idea by Michael Naumann | ||
| + | function! VisualSearch(direction) range | ||
| + | let l:saved_reg = @" | ||
| + | execute " | ||
| + | |||
| + | let l:pattern = escape(@", | ||
| + | let l:pattern = substitute(l: | ||
| + | |||
| + | if a:direction == ' | ||
| + | execute " | ||
| + | elseif a:direction == ' | ||
| + | call CmdLine(" | ||
| + | elseif a:direction == ' | ||
| + | execute " | ||
| + | endif | ||
| + | |||
| + | let @/ = l:pattern | ||
| + | let @" = l: | ||
| + | endfunction | ||
| + | |||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Command mode related | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Smart mappings on the command line | ||
| + | cno $h e ~/ | ||
| + | cno $d e ~/ | ||
| + | cno $j e ./ | ||
| + | cno $c e < | ||
| + | |||
| + | " $q is super useful when browsing on the command line | ||
| + | cno $q < | ||
| + | |||
| + | " Bash like keys for the command line | ||
| + | cnoremap < | ||
| + | cnoremap < | ||
| + | cnoremap < | ||
| + | |||
| + | cnoremap <C-P> < | ||
| + | cnoremap <C-N> < | ||
| + | |||
| + | " Useful on some European keyboards | ||
| + | map 翻 $ | ||
| + | imap 翻 $ | ||
| + | vmap 翻 $ | ||
| + | cmap 翻 $ | ||
| + | |||
| + | |||
| + | func! Cwd() | ||
| + | let cwd = getcwd() | ||
| + | return "e " . cwd | ||
| + | endfunc | ||
| + | |||
| + | func! DeleteTillSlash() | ||
| + | let g:cmd = getcmdline() | ||
| + | if MySys() == " | ||
| + | let g: | ||
| + | else | ||
| + | let g: | ||
| + | endif | ||
| + | if g:cmd == g: | ||
| + | if MySys() == " | ||
| + | let g: | ||
| + | else | ||
| + | let g: | ||
| + | endif | ||
| + | endif | ||
| + | return g: | ||
| + | endfunc | ||
| + | |||
| + | func! CurrentFileDir(cmd) | ||
| + | return a:cmd . " " . expand(" | ||
| + | endfunc | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Moving around, tabs and buffers | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Map space to / (search) and c-space to ? (backgwards search) | ||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | |||
| + | " Smart way to move btw. windows | ||
| + | map <C-j> < | ||
| + | map <C-k> < | ||
| + | map <C-h> < | ||
| + | map <C-l> < | ||
| + | |||
| + | " Close the current buffer | ||
| + | map < | ||
| + | |||
| + | " Close all the buffers | ||
| + | map < | ||
| + | |||
| + | " Use the arrows to something usefull | ||
| + | map < | ||
| + | map < | ||
| + | |||
| + | " Tab configuration | ||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | |||
| + | " When pressing < | ||
| + | map < | ||
| + | |||
| + | |||
| + | command! Bclose call < | ||
| + | function! < | ||
| + | let l: | ||
| + | let l: | ||
| + | |||
| + | if buflisted(l: | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | if bufnr(" | ||
| + | new | ||
| + | | ||
| + | |||
| + | if buflisted(l: | ||
| + | | ||
| + | | ||
| + | endfunction | ||
| + | |||
| + | " Specify the behavior when switching between buffers | ||
| + | try | ||
| + | set switchbuf=usetab | ||
| + | set stal=2 | ||
| + | catch | ||
| + | endtry | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => Statusline | ||
| + | """""""""""""""""""""""""""""" | ||
| + | " Always hide the statusline | ||
| + | set laststatus=2 | ||
| + | |||
| + | " Format the statusline | ||
| + | set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c | ||
| + | |||
| + | |||
| + | function! CurDir() | ||
| + | let curdir = substitute(getcwd(), | ||
| + | return curdir | ||
| + | endfunction | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Parenthesis/ | ||
| + | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | vnoremap $1 < | ||
| + | vnoremap $2 < | ||
| + | vnoremap $3 < | ||
| + | vnoremap $$ < | ||
| + | vnoremap $q < | ||
| + | vnoremap $e < | ||
| + | |||
| + | " Map auto complete of (, ", ', [ | ||
| + | inoremap $1 ()< | ||
| + | inoremap $2 []< | ||
| + | inoremap $3 {}< | ||
| + | inoremap $4 {< | ||
| + | inoremap $q ''< | ||
| + | inoremap $e ""< | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => General Abbrevs | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | iab xdate < | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Editing mappings | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | "Remap VIM 0 | ||
| + | map 0 ^ | ||
| + | |||
| + | "Move a line of text using ALT+[jk] or Comamnd+[jk] on mac | ||
| + | nmap <M-j> mz: | ||
| + | nmap <M-k> mz: | ||
| + | vmap <M-j> : | ||
| + | vmap <M-k> : | ||
| + | |||
| + | if MySys() == " | ||
| + | nmap <D-j> < | ||
| + | nmap <D-k> < | ||
| + | vmap <D-j> < | ||
| + | vmap <D-k> < | ||
| + | endif | ||
| + | |||
| + | " | ||
| + | func! DeleteTrailingWS() | ||
| + | exe " | ||
| + | %s/ | ||
| + | exe " | ||
| + | endfunc | ||
| + | autocmd BufWrite *.py :call DeleteTrailingWS() | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Cope | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Do :help cope if you are unsure what cope is. It's super useful! | ||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => bufExplorer plugin | ||
| + | """""""""""""""""""""""""""""" | ||
| + | let g: | ||
| + | let g: | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => Minibuffer plugin | ||
| + | """""""""""""""""""""""""""""" | ||
| + | let g: | ||
| + | let g: | ||
| + | let g: | ||
| + | let g: | ||
| + | let g: | ||
| + | let g: | ||
| + | let g: | ||
| + | |||
| + | let g: | ||
| + | |||
| + | autocmd BufRead, | ||
| + | |||
| + | map < | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Omni complete functions | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | autocmd FileType css set omnifunc=csscomplete# | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => Spell checking | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " | ||
| + | map < | ||
| + | |||
| + | " | ||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | map < | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => Python section | ||
| + | """""""""""""""""""""""""""""" | ||
| + | au FileType python set nocindent | ||
| + | let python_highlight_all = 1 | ||
| + | au FileType python syn keyword pythonDecorator True None False self | ||
| + | |||
| + | au BufNewFile, | ||
| + | au BufNewFile, | ||
| + | |||
| + | au FileType python inoremap < | ||
| + | au FileType python inoremap < | ||
| + | au FileType python inoremap < | ||
| + | au FileType python inoremap < | ||
| + | au FileType python map < | ||
| + | au FileType python map < | ||
| + | au FileType python map < | ||
| + | au FileType python map < | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => JavaScript section | ||
| + | """"""""""""""""""""""""""""""" | ||
| + | au FileType javascript call JavaScriptFold() | ||
| + | au FileType javascript setl fen | ||
| + | au FileType javascript setl nocindent | ||
| + | |||
| + | au FileType javascript imap <c-t> AJS.log();< | ||
| + | au FileType javascript imap <c-a> alert();< | ||
| + | |||
| + | au FileType javascript inoremap < | ||
| + | au FileType javascript inoremap < | ||
| + | |||
| + | function! JavaScriptFold() | ||
| + | setl foldmethod=syntax | ||
| + | setl foldlevelstart=1 | ||
| + | syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend | ||
| + | |||
| + | function! FoldText() | ||
| + | return substitute(getline(v: | ||
| + | endfunction | ||
| + | setl foldtext=FoldText() | ||
| + | endfunction | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => Fuzzy finder | ||
| + | """""""""""""""""""""""""""""" | ||
| + | try | ||
| + | call fuf# | ||
| + | map < | ||
| + | catch | ||
| + | endtry | ||
| + | |||
| + | |||
| + | """""""""""""""""""""""""""""" | ||
| + | " => Vim grep | ||
| + | """""""""""""""""""""""""""""" | ||
| + | let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated' | ||
| + | set grepprg=/ | ||
| + | |||
| + | |||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " => MISC | ||
| + | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| + | " Remove the Windows ^M - when the encodings gets messed up | ||
| + | noremap < | ||
| + | |||
| + | " | ||
| + | map < | ||
| + | </ | ||
| ===== by 紅塵一隅間拾得 ===== | ===== by 紅塵一隅間拾得 ===== | ||
| 行 299: | 行 889: | ||
| http:// | http:// | ||
| + | |||
| + | ====== VIM Color Scheme Test - Perl ====== | ||
| + | http:// | ||
| + | |||
editor/vim.1262869733.txt.gz · 上一次變更: 由 wenpei
