当前位置:  开发笔记 > 编程语言 > 正文

.vimrc中有什么内容?

如何解决《.vimrc中有什么内容?》经验,为你挑选了15个好方法。

Vi和Vim允许非常棒的自定义,通常存储在.vimrc文件中.程序员的典型特征是语法高亮,智能缩进等.

你有什么其他的生产性编程技巧,隐藏在你的.vimrc中?

我最感兴趣的是重构,自动类和类似的生产力宏,特别是对于C#.



1> Frew Schmidt..:

你自找的 :-)

"{{{Auto Commands

" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif

" Restore cursor position to where it was before
augroup JumpCursorOnEdit
   au!
   autocmd BufReadPost *
            \ if expand(":p:h") !=? $TEMP |
            \   if line("'\"") > 1 && line("'\"") <= line("$") |
            \     let JumpCursorOnEdit_foo = line("'\"") |
            \     let b:doopenfold = 1 |
            \     if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
            \        let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
            \        let b:doopenfold = 2 |
            \     endif |
            \     exe JumpCursorOnEdit_foo |
            \   endif |
            \ endif
   " Need to postpone using "zv" until after reading the modelines.
   autocmd BufWinEnter *
            \ if exists("b:doopenfold") |
            \   exe "normal zv" |
            \   if(b:doopenfold > 1) |
            \       exe  "+".1 |
            \   endif |
            \   unlet b:doopenfold |
            \ endif
augroup END

"}}}

"{{{Misc Settings

" Necesary  for lots of cool vim things
set nocompatible

" This shows what you are typing as a command.  I love this!
set showcmd

" Folding Stuffs
set foldmethod=marker

" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
syntax enable
set grepprg=grep\ -nH\ $*

" Who doesn't like autoindent?
set autoindent

" Spaces are better than a tab character
set expandtab
set smarttab

" Who wants an 8 character tab?  Not me!
set shiftwidth=3
set softtabstop=3

" Use english for spellchecking, but don't spellcheck by default
if version >= 700
   set spl=en spell
   set nospell
endif

" Real men use gcc
"compiler gcc

" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full

" Enable mouse support in console
set mouse=a

" Got backspace?
set backspace=2

" Line Numbers PWN!
set number

" Ignoring case is a fun trick
set ignorecase

" And so is Artificial Intellegence!
set smartcase

" This is totally awesome - remap jj to escape in insert mode.  You'll never type jj anyway, so it's great!
inoremap jj 

nnoremap JJJJ 

" Incremental searching is sexy
set incsearch

" Highlight things that we find with the search
set hlsearch

" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'

" When I close a tab, remove the buffer
set nohidden

" Set off the other paren
highlight MatchParen ctermbg=4
" }}}

"{{{Look and Feel

" Favorite Color Scheme
if has("gui_running")
   colorscheme inkpot
   " Remove Toolbar
   set guioptions-=T
   "Terminus is AWESOME
   set guifont=Terminus\ 9
else
   colorscheme metacosm
endif

"Status line gnarliness
set laststatus=2
set statusline=%F%m%r%h%w\ (%{&ff}){%Y}\ [%l,%v][%p%%]

" }}}

"{{{ Functions

"{{{ Open URL in browser

function! Browser ()
   let line = getline (".")
   let line = matchstr (line, "http[^   ]*")
   exec "!konqueror ".line
endfunction

"}}}

"{{{Theme Rotating
let themeindex=0
function! RotateColorTheme()
   let y = -1
   while y == -1
      let colorstring = "inkpot#ron#blue#elflord#evening#koehler#murphy#pablo#desert#torte#"
      let x = match( colorstring, "#", g:themeindex )
      let y = match( colorstring, "#", x + 1 )
      let g:themeindex = x + 1
      if y == -1
         let g:themeindex = 0
      else
         let themestring = strpart(colorstring, x + 1, y - x - 1)
         return ":colorscheme ".themestring
      endif
   endwhile
endfunction
" }}}

