当前位置: 技术问答>linux和unix
Vim语法高亮设置不成功!
来源: 互联网 发布时间:2016-09-15
本文导语: " All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just " /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime " you can find below. If you wish to change any of those settings, you should " do it in this f...
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below. If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed. It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'"") > 1 && line("'"") Colors and Font
" *> Fileformat
" *> VIM userinterface
" ------ *> Statusline
" *> Visual
" *> Moving around and tab
" *> General Autocommand
" *> Parenthesis/bracket expanding
" *> General Abbrev
" *> Editing mappings etc.
" *> Command-line config
" *> Buffer realted
" *> Files and backup
" *> Folding
" *> Text option
" ------ *> Indent
" *> Spell checking
" *> Plugin configuration
" ------ *> Yank ring
" ------ *> File explorer
" ------ *> Minibuffer
" ------ *> Tag list (ctags) - not used
" ------ *> LaTeX Suite thing
" *> Filetype generic
" ------ *> Todo
" ------ *> VIM
" ------ *> HTML related
" ------ *> Ruby & PHP section
" ------ *> Python section
" ------ *> Cheetah section
" ------ *> Java section
" ------ *> JavaScript section
" ------ *> C mapping
" ------ *> SML
" ------ *> Scheme binding
" *> Snippet
" ------ *> Python
" ------ *> javaScript
" *> Cope
" *> MISC
"
" Tip:
" If you find anything that you can't understand than do this:
" help keyword OR helpgrep keyword
" Example:
" Go into command-line mode and type helpgrep nocompatible, ie.
" :helpgrep nocompatible
" then press c to see the results, or :botright cw
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Get out of VI's compatible mode..
set nocompatible
function! MySys()
return "win32"
endfunction
"Set shell to be bash
if MySys() == "linux" || MySys() == "mac"
set shell=bash
else
"I have to run win32 python without cygwin
"set shell=E:cygwinbinsh
endif
"Sets how many lines of history VIM har to remember
set history=400
"Enable filetype plugin
if has("eval")
filetype plugin on
filetype indent on
endif
"Set to auto read when a file is changed from the outside
set autoread
"Have the mouse enabled all the time:
set mouse=a
"Set mapleader
let mapleader = ","
let g:mapleader = ","
"Fast saving
nmap w :w!
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Font
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable syntax hl
syntax on
"Set font to Monaco 10pt
"if MySys() == "mac"
" set gfn=Bitstream Vera Sans Mono:h14
" set nomacatsui
" set termencoding=macroman
"elseif MySys() == "linux"
" set gfn=Monospace 11
" "set encoding=utf-8
"endif
"internationalization
"I only work in Win2k Chinese version
if has("multi_byte")
set termencoding=chinese
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese
endif
"if you use vim in tty,
"'uxterm -cjk' or putty with option 'Treat CJK ambiguous characters as wide' on
if has("ambiwidth")
set ambiwidth=double
endif
if has("gui_running")
"set guioptions-=m
"set guioptions-=T
set guioptions-=l
set guioptions-=L
"set guioptions-=r
set guioptions-=R
if MySys()=="win32"
"start gvim maximized
"if has("autocmd")
"au GUIEnter * simalt ~x
"endif
endif
"let psc_
"colorscheme ps_color
"colorscheme default
else
"set background=dark
"colorscheme default
endif
"Some nice mapping to switch syntax (useful if one mixes different languages in one file)
map 1 :set syntax=cheetah
map 2 :set syntax=xhtml
map 3 :set syntax=python
map 4 :set ft=javascript
map $ :syntax sync fromstart
"Highlight current
if has("gui_running")
if has("cursorline")
set cursorline
"hi cursorline guibg=#333333
"hi CursorColumn guibg=#333333
endif
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Fileformat
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Favorite filetype
set ffs=unix,dos,mac
nmap fd :se ff=dos
nmap fu :se ff=unix
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Set 7 lines to the curors - when moving vertical..
set so=7
"Turn on WiLd menu
set wildmenu
"Always show current position
set ruler
"The commandbar is 2 high
set cmdheight=2
"Show line number
set nu
"Do not redraw, when running macros.. lazyredraw
set lz
"Change buffer - without saving
set hid
"set current curline
set cursorline
"Set backspace
set backspace=eol,start,indent
"Bbackspace and cursor keys wrap to
set whichwrap+=,h,l
"Ignore case when searching
"set ignorecase
set incsearch
"Set magic on
set magic
"No sound on errors.
set noerrorbells
set novisualbell
set t_vb=
"show matching bracet
set showmatch
"How many tenths of a second to blink
set mat=4
"Highlight search thing
set hlsearch
""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
"Always hide the statusline
set laststatus=2
function! CurDir()
let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
return curdir
endfunction
"Format the statusline
set statusline=
set statusline+=%f "path to the file in the buffer, relative to current directory
set statusline+= %h%1*%m%r%w%0* " flag
set statusline+= [%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
set statusline+=%{&fileformat}] " file format
set statusline+= CWD:%r%{CurDir()}%h
set statusline+= Line:%l/%L
""""""""""""""""""""""""""""""
" => Visual
""""""""""""""""""""""""""""""
" From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '/.*$^~[]')
let l:pattern = substitute(l:pattern, " $", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
else
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
"Basically you press * or # to search for the current selection !! Really useful
vnoremap * :call VisualSearch('f')
vnoremap # :call VisualSearch('b')
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around and tab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Map space to / and c-space to ?
map /
"map ?
"Smart way to move btw. window
map j
map k
map h
map l
"Actually, the tab does not switch buffers, but my arrow
"Bclose function ca be found in "Buffer related" section
"map bd :Bclose
"map bd
"Use the arrows to something usefull
"map :bn
"map :bp
"Tab configuration
map tn :tabnew %
map tc :tabclose
map tm :tabmove
if has("usetab")
set switchbuf=usetab
endif
if has("stal")
set stal=2
endif
"Moving fast to front, back and 2 sides ;)
imap $a
imap 0i
imap $a
imap 0i
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Autocommand
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Switch to current dir
map cd :cd %:p:h
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 `>a)` Command-line config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc
func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "(.*[/]).*", "1", "")
else
let g:cmd_edited = substitute(g:cmd, "(.*[\]).*", "1", "")
endif
if g:cmd == g:cmd_edited
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "(.*[/]).*/", "1", "")
else
let g:cmd_edited = substitute(g:cmd, "(.*[\]).*[\]", "1", "")
endif
endif
return g:cmd_edited
endfunc
func! CurrentFileDir(cmd)
return a:cmd . " " . expand("%:p:h") . "/"
endfunc
"cno $q eDeleteTillSlash()
"cno $c e eCurrentFileDir("e")
"cno $tc eCurrentFileDir("tabnew")
cno $th tabnew ~/
cno $td tabnew ~/Desktop/
"Bash like
cno
cno
cno
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Fast open a buffer by search for a name
"map :sb
"Open a dummy buffer for paste
map q :e ~/buffer
"Restore cursor to file position in previous editing session
set viminfo='10,"100,:20,%,n~/.viminfo
" Buffer - reverse everything ... :)
map ggVGg?
" Don't close window, when deleting a buffer
command! Bclose call BufcloseCloseIt()
function! BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute "bdelete! ".l:currentBufNum
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files and backup
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Turn backup off
set nobackup
set nowb
"set noswapfile
set noar
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
set fen
set fdl=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text option
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" python script
"set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set backspace=2
set smarttab
set lbr
"set tw=500
""""""""""""""""""""""""""""""
" => Indent
""""""""""""""""""""""""""""""
"Auto indent
set ai
"Smart indet
set si
"C-style indenting
set cindent
"Wrap line
set wrap
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map sn ]
map sp [
map sa zg
map s? z=
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => Yank Ring
""""""""""""""""""""""""""""""
map y :YRShow
""""""""""""""""""""""""""""""
" => File explorer
""""""""""""""""""""""""""""""
"Split vertically
let g:explVertical=1
"Window size
let g:explWinSize=35
let g:explSplitLeft=1
let g:explSplitBelow=1
"Hide some file
let g:explHideFiles='^.,.*.class$,.*.swp$,.*.pyc$,.*.swo$,.DS_Store$'
"Hide the help thing..
let g:explDetailedHelp=0
""""""""""""""""""""""""""""""
" => Minibuffer
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 0
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1
"WindowZ
map :WMToggle
let g:bufExplorerSortBy = "name"
""""""""""""""""""""""""""""""
" => Tag list (ctags) - not used
""""""""""""""""""""""""""""""
"let Tlist_Ctags_Cmd = "/sw/bin/ctags-exuberant"
"let Tlist_Sort_Type = "name"
"let Tlist_Show_Menu = 1
"map t :Tlist
map :Tlist
map :NERDTreeToggle
""""""""""""""""""""""""""""""
" => LaTeX Suite thing
""""""""""""""""""""""""""""""
"set grepprg=grep -r -s -n
let g:Tex_DefaultTargetFormat="pdf"
let g:Tex_ViewRule_pdf='xpdf'
if has("autocmd")
"Binding
au BufRead *.tex map :w! :silent! call Tex_RunLaTeX()
"Auto complete some things ;)
au BufRead *.tex ino $i indent
au BufRead *.tex ino $* cdot
au BufRead *.tex ino $i item
au BufRead *.tex ino $m []O
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Filetype generic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Todo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim
""""""""""""""""""""""""""""""
" => VIM
""""""""""""""""""""""""""""""
if has("autocmd")
au BufRead,BufNew *.vim map :w!:source %
endif
""""""""""""""""""""""""""""""
" => HTML related
""""""""""""""""""""""""""""""
" HTML entities - used by xml edit plugin
let xml_use_xhtml = 1
"let xml_no_auto_nesting = 1
"To HTML
let html_use_css = 0
let html_number_lines = 0
let use_xhtml = 1
""""""""""""""""""""""""""""""
" => Ruby & PHP section
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => Python section
""""""""""""""""""""""""""""""
""Run the current buffer in python - ie. on leader+space
"au BufNewFile,BufRead *.py so ~/vim_local/syntax/python.vim
"au BufNewFile,BufRead *.py map :w!:!python %
"au BufNewFile,BufRead *.py so ~/vim_local/plugin/python_fold.vim
""Set some bindings up for 'compile' of python
"au BufNewFile,BufRead *.py set makeprg=python -c "import py_compile,sys; sys.stderr=sys.stdout; py_compile.compile(r'%')"
"au BufNewFile,BufRead *.py set efm=%C %.%#,%A File "%f", line %l%.%#,%Z%[%^ ]%@=%m
"au BufNewFile,BufRead *.py nmap :w!:make
""Python iMap
"au BufNewFile,BufRead *.py set cindent
"au BufNewFile,BufRead *.py ino $r return
"au BufNewFile,BufRead *.py ino $s self
"au BufNewFile,BufRead *.py ino $c ####kla
"au BufNewFile,BufRead *.py ino $i import
"au BufNewFile,BufRead *.py ino $p print
"au BufNewFile,BufRead *.py ino $d """"""O
""Run in the Python interpreter
"function! Python_Eval_VSplit() range
" let src = tempname()
" let dst = tempname()
" execute ": " . a:firstline . "," . a:lastline . "w " . src
" execute ":!python " . src . " > " . dst
" execute ":pedit! " . dst
"endfunction
"au BufNewFile,BufRead *.py vmap :call Python_Eval_VSplit()
""""""""""""""""""""""""""""""
" => Cheetah section
"""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""
" => Java section
"""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => JavaScript section
"""""""""""""""""""""""""""""""
"au BufNewFile,BufRead *.js so ~/vim_local/syntax/javascript.vim
"function! JavaScriptFold()
" set foldmethod=marker
" set foldmarker={,}
" set foldtext=getline(v:foldstart)
"endfunction
"au BufNewFile,BufRead *.js call JavaScriptFold()
"au BufNewFile,BufRead *.js imap console.log();hi
"au BufNewFile,BufRead *.js imap alert();hi
"au BufNewFile,BufRead *.js set nocindent
"au BufNewFile,BufRead *.js ino $r return
"au BufNewFile,BufRead *.js ino $d //////ka
"au BufNewFile,BufRead *.js ino $c /****/ka
if has("eval") && has("autocmd")
fun! abbrev_cpp()
iabbrev cci const_iterator
iabbrev ccl cla
iabbrev cco const
iabbrev cdb bug
iabbrev cde throw
iabbrev cdf /** file/
iabbrev cdg ingroup
iabbrev cdn /** namespace/
iabbrev cdp param
iabbrev cdt test
iabbrev cdx /**/
iabbrev cit iterator
iabbrev cns namespace
iabbrev cpr protected
iabbrev cpu public
iabbrev cpv private
iabbrev csl std::list
iabbrev csm std::map
iabbrev css std::string
iabbrev csv std::vector
iabbrev cty typedef
iabbrev cun using namespace
iabbrev cvi virtual
iabbrev #i #include
iabbrev #d #define
endfun
fun! abbrev_java()
iabbrev #i import
iabbrev #p System.out.println
iabbrev #m public static void main(String[] args
endfun
fun! abbrev_python()
iabbrev #i import
iabbrev #p print
iabbrev #m if __name__=="__main":
endfun
augroup abbreviation
autocmd!
autocmd FileType cpp,c :call abbrev_cpp()
autocmd FileType java :call abbrev_java()
autocmd FileType python :call abbrev_python()
augroup END
endif
cs add ./cscope.out
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remove the Windows ^M
noremap m :%s/r//g
"Paste toggle - when pasting something in, don't indent.
"set pastetoggle=
"Remove indenting on empty line
map :%s/s*$//g:noh''
"Super paste
ino :set pastemui+mv'uV'v=:set nopaste
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below. If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed. It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'"") > 1 && line("'"") Colors and Font
" *> Fileformat
" *> VIM userinterface
" ------ *> Statusline
" *> Visual
" *> Moving around and tab
" *> General Autocommand
" *> Parenthesis/bracket expanding
" *> General Abbrev
" *> Editing mappings etc.
" *> Command-line config
" *> Buffer realted
" *> Files and backup
" *> Folding
" *> Text option
" ------ *> Indent
" *> Spell checking
" *> Plugin configuration
" ------ *> Yank ring
" ------ *> File explorer
" ------ *> Minibuffer
" ------ *> Tag list (ctags) - not used
" ------ *> LaTeX Suite thing
" *> Filetype generic
" ------ *> Todo
" ------ *> VIM
" ------ *> HTML related
" ------ *> Ruby & PHP section
" ------ *> Python section
" ------ *> Cheetah section
" ------ *> Java section
" ------ *> JavaScript section
" ------ *> C mapping
" ------ *> SML
" ------ *> Scheme binding
" *> Snippet
" ------ *> Python
" ------ *> javaScript
" *> Cope
" *> MISC
"
" Tip:
" If you find anything that you can't understand than do this:
" help keyword OR helpgrep keyword
" Example:
" Go into command-line mode and type helpgrep nocompatible, ie.
" :helpgrep nocompatible
" then press c to see the results, or :botright cw
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Get out of VI's compatible mode..
set nocompatible
function! MySys()
return "win32"
endfunction
"Set shell to be bash
if MySys() == "linux" || MySys() == "mac"
set shell=bash
else
"I have to run win32 python without cygwin
"set shell=E:cygwinbinsh
endif
"Sets how many lines of history VIM har to remember
set history=400
"Enable filetype plugin
if has("eval")
filetype plugin on
filetype indent on
endif
"Set to auto read when a file is changed from the outside
set autoread
"Have the mouse enabled all the time:
set mouse=a
"Set mapleader
let mapleader = ","
let g:mapleader = ","
"Fast saving
nmap w :w!
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Font
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable syntax hl
syntax on
"Set font to Monaco 10pt
"if MySys() == "mac"
" set gfn=Bitstream Vera Sans Mono:h14
" set nomacatsui
" set termencoding=macroman
"elseif MySys() == "linux"
" set gfn=Monospace 11
" "set encoding=utf-8
"endif
"internationalization
"I only work in Win2k Chinese version
if has("multi_byte")
set termencoding=chinese
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese
endif
"if you use vim in tty,
"'uxterm -cjk' or putty with option 'Treat CJK ambiguous characters as wide' on
if has("ambiwidth")
set ambiwidth=double
endif
if has("gui_running")
"set guioptions-=m
"set guioptions-=T
set guioptions-=l
set guioptions-=L
"set guioptions-=r
set guioptions-=R
if MySys()=="win32"
"start gvim maximized
"if has("autocmd")
"au GUIEnter * simalt ~x
"endif
endif
"let psc_
"colorscheme ps_color
"colorscheme default
else
"set background=dark
"colorscheme default
endif
"Some nice mapping to switch syntax (useful if one mixes different languages in one file)
map 1 :set syntax=cheetah
map 2 :set syntax=xhtml
map 3 :set syntax=python
map 4 :set ft=javascript
map $ :syntax sync fromstart
"Highlight current
if has("gui_running")
if has("cursorline")
set cursorline
"hi cursorline guibg=#333333
"hi CursorColumn guibg=#333333
endif
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Fileformat
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Favorite filetype
set ffs=unix,dos,mac
nmap fd :se ff=dos
nmap fu :se ff=unix
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Set 7 lines to the curors - when moving vertical..
set so=7
"Turn on WiLd menu
set wildmenu
"Always show current position
set ruler
"The commandbar is 2 high
set cmdheight=2
"Show line number
set nu
"Do not redraw, when running macros.. lazyredraw
set lz
"Change buffer - without saving
set hid
"set current curline
set cursorline
"Set backspace
set backspace=eol,start,indent
"Bbackspace and cursor keys wrap to
set whichwrap+=,h,l
"Ignore case when searching
"set ignorecase
set incsearch
"Set magic on
set magic
"No sound on errors.
set noerrorbells
set novisualbell
set t_vb=
"show matching bracet
set showmatch
"How many tenths of a second to blink
set mat=4
"Highlight search thing
set hlsearch
""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
"Always hide the statusline
set laststatus=2
function! CurDir()
let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
return curdir
endfunction
"Format the statusline
set statusline=
set statusline+=%f "path to the file in the buffer, relative to current directory
set statusline+= %h%1*%m%r%w%0* " flag
set statusline+= [%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
set statusline+=%{&fileformat}] " file format
set statusline+= CWD:%r%{CurDir()}%h
set statusline+= Line:%l/%L
""""""""""""""""""""""""""""""
" => Visual
""""""""""""""""""""""""""""""
" From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '/.*$^~[]')
let l:pattern = substitute(l:pattern, " $", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
else
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
"Basically you press * or # to search for the current selection !! Really useful
vnoremap * :call VisualSearch('f')
vnoremap # :call VisualSearch('b')
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around and tab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Map space to / and c-space to ?
map /
"map ?
"Smart way to move btw. window
map j
map k
map h
map l
"Actually, the tab does not switch buffers, but my arrow
"Bclose function ca be found in "Buffer related" section
"map bd :Bclose
"map bd
"Use the arrows to something usefull
"map :bn
"map :bp
"Tab configuration
map tn :tabnew %
map tc :tabclose
map tm :tabmove
if has("usetab")
set switchbuf=usetab
endif
if has("stal")
set stal=2
endif
"Moving fast to front, back and 2 sides ;)
imap $a
imap 0i
imap $a
imap 0i
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Autocommand
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Switch to current dir
map cd :cd %:p:h
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 `>a)` Command-line config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc
func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "(.*[/]).*", "1", "")
else
let g:cmd_edited = substitute(g:cmd, "(.*[\]).*", "1", "")
endif
if g:cmd == g:cmd_edited
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "(.*[/]).*/", "1", "")
else
let g:cmd_edited = substitute(g:cmd, "(.*[\]).*[\]", "1", "")
endif
endif
return g:cmd_edited
endfunc
func! CurrentFileDir(cmd)
return a:cmd . " " . expand("%:p:h") . "/"
endfunc
"cno $q eDeleteTillSlash()
"cno $c e eCurrentFileDir("e")
"cno $tc eCurrentFileDir("tabnew")
cno $th tabnew ~/
cno $td tabnew ~/Desktop/
"Bash like
cno
cno
cno
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Fast open a buffer by search for a name
"map :sb
"Open a dummy buffer for paste
map q :e ~/buffer
"Restore cursor to file position in previous editing session
set viminfo='10,"100,:20,%,n~/.viminfo
" Buffer - reverse everything ... :)
map ggVGg?
" Don't close window, when deleting a buffer
command! Bclose call BufcloseCloseIt()
function! BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute "bdelete! ".l:currentBufNum
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files and backup
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Turn backup off
set nobackup
set nowb
"set noswapfile
set noar
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
set fen
set fdl=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text option
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" python script
"set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set backspace=2
set smarttab
set lbr
"set tw=500
""""""""""""""""""""""""""""""
" => Indent
""""""""""""""""""""""""""""""
"Auto indent
set ai
"Smart indet
set si
"C-style indenting
set cindent
"Wrap line
set wrap
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map sn ]
map sp [
map sa zg
map s? z=
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => Yank Ring
""""""""""""""""""""""""""""""
map y :YRShow
""""""""""""""""""""""""""""""
" => File explorer
""""""""""""""""""""""""""""""
"Split vertically
let g:explVertical=1
"Window size
let g:explWinSize=35
let g:explSplitLeft=1
let g:explSplitBelow=1
"Hide some file
let g:explHideFiles='^.,.*.class$,.*.swp$,.*.pyc$,.*.swo$,.DS_Store$'
"Hide the help thing..
let g:explDetailedHelp=0
""""""""""""""""""""""""""""""
" => Minibuffer
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 0
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1
"WindowZ
map :WMToggle
let g:bufExplorerSortBy = "name"
""""""""""""""""""""""""""""""
" => Tag list (ctags) - not used
""""""""""""""""""""""""""""""
"let Tlist_Ctags_Cmd = "/sw/bin/ctags-exuberant"
"let Tlist_Sort_Type = "name"
"let Tlist_Show_Menu = 1
"map t :Tlist
map :Tlist
map :NERDTreeToggle
""""""""""""""""""""""""""""""
" => LaTeX Suite thing
""""""""""""""""""""""""""""""
"set grepprg=grep -r -s -n
let g:Tex_DefaultTargetFormat="pdf"
let g:Tex_ViewRule_pdf='xpdf'
if has("autocmd")
"Binding
au BufRead *.tex map :w! :silent! call Tex_RunLaTeX()
"Auto complete some things ;)
au BufRead *.tex ino $i indent
au BufRead *.tex ino $* cdot
au BufRead *.tex ino $i item
au BufRead *.tex ino $m []O
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Filetype generic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Todo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim
""""""""""""""""""""""""""""""
" => VIM
""""""""""""""""""""""""""""""
if has("autocmd")
au BufRead,BufNew *.vim map :w!:source %
endif
""""""""""""""""""""""""""""""
" => HTML related
""""""""""""""""""""""""""""""
" HTML entities - used by xml edit plugin
let xml_use_xhtml = 1
"let xml_no_auto_nesting = 1
"To HTML
let html_use_css = 0
let html_number_lines = 0
let use_xhtml = 1
""""""""""""""""""""""""""""""
" => Ruby & PHP section
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => Python section
""""""""""""""""""""""""""""""
""Run the current buffer in python - ie. on leader+space
"au BufNewFile,BufRead *.py so ~/vim_local/syntax/python.vim
"au BufNewFile,BufRead *.py map :w!:!python %
"au BufNewFile,BufRead *.py so ~/vim_local/plugin/python_fold.vim
""Set some bindings up for 'compile' of python
"au BufNewFile,BufRead *.py set makeprg=python -c "import py_compile,sys; sys.stderr=sys.stdout; py_compile.compile(r'%')"
"au BufNewFile,BufRead *.py set efm=%C %.%#,%A File "%f", line %l%.%#,%Z%[%^ ]%@=%m
"au BufNewFile,BufRead *.py nmap :w!:make
""Python iMap
"au BufNewFile,BufRead *.py set cindent
"au BufNewFile,BufRead *.py ino $r return
"au BufNewFile,BufRead *.py ino $s self
"au BufNewFile,BufRead *.py ino $c ####kla
"au BufNewFile,BufRead *.py ino $i import
"au BufNewFile,BufRead *.py ino $p print
"au BufNewFile,BufRead *.py ino $d """"""O
""Run in the Python interpreter
"function! Python_Eval_VSplit() range
" let src = tempname()
" let dst = tempname()
" execute ": " . a:firstline . "," . a:lastline . "w " . src
" execute ":!python " . src . " > " . dst
" execute ":pedit! " . dst
"endfunction
"au BufNewFile,BufRead *.py vmap :call Python_Eval_VSplit()
""""""""""""""""""""""""""""""
" => Cheetah section
"""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""
" => Java section
"""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => JavaScript section
"""""""""""""""""""""""""""""""
"au BufNewFile,BufRead *.js so ~/vim_local/syntax/javascript.vim
"function! JavaScriptFold()
" set foldmethod=marker
" set foldmarker={,}
" set foldtext=getline(v:foldstart)
"endfunction
"au BufNewFile,BufRead *.js call JavaScriptFold()
"au BufNewFile,BufRead *.js imap console.log();hi
"au BufNewFile,BufRead *.js imap alert();hi
"au BufNewFile,BufRead *.js set nocindent
"au BufNewFile,BufRead *.js ino $r return
"au BufNewFile,BufRead *.js ino $d //////ka
"au BufNewFile,BufRead *.js ino $c /****/ka
if has("eval") && has("autocmd")
fun! abbrev_cpp()
iabbrev cci const_iterator
iabbrev ccl cla
iabbrev cco const
iabbrev cdb bug
iabbrev cde throw
iabbrev cdf /** file/
iabbrev cdg ingroup
iabbrev cdn /** namespace/
iabbrev cdp param
iabbrev cdt test
iabbrev cdx /**/
iabbrev cit iterator
iabbrev cns namespace
iabbrev cpr protected
iabbrev cpu public
iabbrev cpv private
iabbrev csl std::list
iabbrev csm std::map
iabbrev css std::string
iabbrev csv std::vector
iabbrev cty typedef
iabbrev cun using namespace
iabbrev cvi virtual
iabbrev #i #include
iabbrev #d #define
endfun
fun! abbrev_java()
iabbrev #i import
iabbrev #p System.out.println
iabbrev #m public static void main(String[] args
endfun
fun! abbrev_python()
iabbrev #i import
iabbrev #p print
iabbrev #m if __name__=="__main":
endfun
augroup abbreviation
autocmd!
autocmd FileType cpp,c :call abbrev_cpp()
autocmd FileType java :call abbrev_java()
autocmd FileType python :call abbrev_python()
augroup END
endif
cs add ./cscope.out
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remove the Windows ^M
noremap m :%s/r//g
"Paste toggle - when pasting something in, don't indent.
"set pastetoggle=
"Remove indenting on empty line
map :%s/s*$//g:noh''
"Super paste
ino :set pastemui+mv'uV'v=:set nopaste
|
你是修改的/etc/vimrc吗
http://blog.chinaunix.net/u/22968/showart_432269.html
http://blog.chinaunix.net/u/22968/showart_432269.html
|
是需要有一些语法配置的才行。你看一下这个目录里/usr/share/vim/vim72/syntax
是语法的插件。
另外,vi没有语法加亮,只有vim有。
是语法的插件。
另外,vi没有语法加亮,只有vim有。
|
不过用vim写程序的时候 想补全的时候按ctrl+p可以实现 但是效率不怎么好(特别是第一次按要稍微等下)
|
你用的什么系统啊?fedora默认安装的是vi,必须自己安装vim。。。
|
呵呵,对啊。。
|
设置c语言的关键字高亮度,还有关键字自动补齐的功能要怎么设置啊?
|
mark,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
恩,不错。。。。。的东西