vimrc配置

"==========================================
" ProjectLink: https://github.com/wklken/vim-for-server
" Author:  wklken
" Version: 0.1
" Email: wklken@yeah.net
" BlogPost: http://www.wklken.me
" Donation: http://www.wklken.me/pages/donation.html
" ReadMe: README.md
" Last_modify: 2014-11-02
" Sections:
" Desc: simple vim config for server, without any plugins.
"==========================================

" leader
let mapleader = ','
let g:mapleader = ','

" syntax
syntax on

" history : how many lines of history VIM has to remember
set history=2000

" filetype
filetype on
" Enable filetype plugins
filetype plugin on
filetype indent on


" base
set nocompatible                " don't bother with vi compatibility
set autoread                    " reload files when changed on disk, i.e. via `git checkout`
set shortmess=atI

set magic                       " For regular expressions turn magic on
set title                       " change the terminal's title
set nobackup                    " do not keep a backup file
set novisualbell                " turn off visual bell
set noerrorbells         " don't beep
set visualbell t_vb=            " turn off error beep/flash
set t_vb=
set tm=500


" show location
set cursorcolumn
set cursorline


" movement
set scrolloff=7                 " keep 3 lines when scrolling

nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j

map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>


" show
set ruler                       " show the current row and column
set number                      " show line numbers
set nowrap
set showcmd                     " display incomplete commands
set showmode                    " display current modes
set showmatch                   " jump to matches when entering parentheses
set matchtime=2                 " tenths of a second to show the matching parenthesis


" search
set hlsearch                    " highlight searches
set incsearch                   " do incremental searching, search as you type
set ignorecase                  " ignore case when searching
set smartcase                   " no ignorecase if Uppercase char present

noremap <silent><leader>/ :nohls<CR>

" tab
set expandtab                   " expand tabs to spaces
set smarttab
set shiftround

" indent
set autoindent smartindent shiftround
set shiftwidth=4
set tabstop=4
set softtabstop=4                " insert mode tab and backspace use 4 spaces

vnoremap < <gv
vnoremap > >gv

" NOT SUPPORT
" fold
" set foldenable
" set foldmethod=indent
" set foldlevel=99

" encoding
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set termencoding=utf-8
set ffs=unix,dos,mac
set formatoptions+=m
set formatoptions+=B

" select & complete
set selection=inclusive
set selectmode=mouse,key

set completeopt=longest,menu
set wildmenu                           " show a navigable menu for tab completion"
set wildmode=longest,list,full
set wildignore=*.o,*~,*.pyc,*.class


" if this not work ,make sure .viminfo is writable for you
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" NOT SUPPORT
" Enable basic mouse behavior such as resizing buffers.
" set mouse=a

" theme
set background=dark
colorscheme desert

hi! link SignColumn   LineNr
hi! link ShowMarksHLl DiffAdd
hi! link ShowMarksHLu DiffChange

" status line
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P
set laststatus=2   " Always show the status line - use 2 lines for the status bar

" specific language
autocmd FileType python set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType ruby set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai

autocmd BufNewFile *.sh,*.py exec ":call AutoSetFileHead()"
function! AutoSetFileHead()
    " .sh
    if &filetype == 'sh'
        call setline(1, "\#!/bin/bash")
    endif

    " python
    if &filetype == 'python'
        call setline(1, "\#!/usr/bin/env python")
        call append(1, "\# encoding: utf-8")
    endif

    normal G
    normal o
    normal o
endfunc

" others
set backspace=indent,eol,start  " make that backspace key work the way it should
set whichwrap+=<,>,h,l
cmap w!! w !sudo tee >/dev/null %

" kj 替换 Esc
inoremap kj <Esc>

nnoremap <F2> :set nu! nu?<CR>
nnoremap <F3> :set list! list?<CR>
nnoremap <F4> :set wrap! wrap?<CR>
nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>

set pastetoggle=<F5>
au InsertLeave * set nopaste

fun! <SID>StripTrailingWhitespaces()
    let l = line(".")
    let c = col(".")
    %s/\s\+$//e
    call cursor(l, c)
endfun
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()

 

【使用说明】在主目录直接解包就行 【功能详情】--------快捷键 //----------------------------------------------------------------- 【#】显示函数列表 : TlistToggle //显示函数列表 按将会在VIM的左边打开一个Taglist窗口,这个窗口里面包含了C文件里面的定义,如struct,typedef,全局变量,函数等。使用'+h将光标移动到左边的窗口,上下选择tag按回车定位到tag的定义处。 【#】当前目录列表,方便打开文件 : NERDTreeToggle //当前目录列表,方便打开文件 按会在VIM的右边打开一个文件浏览器窗口。再按一下会关闭这个窗口。 【#】最近文件列表 : MRU //最近文件列表 按会打开一个MRU窗口,这个窗口里面记录了最近打开的文档,上下选择文件回车打开。如果没有你想打开的文件可以按"q"关闭窗口。 : LookupFile 在VIM的上面打开文件查找窗口, : vimgrep 假设你想查找某个字符串在项目中出现的位置,你可以把光标放在这个字符串上, 按就会在VIM的最下面显示你想查找的字符串,此时你可以修改这个字符串,回车到下一步,此时会提示你要查找的文件范围, 【#】编译 : gcc 直接按可以对打开的文件直接编译 【#】gdb调试 : gdb 直接按可以直接进入gdb调试状态 : Generate tags 在代码间跳来跳去。先按生成tag数据库。将会在项目的当前目录下生成tags文件。此时将光标放在某个函数调用上,按+]就会跳到函数的定义处,按+o就会跳回来。 : HLUDSync 按可以生成cscope的数据库文件cscope.out,再使用",sa"(:cs add cscope.out)添加数据库文件。当下次启动VIM的时候就会自动加载当前目录下的cscope数据库文件。在.vimrc里面定义了使用cscope的快捷键,比如将光标放在某个函数上使用命令",sc"就可以查看这个函数被哪些函数调用过, 【#】全屏显示 :genfiletags.sh 是让终端全屏显示 add cscope.out 在查找文件之前要生成文件数据库, 按将会在项目的当前目录下生成tags.filename文件,所以最好是在项目的根目录下按。再按就可以使用通配符查找文件了。 【功能详情】--------命令行功能 【#】添加函数注释等 :Dox 添加函数注释 【#】头文件和c文件切换 :AV 垂直分屏显示头文件或者c文件 【其他功能】------- 1.输入main后按table键,自动生成main函数 2.输入单词自动补全//注,本文档之前输入的单词自动补全 3.双引号、单引号、大括号自动补全,小括号不能自动补全【如果有人发现是什么原因,可以留言哈】 【注】祝大家更高效的玩转vim
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值