vim的Windows编程系列

我一直搞不定一个问题,就是vim怎么也无法编译程序。

基本知道应该怎么编程了,只是在命令行编程略微有点不爽,不过这本来就是Linux使用的嘛,我也看到了很多的大佬写的配置文件,只是因为自己不了解,用太多反而弄巧成拙,所以我先把我的配置文件写出来,以后要配置的话先用着,有压力的再去钻研大佬写的

鉴于自己的实力,而且有替代方案,我就不想再弄了,用了一小时了,我配置的方案很简陋,就可以补全括号,一键运行代码。不过基本除了一些项目要用IDE,其他的小程序我基本用它写,不过写Java有点难受,导包好麻烦

source $VIMRUNTIME/vimrc_example.vim

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg1 = substitute(arg1, '!', '\!', 'g')
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg2 = substitute(arg2, '!', '\!', 'g')
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let arg3 = substitute(arg3, '!', '\!', 'g')
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  let cmd = substitute(cmd, '!', '\!', 'g')
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction
set nu!            "设置行号
colorscheme desert     "设置配色方案
syntax on         "语法高亮
syntax enable        set nobackup        "不生成备份文件
set showmatch        "设置匹配模式
set smartindent        "设置只能对齐
set ai!            "设置自动缩进
set fileencodings=utf-8,gbk
set ambiwidth=double    "设置中文支持
set guifont=consolas:h12 "设置字体及大小
set mouse=a        "启用鼠标
set spell spelllang=en_us
set undofile
set history=1000
set wildmenu
set wildmode=longest:list,full
set tabstop=2
set shiftwidth=4
set showmatch
nmap <leader>w :w!<cr>
nmap <leader>f :find<cr>

" 映射全选+复制 ctrl+a
map <C-A> ggVGY
map! <C-A> <Esc>ggVGY
map <F12> gg=G
" 选中状态下 Ctrl+c 复制
vmap <C-c> "+y
vmap <C-v> "+p
nmap <C-z> u

map  ddf <Esc>
omap ddf <Esc>
imap ddf <Esc>
cmap ddf <Esc>
"列出当前目录文件  
map <F3> :tabnew .<CR>  
"打开树状文件目录  
map <C-F3> \be  
"代码补全 
set completeopt=preview,menu 
"允许插件  
filetype plugin on
"共享剪贴板  
set clipboard+=unnamed 
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
"自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endfunction
filetype plugin indent on 


map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!gcc % -o %<"
        exec "! %<"
    elseif &filetype == 'cpp'
        exec "!gcc % -o %<"
        exec "! %<"
    elseif &filetype == 'java' 
        exec "!javac %" 
        exec "!java %<"
    elseif &filetype == 'sh'
        :!%
    endif
endfunc


"C,C++debug
map <F8> :call Rungdb()<CR>
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb %<"
endfunc

" <F5> 运行python程序
map <F6> :w<cr>:!python %<cr>

ps:我觉得新手还不如花半小时配一个sublime呢

猜你喜欢

转载自www.cnblogs.com/xiaolongdejia/p/11327030.html