"{{{ Paste Toggle
let paste_mode = 0 " 0 = normal, 1 = paste

func! Paste_on_off()
   if g:paste_mode == 0
      set paste
      let g:paste_mode = 1
   else
      set nopaste
      let g:paste_mode = 0
   endif
   return
endfunc
"}}}

"{{{ Todo List Mode

function! TodoListMode()
   e ~/.todo.otl
   Calendar
   wincmd l
   set foldlevel=1
   tabnew ~/.notes.txt
   tabfirst
   " or 'norm! zMzr'
endfunction

"}}}

"}}}

"{{{ Mappings

" Open Url on this line with the browser \w
map w :call Browser ()

" Open the Project Plugin 
nnoremap   :Project

" Open the Project Plugin
nnoremap  pal  :Project .vimproject

" TODO Mode
nnoremap  todo :execute TodoListMode()

" Open the TagList Plugin 
nnoremap   :Tlist

" Next Tab
nnoremap   :tabnext

" Previous Tab
nnoremap   :tabprevious

" New Tab
nnoremap   :tabnew

" Rotate Color Scheme 
nnoremap   :execute RotateColorTheme()

" DOS is for fools.
nnoremap   :%s/$//g:%s// /g

" Paste Mode!  Dang! 
nnoremap   :call Paste_on_off()
set pastetoggle=

" Edit vimrc \ev
nnoremap  ev :tabnew:e ~/.vimrc

" Edit gvimrc \gv
nnoremap  gv :tabnew:e ~/.gvimrc

" Up and down are more logical with g..
nnoremap  k gk
nnoremap  j gj
inoremap   gka
inoremap   gja

" Good call Benjie (r for i)
nnoremap   i r
nnoremap   a r

" Create Blank Newlines and stay in Normal mode
nnoremap  zj o
nnoremap  zk O

" Space will toggle folds!
nnoremap  za

" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
map N Nzz
map n nzz

" Testing
set completeopt=longest,menuone,preview

inoremap   pumvisible() ? "\" : "\u\"
inoremap   pumvisible() ? "\c-n>" : "\c-n>\c-r>=pumvisible() ? \"\\down>\" : \"\"\cr>"
inoremap   pumvisible() ? "\c-n>" : "\c-x>\c-o>\c-n>\c-p>\c-r>=pumvisible() ? \"\\down>\" : \"\"\cr>"

" Swap ; and :  Convenient.
nnoremap ; :
nnoremap : ;

" Fix email paragraphs
nnoremap par :%s/^>$//

"ly$O#{{{ "lpjjj_%A#}}}jjzajj

"}}}

"{{{Taglist configuration
let Tlist_Use_Right_Window = 1
let Tlist_Enable_Fold_Column = 0
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_SingleClick = 1
let Tlist_Inc_Winwidth = 0
"}}}

let g:rct_completion_use_fri = 1
"let g:Tex_DefaultTargetFormat = "pdf"
let g:Tex_ViewRule_pdf = "kpdf"

filetype plugin indent on
syntax on


但为什么3,设置shiftwidth = 3,设置softtabstop = 3 ...也许2或4但为什么3?
我喜欢'nzz`和交换`;`和`:`,为什么我没想到:)
那里有一些非常酷的技巧 - 谢谢!
如果真正的男人使用gcc,为什么不呢?(编译器gcc被注释掉了!)
@Johan:因为"三个是一个神奇的数字".:)实际上,这只是自行车,但我也更喜欢三个.:)

2> Greg Hewgill..:

这不在我的.vimrc文件中,但昨天我了解了该]p命令.这样就可以粘贴缓冲区的内容p,但它会自动调整缩进以匹配光标所在的行!这非常适合移动代码.


据我所知,:set paste选项对p命令没有任何影响,它只影响在插入模式下键入的文本(或通过终端粘贴).所以不,这是一个不同的功能.

3> Harley Holco..:

我使用以下内容将所有临时文件和备份文件保存在一个位置:

set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp

