shepherdwind / vim

my vim config file
0 stars 0 forks source link

vim简单配置 #1

Open shepherdwind opened 10 years ago

shepherdwind commented 10 years ago
if has('win32')
    let $VIMFILES = $VIM.'/vimfiles'
else
    let $VIMFILES = $HOME.'/.vim'
endif
"指定英文逗号作为<leader>键
let mapleader=","
set nocompatible
set nobackup
" 重启后撤销历史可用 persistent undo 
set undofile
set undodir=$VIMFILES/bak
set undolevels=1000 "maximum number of changes that can be undone

set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time
set showcmd     " display incomplete commands
set incsearch       " do incremental searching

" 把shell设置为bash
set shell=/bin/bash

map Q gq
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent        " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

if has("mac")
  set guifont=Monaco:h14
endif

" 配置多语言环境
if has("multi_byte")
    " UTF-8 编码
    set encoding=utf-8
    set termencoding=utf-8
    set formatoptions+=mM
    set fenc=utf-8
    set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936

    if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
        set ambiwidth=double
    endif

    if has("win32")
        source $VIMRUNTIME/delmenu.vim
        source $VIMRUNTIME/menu.vim
        language messages zh_CN.utf-8
    endif
else
    echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif

set relativenumber

"窗口分割时,进行切换的按键热键需要连接两次,比如从下方窗口移动
"光标到上方窗口,需要<c-w><c-w>k,非常麻烦,现在重映射为<c-k>,切换的
"时候会变得非常方便.
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

color Tomorrow-Night

set expandtab
set shiftwidth=2
set tabstop=2
au FileType html,css,vim,javascript setl shiftwidth=2
au FileType html,css,vim,javascript setl tabstop=2
au FileType java,php,pascal setl shiftwidth=4
au FileType java,php,pascal setl tabstop=4
au FileType python setlocal tabstop=8 expandtab shiftwidth=4 softtabstop=4
au BufNewFile,BufRead *.md set filetype=markdown

set smarttab
set lbr

set tw=78
set fo+=m
"Auto indent
set ai
set si
set cindent
set wrap

if has("win32")
  au GUIENTER * simalt ~x "vi自动最大化
endif

set complete-=k complete+=k

"双击m键删除^M符号
nmap mm :%s/\r//g<cr>
nnoremap <leader>cfg :e $VIMFILES/config.vim<CR>
nnoremap <leader>so :source $VIMFILES/config.vim<cr>

nnoremap <leader><space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
wsdjeg commented 9 years ago

楼主真是一个很细新的人,看过你在玉伯的博客中的回复,也想着到你这里来看看,你的这个配置文件标注的很详细,我很喜欢折腾vim,但是目前学习资料太少,网上可以找到的资料也很少,很难系统的学习viml,目前只能通过看插件源码来学习了,正则方面的只是最匮乏,很多可以想到的功能却无法自己实现!

shepherdwind commented 9 years ago

Viml系统学习可以看看这本书 http://learnvimscriptthehardway.stevelosh.com/

wsdjeg commented 9 years ago

这本书我已经看完了,目前尝试着自己写一些功能,都加在自己的vimrc中,目前遇到了一个问题,就是如何判断输入位置是否在注释中,您是否知道有此类功能的插件,我去看看他是怎么写的。 另外就是想了解正则的知识。

shepherdwind commented 9 years ago

我感觉vim没有必要深入学习,vim是工具,最好的学习还是用vim。写插件的话,vim自身的语法还是有点难用的,调试啥的都没有很好的解决方案。

wsdjeg commented 9 years ago

没有太明白你的意思,我不是做IT的,学习这个纯粹兴趣,只是想学习下正则,以及基本的vim语法,实现自己需要的功能,另外就是更方便的管理插件,在需要的时候开启某些功能