在整个地方保存混乱的工作目录.

您必须先创建这些目录,vim 不会为您创建它们.


试试这个:au BufWritePre*let&bex =' - '.strftime("%Y%m%d-%H%M%S").'.vimbackup'(这是一行.)我也必须提到这一点:http://vim.wikia.com/wiki/VimTip962
我应该提到你必须自己创建这些目录,vim不会为你做.

4> Herbert Sitz..:

上面发布的有人(即Frew)有这条线:

"自动进入文件所在的目录:"

autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

我自己做了类似的事情,直到我发现内置设置可以完成同样的事情:

set autochdir

我认为类似的事情发生在我身上几次.Vim有许多不同的内置设置和选项,它有时比使用内置方式搜索文档更快更容易自己滚动.


autochdir有一些我无法解决的烦恼(在加载命令行上给出的文件之前更改目录),我在这里读到关于`autocmd BufEnter*silent的其他地方!lcd%:p:h:gs// \\ /`它执行相同的基本操作但不会破坏命令行.

5> Martin..:

我最新增加的是突出显示当前行

set cul                                           # highlight current line
hi CursorLine term=none cterm=none ctermbg=3      # adjust color


有没有办法从更多颜色中选择?
请参阅此脚本(http://www.vim.org/scripts/script.php?script_id=1349)以获取可用颜色.可能需要为vim打开256色支持以获得更多种类.

6> Gavin Gilmou..:

更新2012:我现在真的建议检查已取代旧的状态行脚本的vim-powerline,尽管目前缺少一些我想念的功能.


我会说,在状态的东西我的vimrc可能是最有趣/有用了很多(从作者撕开的vimrc 这里和相应的博客文章在这里).

截图:

状态行http://img34.imageshack.us/img34/849/statusline.png

码:

"recalculate the trailing whitespace warning when idle, and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning

"return '[\s]' if trailing white space is detected
"return '' otherwise
function! StatuslineTrailingSpaceWarning()
    if !exists("b:statusline_trailing_space_warning")

        if !&modifiable
            let b:statusline_trailing_space_warning = ''
            return b:statusline_trailing_space_warning
        endif

        if search('\s\+$', 'nw') != 0
            let b:statusline_trailing_space_warning = '[\s]'
        else
            let b:statusline_trailing_space_warning = ''
        endif
    endif
    return b:statusline_trailing_space_warning
endfunction


"return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
    let name = synIDattr(synID(line('.'),col('.'),1),'name')
    if name == ''
        return ''
    else
        return '[' . name . ']'
    endif
endfunction

"recalculate the tab warning flag when idle and after writing
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning

"return '[&et]' if &et is set wrong
"return '[mixed-indenting]' if spaces and tabs are used to indent
"return an empty string if everything is fine
function! StatuslineTabWarning()
    if !exists("b:statusline_tab_warning")
        let b:statusline_tab_warning = ''

        if !&modifiable
            return b:statusline_tab_warning
        endif

        let tabs = search('^\t', 'nw') != 0

        "find spaces that arent used as alignment in the first indent column
        let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0

        if tabs && spaces
            let b:statusline_tab_warning = '[mixed-indenting]'
        elseif (spaces && !&et) || (tabs && &et)
            let b:statusline_tab_warning = '[&et]'
        endif
    endif
    return b:statusline_tab_warning
endfunction

"recalculate the long line warning when idle and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning

"return a warning for "long lines" where "long" is either &textwidth or 80 (if
"no &textwidth is set)
"
"return '' if no long lines
"return '[#x,my,$z] if long lines are found, were x is the number of long
"lines, y is the median length of the long lines and z is the length of the
"longest line
function! StatuslineLongLineWarning()
    if !exists("b:statusline_long_line_warning")

        if !&modifiable
            let b:statusline_long_line_warning = ''
            return b:statusline_long_line_warning
        endif

        let long_line_lens = s:LongLines()

        if len(long_line_lens) > 0
            let b:statusline_long_line_warning = "[" .
                        \ '#' . len(long_line_lens) . "," .
                        \ 'm' . s:Median(long_line_lens) . "," .
                        \ '$' . max(long_line_lens) . "]"
        else
            let b:statusline_long_line_warning = ""
        endif
    endif
    return b:statusline_long_line_warning
endfunction

"return a list containing the lengths of the long lines in this buffer
function! s:LongLines()
    let threshold = (&tw ? &tw : 80)
    let spaces = repeat(" ", &ts)

    let long_line_lens = []

    let i = 1
    while i <= line("$")
        let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
        if len > threshold
            call add(long_line_lens, len)
        endif
        let i += 1
    endwhile

    return long_line_lens
endfunction

"find the median of the given array of numbers
function! s:Median(nums)
    let nums = sort(a:nums)
    let l = len(nums)

    if l % 2 == 1
        let i = (l-1) / 2
        return nums[i]
    else
        return (nums[l/2] + nums[(l/2)-1]) / 2
    endif
endfunction


"statusline setup
set statusline=%f "tail of the filename

"display a warning if fileformat isnt unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*

"display a warning if file encoding isnt utf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*

set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag

"display a warning if &et is wrong, or we have mixed-indenting
set statusline+=%#error#
set statusline+=%{StatuslineTabWarning()}
set statusline+=%*

set statusline+=%{StatuslineTrailingSpaceWarning()}

set statusline+=%{StatuslineLongLineWarning()}

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

"display a warning if &paste is set
set statusline+=%#error#
set statusline+=%{&paste?'[paste]':''}
set statusline+=%*

set statusline+=%= "left/right separator

function! SlSpace()
    if exists("*GetSpaceMovement")
        return "[" . GetSpaceMovement() . "]"
    else
        return ""
    endif
endfunc
set statusline+=%{SlSpace()}

set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
set statusline+=%c, "cursor column
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
set laststatus=2

除此之外,它通知标准文件信息的状态行,但还包括警告的其他内容:设置粘贴,混合缩进,尾随空格等.如果您特别肛门有关您的代码格式,这非常有用.

此外,如屏幕截图所示,将其与syntastic结合使用 可以突出显示任何语法错误(假设您选择的语言捆绑了相关的语法检查器.



7> Adam Gibbins..:

我的迷你版:

syntax on
set background=dark
set shiftwidth=2
set tabstop=2

if has("autocmd")
  filetype plugin indent on
endif

set showcmd             " Show (partial) command in status line.
set showmatch           " Show matching brackets.
set ignorecase          " Do case insensitive matching
set smartcase           " Do smart case matching
set incsearch           " Incremental search
set hidden              " Hide buffers when they are abandoned

从各个地方收集的大版本:

syntax on
set background=dark
set ruler                     " show the line number on the bar
set more                      " use more prompt
set autoread                  " watch for file changes
set number                    " line numbers
set hidden
set noautowrite               " don't automagically write on :next
set lazyredraw                " don't redraw when don't have to
set showmode
set showcmd
set nocompatible              " vim, not vi
set autoindent smartindent    " auto/smart indent
set smarttab                  " tab and backspace are smart
set tabstop=2                 " 6 spaces
set shiftwidth=2
set scrolloff=5               " keep at least 5 lines above/below
set sidescrolloff=5           " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set linebreak
set cmd command line two lines high
set undolevels=1000           " 1000 undos
set updatecount=100           " switch every 100 chars
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set ttyfast                   " we have a fast terminal
set noerrorbells              " No error bells please
set shell=bash
set fileformats=unix
set ff=unix
filetype on                   " Enable filetype detection
filetype indent on            " Enable filetype-specific indenting
filetype plugin on            " Enable filetype-specific plugins
set wildmode=longest:full
set wildmenu                  " menu has tab completion
let maplocalleader=','        " all my macros start with ,
set laststatus=2

"  searching
set incsearch                 " incremental search
set ignorecase                " search ignoring case
set hlsearch                  " highlight the search
set showmatch                 " show matching bracket
set diffopt=filler,iwhite     " ignore all whitespace and sync

"  backup
set backup
set backupdir=~/.vim_backup
set viminfo=%100,'100,/100,h,\"500,:100,n~/.viminfo
"set viminfo='100,f1

" spelling
if v:version >= 700
  " Enable spell check for text files
  autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en
endif

" mappings
" toggle list mode
nmap tl :set list!
" toggle paste mode
nmap pp :set paste!


感谢"滚动",这非常方便!我讨厌滚动到底部向下滚动.

8> William Purs..:

有时最简单的东西是最有价值的.我的.vimrc中的2行是完全不可或缺的:

nore ; :
nore , ;


在法语键盘上,你不需要'shift'来写',',';' 和':'......但''','['和']'是一种真正的痛苦.
分号是一种很少使用的命令.冒号是一个非常常见的命令,用于进入命令行模式.将一个重新映射到另一个允许您进入命令行模式而无需按下shift键,从而节省小手指的肌肉.
但是它做了什么?:)
在你的vimrc中使用这十年将节省大量的小拇指痛苦!

9> Alex B..:

杂项.设置:

    关闭恼人的错误铃声:

    set noerrorbells
    set visualbell
    set t_vb=
    

    使用包装线使光标按预期移动:

    inoremap  gj
    inoremap  gk
    

    查找ctags"标记"文件在目录中,直到找到一个:

    set tags=tags;/
    

    使用Python语法显示SCons文件:

    autocmd BufReadPre,BufNewFile SConstruct set filetype=python
    autocmd BufReadPre,BufNewFile SConscript set filetype=python
    



10> Whaledawg..:

我不是世界上最先进的vim'er,但这里有一些我已经接受了

function! Mosh_Tab_Or_Complete()
    if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
        return "\"
    else
        return "\"
endfunction

inoremap  =Mosh_Tab_Or_Complete()

使标签自动完成计算出是否要在那里放置单词或实际标签(4个空格).

map cc :.,$s/^ *//

从此处删除所有打开的空格到文件末尾.出于某种原因,我觉得这很有用.

set nu! 
set nobackup

显示行号,不要创建那些烦人的备份文件.我从来没有从旧的备份中恢复任何东西.

imap ii 

在插入时,按两次i进入命令模式.我从来没有遇到过连续2个字的单词或变量,这样我就不必让我的手指离开主行或按下多个键来回切换.


有趣的ii映射...非常有趣.这是一个非常酷的想法 - 虽然我担心它会严重影响我使用'香草'vim的能力,如果我不得不这样做的话.

11> guns..:

我的评论很重要的vimrc,带有readline-esque(emacs)键绑定:

if version >= 700

"------ Meta ------"

" clear all autocommands! (this comment must be on its own line)
autocmd!

set nocompatible                " break away from old vi compatibility
set fileformats=unix,dos,mac    " support all three newline formats
set viminfo=                    " don't use or save viminfo files

"------ Console UI & Text display ------"

set cmd explicitly set the height of the command line
set showcmd                     " Show (partial) command in status line.
set number                      " yay line numbers
set ruler                       " show current position at bottom
set noerrorbells                " don't whine
set visualbell t_vb=            " and don't make faces
set lazyredraw                  " don't redraw while in macros
set scrolloff=5                 " keep at least 5 lines around the cursor
set wrap                        " soft wrap long lines
set list                        " show invisible characters
set listchars=tab:>·,trail:·    " but only show tabs and trailing whitespace
set report=0                    " report back on all changes
set shortmess=atI               " shorten messages and don't show intro
set wildmenu                    " turn on wild menu :e 
set wildmode=list:longest       " set wildmenu to list choice
if has('syntax')
    syntax on
    " Remember that rxvt-unicode has 88 colors by default; enable this only if
    " you are using the 256-color patch
    if &term == 'rxvt-unicode'
        set t_Co=256
    endif

    if &t_Co == 256
        colorscheme xoria256
    else
        colorscheme peachpuff
    endif
endif

"------ Text editing and searching behavior ------"

set nohlsearch                  " turn off highlighting for searched expressions
set incsearch                   " highlight as we search however
set matchtime=5                 " blink matching chars for .x seconds
set mouse=a                     " try to use a mouse in the console (wimp!)
set ignorecase                  " set case insensitivity
set smartcase                   " unless there's a capital letter
set completeopt=menu,longest,preview " more autocomplete -P options
set nostartofline               " leave my cursor position alone!
set backspace=2                 " equiv to :set backspace=indent,eol,start
set text we like 80 columns
set showmatch                   " show matching brackets
set formatoptions=tcrql         " t - autowrap to textwidth
                                " c - autowrap comments to textwidth
                                " r - autoinsert comment leader with 
                                " q - allow formatting of comments with :gq
                                " l - don't format already long lines

"------ Indents and tabs ------"

set autoindent                  " set the cursor at same indent as line above
set smartindent                 " try to be smart about indenting (C-style)
set expandtab                   " expand s with spaces; death to tabs!
set shift spaces for each step of (auto)indent
set softtabstop=4               " set virtual tab stop (compat for 8-wide tabs)
set tabstop=8                   " for proper display of files with tabs
set shiftround                  " always round indents to multiple of shiftwidth
set copyindent                  " use existing indents for new indents
set preserveindent              " save as much indent structure as possible
filetype plugin indent on       " load filetype plugins and indent settings

"------ Key bindings ------"

" Remap broken meta-keys that send ^[
for n in range(97,122) " ASCII a-z
    let c = nr2char(n)
    exec "set =\e". c
    exec "map  \e". c ." "
    exec "map! \e". c ." "
endfor

""" Emacs keybindings
" first move the window command because we'll be taking it over
noremap  
" Movement left/right
noremap!  
noremap!  
" word left/right
noremap   b
noremap!  b
noremap   w
noremap!  w
" line start/end
noremap   ^
noremap!  I
noremap   $
noremap!  A
" Rubout word / line and enter insert mode
noremap   i
noremap   i
" Forward delete char / word / line and enter insert mode
noremap!  x
noremap   dw
noremap!  dw
noremap   Da
noremap!  D
" Undo / Redo and enter normal mode
noremap   u
noremap!  u
noremap!  

" Remap  to word completion
noremap!  

" OS X paste (pretty poor implementation)
if has('mac')
    noremap  ? :r!pbpaste
    noremap! ? ?
endif

""" screen.vim REPL: http://github.com/ervandew/vimfiles
" send paragraph to parallel process
vmap  :ScreenSend
nmap  mCvip`C
imap  
" set shell region height
let g:ScreenShellHeight = 12


"------ Filetypes ------"

" Vimscript
autocmd FileType vim setlocal expandtab shiftwidth=4 tabstop=8 softtabstop=4

" Shell
autocmd FileType sh setlocal expandtab shiftwidth=4 tabstop=8 softtabstop=4

" Lisp
autocmd Filetype lisp,scheme setlocal equalprg=~/.vim/bin/lispindent.lisp expandtab shiftwidth=2 tabstop=8 softtabstop=2

" Ruby
autocmd FileType ruby setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2

" PHP
autocmd FileType php setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4

" X?HTML & XML
autocmd FileType html,xhtml,xml setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2

" CSS
autocmd FileType css setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4

" JavaScript
" autocmd BufRead,BufNewFile *.json setfiletype javascript
autocmd FileType javascript setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
let javascript_enable_domhtmlcss=1

"------ END VIM-500 ------"

endif " version >= 500



12> Maxim Sloyko..:
syntax on
set cindent
set ts=4
set sw=4
set backspace=2
set laststatus=2
set nohlsearch
set modeline
set modelines=3
set ai
map Q gq

set vb t_vb=

set nowrap
set ss=5
set is
set scs
set ru

map  :w
map!  :w

map  :qa
map!  :qa

map   :wqa
map!   :wqa

inoremap  W
inoremap  w

nnoremap  W
nnoremap  w

" Fancy middle-line 
inoremap  o
nnoremap  o

" This is the way I like my quotation marks and various braces
inoremap '' ''
inoremap "" ""
inoremap () ()
inoremap <> <>
inoremap {} {}
inoremap [] []
inoremap () ()

" Quickly set comma or semicolon at the end of the string
inoremap ,, ,
inoremap ;; ;
au FileType python inoremap :: :


au FileType perl,python set foldlevel=0
au FileType perl,python set foldcolumn=4
au FileType perl,python set fen
au FileType perl        set fdm=syntax
au FileType python      set fdm=indent
au FileType perl,python set fdn=4
au FileType perl,python set fml=10
au FileType perl,python set fdo=block,hor,mark,percent,quickfix,search,tag,undo,search

au FileType perl,python abbr sefl self
au FileType perl abbr sjoft shift
au FileType perl abbr DUmper Dumper

function! ToggleNumberRow()
       if !exists("g:NumberRow") || 0 == g:NumberRow
               let g:NumberRow = 1
               call ReverseNumberRow()
       else
               let g:NumberRow = 0
               call NormalizeNumberRow()
       endif
endfunction


" Reverse the number row characters
function! ReverseNumberRow()
       " map each number to its shift-key character
       inoremap 1 !
       inoremap 2 @
       inoremap 3 #
       inoremap 4 $
       inoremap 5 %
       inoremap 6 ^
       inoremap 7 &
       inoremap 8 *
       inoremap 9 (
       inoremap 0 )
       inoremap - _
    inoremap 90 ()
       " and then the opposite
       inoremap ! 1
       inoremap @ 2
       inoremap # 3
       inoremap $ 4
       inoremap % 5
       inoremap ^ 6
       inoremap & 7
       inoremap * 8
       inoremap ( 9
       inoremap ) 0
       inoremap _ -
endfunction

" DO the opposite to ReverseNumberRow -- give everything back
function! NormalizeNumberRow()
       iunmap 1
       iunmap 2
       iunmap 3
       iunmap 4
       iunmap 5
       iunmap 6
       iunmap 7
       iunmap 8
       iunmap 9
       iunmap 0
       iunmap -
       "------
       iunmap !
       iunmap @
       iunmap #
       iunmap $
       iunmap %
       iunmap ^
       iunmap &
       iunmap *
       iunmap (
       iunmap )
       iunmap _
       inoremap () ()
endfunction

"call ToggleNumberRow()
nnoremap  :call ToggleNumberRow()

" Add use  at the top of the file
function! UseWord(word)
       let spec_cases = {'Dumper': 'Data::Dumper'}
       let my_word = a:word
       if has_key(spec_cases, my_word)
               let my_word = spec_cases[my_word]
       endif

       let was_used = search("^use.*" . my_word, "bw")

       if was_used > 0
               echo "Used already"
               return 0
       endif

       let last_use = search("^use", "bW")
       if 0 == last_use
               last_use = search("^package", "bW")
               if 0 == last_use
                       last_use = 1
               endif
       endif

       let use_string = "use " . my_word . ";"
       let res = append(last_use, use_string)
       return 1
endfunction

function! UseCWord()
       let cline = line(".")
       let ccol = col(".")
       let ch = UseWord(expand(""))
       normal mu
       call cursor(cline + ch, ccol)

endfunction

function! GetWords(pattern)
       let cline = line(".")
       let ccol = col(".")
       call cursor(1,1)

       let temp_dict = {}
       let cpos = searchpos(a:pattern)
       while cpos[0] != 0
               let temp_dict[expand("")] = 1
               let cpos = searchpos(a:pattern, 'W')
       endwhile

       call cursor(cline, ccol)
       return keys(temp_dict)
endfunction

" Append the list of words, that match the pattern after cursor
function! AppendWordsLike(pattern)
       let word_list = sort(GetWords(a:pattern))
       call append(line("."), word_list)
endfunction


nnoremap   :call UseCWord()

" Useful to mark some code lines as debug statements
function! MarkDebug()
       let cline = line(".")
       let ctext = getline(cline)
       call setline(cline, ctext . "##_DEBUG_")
endfunction

" Easily remove debug statements
function! RemoveDebug()
       %g/#_DEBUG_/d
endfunction

au FileType perl,python inoremap  :call MarkDebug()
au FileType perl,python inoremap  :call RemoveDebug()
au FileType perl,python nnoremap  :call RemoveDebug()

" end Perl settings

nnoremap   :TlistToggle
inoremap   :TlistToggle

function! AlwaysCD()
       if bufname("") !~ "^scp://" && bufname("") !~ "^sftp://" && bufname("") !~ "^ftp://"
               lcd %:p:h
       endif
endfunction
autocmd BufEnter * call AlwaysCD()

function! DeleteRedundantSpaces()
       let cline = line(".")
       let ccol = col(".")
       silent! %s/\s\+$//g
       call cursor(cline, ccol)
endfunction
au BufWrite * call DeleteRedundantSpaces()

set nobackup
set nowritebackup
set cul

colorscheme evening

autocmd FileType python set formatoptions=wcrq2l
autocmd FileType python set inc="^\s*from"
autocmd FileType python so /usr/share/vim/vim72/indent/python.vim

autocmd FileType c      set si
autocmd FileType mail   set noai
autocmd FileType mail   set ts=3
autocmd FileType mail   set tw=78
autocmd FileType mail   set shiftwidth=3
autocmd FileType mail   set expandtab
autocmd FileType xslt   set ts=4
autocmd FileType xslt   set shiftwidth=4
autocmd FileType txt    set ts=3
autocmd FileType txt    set tw=78
autocmd FileType txt    set expandtab

" Move cursor together with the screen
noremap  j
noremap  k

" Better Marks
nnoremap ' `



13> Dominic Dos ..:

常见错别字的一些修复为我节省了大量时间:

:command WQ wq
:command Wq wq
:command W w
:command Q q

iab anf and
iab adn and
iab ans and
iab teh the
iab thre there


我不喜欢这个 - 它只是训练错误.
@Svante,通常我会同意,除了我在我的命令中也有这个,我倾向于经常保存或经常保存/退出.通常我的小指只是在一小段时间内从提升换挡键和BAM一个或另一个最终被大写,但它很烦人!

14> rshdev..:

我没有意识到我的3200 .vimrc线路中有多少只是为了我的古怪需求而且在这里列出的内容非常简单.但也许这就是为什么Vim如此有用......

iab AlP ABCDEFGHIJKLMNOPQRSTUVWXYZ
iab MoN January February March April May June July August September October November December
iab MoO Jan Feb Mar Apr May Jun Jul Aug Sep Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
iab NuM 12345678901234567890123456789012345678901234567890123456789012345678901234567890 
iab RuL ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

" Highlight every other line
map , :set hls/\\n.*\\n/

" This is for working across multiple xterms and/or gvims
" Transfer/read and write one block of text between vim sessions (capture whole line):
" Write
nmap ;w :. w! ~/.vimxfer
" Read
nmap ;r :r ~/.vimxfer
" Append 
nmap ;a :. w! >>~/.vimxfer


聪明的东西!我很想看到你的.vimrc

15> unperson3256..:

我的242行.vimrc不是那么有趣,但是由于没有人提到它,我觉得我必须分享两个最重要的映射,这些映射除了默认映射之外还增强了我的工作流程:

map  :bprev
map  :bnext
set hidden " this will go along

说真的,切换缓冲区是经常做事情.Windows,当然,但一切都不适合屏幕这么好.

用于快速浏览错误的类似映射集(请参阅quickfix)和grep结果:

map  :cn
map  :cp

简单,轻松,高效.

推荐阅读
手机用户2502851955
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有