vim配置IDE,下载压缩包即拥有轻巧且强大的文本编辑器

简介: vim配置IDE,下载压缩包即拥有轻巧且强大的文本编辑器

用 vim 也有一段时间了, 真心是越用越好用, 现已作为敲代码主力以及默认文本编辑器。


工作中常用到c和c++开发,虽然有各种好用的IDE如QTCreater、CLion,还有各种常用的文本编辑工具如vscode,nodepad++,sublineText等,但是还是觉得vim好用。vim小巧灵活,打开代码文件几乎是秒开,像用记事本一样轻便。CLion是很强大,但有点儿太重量级,打开太慢,它比较适合大的工程项目,但有时仅是打开或浏览代码,如记事本般小巧的vim实用。


相信用了会爱不释手,整个压缩包11M大小,就拥有了可以媲美IDE强大的文本编辑神器。


文章末尾有完成压缩包的下载链接,解压即可用。


已经集成了各种常用的vim插件。算不上大而全,但样样都是瑞士军刀般的好用和实用。


支持窗口浏览和目录树显示和浏览的,winmanager和NERDTree插件。


自动代码提示补全的omnicppcomplete 插件。


最强大和好用的查找和替换 -- 插件: easyGrep


快速浏览和操作Buffer -- 插件: MiniBufExplorer


显示函数名的Tag List插件,可以快速跳转到的变量、类型、类和函数。


集成了ctag和cscope等工具,支持函数跳转。


先来截个图:



新手之所以感觉vim不方便,一是需要入门学习,另一点就是想要个好用强大点儿的配置,需要自己安装配置各种插件。而我这个配置的好用之处是只需要下载我提供的压缩包就好了,即可拥有和我一样的配置,常用的快捷键操作助你在码上飞奔,字节跳动。


关闭或显示最左侧的目录树浏览快捷键,只需要按下wm组合键即可。


关闭或显示最右侧的函数或变量列表的taglist,只需要按下tl组合键即可。


按:键输入sp或vsp可以任意分割窗口显示。这在对比可查看多个文件时很有用。想要在多个窗口间跳转切换,只需要按组合键ctrl+w连续按两次。



函数跳转,只需要光标移动到函数的位置上点击两下","符号按键即可。(支持函数跳转有个前提条件:首次在项目的根目录位置使用vim打开文件后,需要执行一个:SrcInit()函数,然后按回车键,这样会自动触发ctag和cscope命令行工具工作。)想再跳转回来,只需要输入",m"即可。



注意红圈圈住的位置,在项目代码根目录下,找到个文件使用vim打开,输入:SrcInit()执行以下



后续就可以愉快的函数跳转啦。


还支持多标签页面及灵活的切换。输入":"符号后,输入tabnew然后按回车,会出现新的tab标签页,在tab标签页上切换也很简单,只需要输入gt两个键即可,完全可以不用移动鼠标啦。


下面是我常用的一些命令, 放在这里供我备忘:


%    跳转到配对的括号去


[[    跳转到代码块的开头去(但要求代码块中'{'必须单独占一行)


gD    跳转到局部变量的定义处hui


''    跳转到光标上次停靠的地方, 是两个', 而不是一个"


mx    设置书签,x只能是a-z的26个字母


`x    跳转到书签处("`"是1左边的键)


>    增加缩进,"x>"表示增加以下x行的缩进


<    减少缩进,"x<"表示减少以下x行的缩进


ctrl+o ,ctrl+I 跳转到光标的上次位置。


gi 回到上次编辑的位置。


按住 Ctrl,然后按两次 o,这条命令可以重复使用,打开更多历史编辑过的文件。


vim格式化代码对齐:1,gg 跳转到第一行 2,shift+v 转到可视模式 3,shift+g 全选


按下神奇的 = 号,你会惊奇的发现代码自动缩进了。


实现自动格式化


打开要编辑的文件,在命令行模式下(不需要按冒号),以此按下


gg
=
G (或者 shift+G)


vim多次复制粘贴方法:在使用p的是时候使用 0p,这样就能无限制的一直粘贴了。


easyGerp查找快捷键


<Leader>vv  # 搜索光标所在单词,并匹配出所有结果,类似 gstar
<Leader>vV  # 搜索光标所在单词,全词匹配,类似 star
<Leader>va  # 类似 vv,但是会把结果添加到之前的搜索列表
<Leader>vA  # 类似 vV,但是会把结果添加到之前的搜索列表
<Leader>vr  # 全局搜索光标所在单词,并替换想要的单词


easygrep查找使用举例:


把光标停留在需要查找的名字前,在浏览模式下输入\vv,效果如下:



注意到没,MiniBufExplorer也很好用。蓝色带*的文件名为正在浏览的文件,看图上面显示了最近你所有打开的文件,想要再去浏览它,直接切换过去点开就行了。


想全局搜索项目中的所有文件怎么办?


默认\vv好像是搜的当前文件下的内容。若想搜整个工程下的,可进入工程根目录下手动敲Grep命令带参数。


:Grep word将搜索"word", 如果加叹号:Grep !word表示全词匹配的方式搜索。


Grep也可以带参数, 比如:Grep -ir word, r表示递归目录. i表示不区分大小写。


后续了解到,easyGerp可以在_vimrc文件里配置一些参数,来设定默认搜索范围:


每个Option的解释可以参考Github上的README


let g:EasyGrepMode = 2 " All:0, Open Buffers:1, TrackExt:2,
let g:EasyGrepCommand = 0 " Use vimgrep:0, grepprg:1
let g:EasyGrepRecursive = 1 " Recursive searching
let g:EasyGrepIgnoreCase = 1 " not ignorecase:0
let g:EasyGrepFilesToExclude = "*.bak, *~, cscope.*, *.a, *.o, *.pyc, *.bak"


窗口快速跳转


当你打开了多个窗口的时候,vim 里可以使用 ctrl+w+hjkl 在窗口之间移动。不过这个操作依然比较麻烦,这里介绍我用的映射直接用 ctrl+hjkl 来进行窗口跳转,使用了 hjkl 保持和 vim normal 模式下的方向保持一致,用起来更符合习惯。


" use ctrl+h/j/k/l switch window
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" 切换 buffer
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> [n :bnext<CR>




还有更多好用的快捷键组合和功能,详情可阅读配置文件_vimrc文件,位置在:



分享下_vimrc文件配置,很多功能和快捷键可以在这里找到。


这个基本不需要改动,或者根据需要可修改或添加功能。


最后附上安装包的下载链接:


下载链接: https://pan.baidu.com/s/1b_XVuBYaHYdZ6HRdPrzvRA?pwd=kn5a 提取码: kn5a


分享个在线测试c++代码的网站:


C++在线编译器,C++在线代码执行,C++在线测试代码 - 字节流


c++在线编译器,c++语言在线解释器,在线编程网站


windows下支持c++11的mingw64的下载安装配置:WinLibs - GCC+MinGW-w64 compiler for Windows



vimrc文件配置:


" Setting some decent VIM settings for programming
" set runtimepath+=d:/YouCompleteMe
set nocp
set ai                          " set auto-indenting on for programming
set showmatch                   " automatically show matching brackets. works like it does in bbedit.
set vb                          " turn on the "visual bell" - which is much quieter than the "audio blink"
set ruler                       " show the cursor position all the time
set laststatus=2                " make the last line where the status is two lines deep so you can see status always
set backspace=indent,eol,start  " make that backspace key work the way it should
set nocompatible                " vi compatible is LAME
set background=dark             " Use colours that work well on a dark background (Console is usually black)
set showmode                    " show the current mode
syntax on                       " turn syntax highlighting on by default
" Show EOL type and last modified timestamp, right after the filename
set statusline=%<%F%h%m%r\ [%{&ff}]\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})%=%l,%c%V\ %P
"------------------------------------------------------------------------------
" Only do this part when compiled with support for autocommands.
if has("autocmd")
    "Set UTF-8 as the default encoding for commit messages
    autocmd BufReadPre COMMIT_EDITMSG,git-rebase-todo setlocal fileencodings=utf-8
    "Remember the positions in files with some git-specific exceptions"
    autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line("$")
      \           && expand("%") !~ "COMMIT_EDITMSG"
      \           && expand("%") !~ "ADD_EDIT.patch"
      \           && expand("%") !~ "addp-hunk-edit.diff"
      \           && expand("%") !~ "git-rebase-todo" |
      \   exe "normal g`\"" |
      \ endif
      autocmd BufNewFile,BufRead *.patch set filetype=diff
      autocmd BufNewFile,BufRead *.diff set filetype=diff
      autocmd Syntax diff
      \ highlight WhiteSpaceEOL ctermbg=red |
      \ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/
      autocmd Syntax gitcommit setlocal textwidth=74
endif " has("autocmd")
" General option
syntax enable
set ruler number
set hlsearch incsearch
set autowrite nobackup
set ignorecase
set linebreak
set mouse=a
set cindent shiftwidth=4 tabstop=4
set backspace=2
set formatoptions=tcqor
set scrolloff=6
set tags=tags,tagsx,..\tags;
set autochdir
set path=**
set laststatus=2
set grepprg=gfind\ .\ -name\ \"*.[chs]\"\ -exec\ grep\ -iHn\ <cword>\ {}\ ;
set shellpipe=2>&1\|tee
compiler! gcc
colorscheme torte
hi StatusLine gui=reverse " guifg=darkgrey guibg=cyan
hi cursorline guibg=grey30
hi cursorcolumn guibg=grey20
hi Search guifg=cyan
nmap ,d :bd<cr>
nmap ,4 :set ts=4<cr>
nmap tt "Ayy
nmap <space>f :find 
nmap <space>g :tag 
nmap <space>i [I
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enhanced up-down-motions
nmap ff zz
nmap fj zb
nmap fk zt
nmap fm ztM
nmap f, zbM
nmap <space>j :call ToggleJK()<cr>
let s:jk_func = 0
function ToggleJK()
  if s:jk_func == 0
    nmap j <Down>zz
    nmap k <Up>zz
    let s:jk_func = 1
    hi StatusLine guifg=darkcyan ctermbg=11
  else
    unmap j
    unmap k
    let s:jk_func = 0
    hi StatusLine guifg=blue ctermbg=15
  endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enhanced code navigation & source code management
nmap ,. :cs find s <cword><cr>
nmap ,, <C-]>
nmap ,m <C-T>
nmap ,j <C-^>
nmap ,a :lv <cword> **/*.[chsCHS]<cr>
" Update settings affected by the location of source code root directory
function UpdateSetting(path)
  execute 'set path=**,' . a:path . '/**'
  execute 'nmap ,a :lv <cword> ' . a:path . '/**/*.[chsCHS]<cr>'
endfunction
" To decide location of the source code root directory
let g:src_root = "."
call UpdateSetting(g:src_root)
" Rebuild environment according to source code root directory
command -nargs=1 SrcInit call SrcInit(<f-args>)
function SrcInit(str)
  let g:src_root = a:str
  " let g:src_root = resolve(getcwd() . "\\" . a:str)
  TagUpdate
  call Warning("Now src_root: " . g:src_root)
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Work directory type: git working copy or svn working copy
function CheckWorkDirType()
  let str = system("git status")
  let ret = stridx(str, "branch")
  if ret != -1 | return "git" | endif
  let str = system("svn info")
  let ret = stridx(str, "UUID")
  if ret != -1 | return "svn" | endif
  return "dir"
endfunction
let g:wd_type = CheckWorkDirType()
function GetRevision()
  if g:wd_type == "git"
    let str = system("git log --pretty=%h")
    return str[0:6]
  elseif g:wd_type == "svn"
    let str = system("svn info")
    let i1 = stridx(str, "Revision")
    let i2 = match(str, "\n", i1)
    return str[i1+10 : i2-1]
  else
    return "0"
  endif
endfunction
let g:wd_rev  = GetRevision()
set statusline=%{g:wd_type}:%n>\ %<%f\ %h%m%r%w%y%=%-5B%-15.(%l/%L,\ %c%V%)\ %P
set titlestring=%F\ %=%{g:wd_type}:%{g:wd_rev}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Function keys
"nmap <special> <F1> :make!<cr>
"lne # 显示下一个quickfix(location list)项
nmap <special> <F1> :lne<cr>
nmap <special> <F2> :lp<cr>
nmap <special> <F3> :lnewer \| lli<cr>
nmap <special> <F4> :lolder \| lli<cr>
nmap <special> <F5> :cn<cr>
nmap <special> <F6> :cp<cr>
nmap <special> <F7> :call ToggleView()<cr>
nmap <special> <F8> :TagUpdate<cr>
if g:wd_type == "git"
  nmap <special> <F9>  :call GitStatus()<cr>
  nmap <special> <F10> :call GitLog()<CR>
  nmap <special> <F11> :call GitLog(bufname(""))<CR>
  nmap <special> <F12> :call GitDiff()<CR>
else
  nmap <special> <F9>  :call SvnStatus()<cr>
  nmap <special> <F10> :call SvnLog()<CR>
  nmap <special> <F11> :call SvnLog(bufname(""))<CR>
  nmap <special> <F12> :call SvnDiff()<CR>
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" For cscope
if has("cscope")
  set csprg=cscope csto=0 cst nocsverb
  if filereadable("cscope.out") " add any database in current directory
    cs add cscope.out
  elseif $CSCOPE_DB != "" " else add database pointed to by environment
    cs add $CSCOPE_DB
  endif
  set csverb
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Save a string into a temp file and view in vim
let s:file_tmp = tempname() . "-zt"
function ViewInTmpFile(str)
  let alist = split(a:str, "\n")
  call writefile(alist, s:file_tmp, 'b')
  let cmd = "view +setlocal\\ nomodifiable " . s:file_tmp
  execute cmd
endfunction
" Save a command output into a temp file and view in vim
function CmdInTmpFile(cmd)
  let ret = system(a:cmd)
  call ViewInTmpFile(ret)
  redraw
  echo "Command: " . a:cmd
endfunction
function Warning(msg)
  echohl LineNr | echo a:msg | echohl None
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enhanced search
set updatetime=800
hi MatchParen guifg=white guibg=grey40
hi xx1 guibg=blue guifg=lightyellow
hi xx2 guibg=darkgreen guifg=lightyellow
hi xx3 guibg=orange guifg=lightyellow
" Highlight the word under cursor
nmap ,8 :autocmd! CursorHold<cr>
nmap ,9 :autocmd! CursorHold * nested silent! call CursorWord()<cr>
nmap <space>7 :call matchadd("xx3", '\c\<' . expand('<cword>') . '\>', 11, 4)<cr>
nmap <space>8 :exe '2match xx1 /\c\<' . expand('<cword>') . '\>/'<cr>
nmap <space>9 :exe 'match xx2 /\c\<' . expand('<cword>') . '\>/'<cr>
nmap <space>0 :exe 'call clearmatches() \| nohlsearch'<cr>
let s:cursor_match_id = 0
function CursorWord()
  call matchdelete(s:cursor_match_id)
  let s:cursor_match_id = matchadd("MatchParen", '\c\<' . expand('<cword>') . '\>', -1)
endfunction
command -nargs=* -complete=tag_listfiles Vvim call Vvim(<f-args>)
function Vvim(...)
  let searchpath = g:src_root . '/**/*.[chsCHS]'
  if a:0 == 0
    let pattern = expand("<cword>")
    let cmd = "lv /" . pattern . "/ " . expand("%")
    call matchadd("Pmenu", '\c' . pattern)
  elseif a:0 == 1
    let cmd = "lv /" . a:1 . "/ " . searchpath
    call matchadd("Pmenu", '\c' . a:1)
  elseif a:0 == 2
    let ptn1 = a:1 . '.*' . a:2
    let ptn2 = a:2 . '.*' . a:1
    let pattern = '\(' . ptn1 . '\)\|\(' . ptn2 . '\)'
    let cmd = "lv /" . pattern . "/ " . searchpath
    call matchadd("Pmenu", '\c' . a:1)
    call matchadd("Todo", '\c' . a:2)
  else
    let cmd = "lv /" . a:1 . "/ " . expand("%")
    call matchadd("Pmenu", '\c' . a:1)
  endif
  try
    echo cmd
    execute cmd
  catch /^Vim(lvimgrep)/
    call Warning("vim: No match")
    return
  endtry
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Git operations
"let s:gitlogcmd="git log --pretty=\"%h: %Cgreen%s %C(cyan)<%an>%Creset <%ai>\" "
"let s:gitlogcmd="git log --pretty=\"%h: %s <%an> <%ai>\" "
let s:gitlogcmd="git log --encoding=cp936 --decorate -- "
let s:diffmode = 0 " diffmode: 0 for whole source code tree, 1 for current file only.
command -nargs=1 Git call Git(<f-args>)
function Git(str)
  let gitprg = "\"c:\\program files\\git\\bin\\git.exe\" " . a:str
  echo system(gitprg)
endfunction
function GitDiff()
  if s:diffmode == 0
    call CmdInTmpFile("git diff -- " . g:src_root)
  else
    call CmdInTmpFile("git diff -- " . bufname(""))
    call Warning("Diff mode: " . s:diffmode)
  endif
  set filetype=diff
endfunction
function GitStatus()
  let g:wd_rev = GetRevision()
  echo "Work dir:" getcwd()
  echo "Src root:" g:src_root
  echo "Git rev :" g:wd_rev
  echo "Git branches:"
  Git branch
  echo "======================================="
  Git status
endfunction
function GitLog(...)
  if a:0 == 0
    let s:diffmode = 0
    call CmdInTmpFile(s:gitlogcmd . g:src_root)
  else
    let s:diffmode = 1
    call CmdInTmpFile(s:gitlogcmd . a:1)
  endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Svn operations
function Svn(str)
  let svnprg = "\"c:\\program files\\TortoiseSvn\\bin\\svn.exe\" " . a:str
  let ret = system(svnprg)
  let xx = split(ret, "\n")
  let yy = sort(xx)
  let zz = join(yy, "\n")
  echo zz
endfunction
function SvnDiff()
  if s:diffmode == 0
    call CmdInTmpFile("svn diff " . g:src_root)
  else
    call CmdInTmpFile("svn diff " . bufname(""))
    call Warning("Diff mode: " . s:diffmode)
  endif
  set filetype=diff
endfunction
function SvnStatus()
  let g:wd_rev = GetRevision()
  echo "Work dir:" getcwd()
  echo "Src root:" g:src_root
  echo "Svn rev :" g:wd_rev
  call Svn("status " . g:src_root)
  echo "======================================="
  call Svn("info")
endfunction
function SvnLog(...)
  if a:0 == 0
    let s:diffmode = 0
    call CmdInTmpFile("svn log " . g:src_root)
  else
    let s:diffmode = 1
    call CmdInTmpFile("svn log " . a:1)
  endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" View patches according to svn revision number & git hash value
command -nargs=0 ViewRevision call ViewRevision(expand("<cword>"))
function ViewRevision(rev)
  if g:wd_type == "git"
    call CmdInTmpFile("git show " . a:rev)
  elseif g:wd_type == "svn"
    call CmdInTmpFile("svn diff -c " . a:rev)
  else
    call Warning("No source control")
  endif
endfunction
" View blame result of current file
command -nargs=0 Blame call Blame(expand("%"))
function Blame(filename)
  let pos = getpos(".")
  if g:wd_type == "git"
    call CmdInTmpFile("git blame " . a:filename)
  elseif g:wd_type == "svn"
    call CmdInTmpFile("svn blame " . a:filename)
  else
    call Warning("No source control")
    return
  endif
  call setpos(".", pos)
endfunction
" Git commit in vim
command -nargs=0 Gitcommit call Gitcommit()
function Gitcommit()
  echo system("git diff --stat")
  let msg = input("Commit msg: ", "", "tag")
  if strlen(msg) == 0
    echo "Commit cannelled"
    return
  endif
  let cmd = "git commit -a -m \"" . msg . "\""
  echo cmd
  echo system(cmd)
  let g:wd_rev = GetRevision()
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" tags and cscope database
" let s:tagfile = tempname() . "-ztg"
let s:tagfile = "tags"
let s:csfile = "cscope.out"
" let s:csfile = tempname() . "-zcs"
function RemoveFile(filename)
  if filereadable(a:filename)
    let ret = delete(a:filename)
    if ret == 0
      echo a:filename . " removed."
    else
      call Warning("Fail to remove " . a:filename)
    endif
  endif
endfunction
" Function BuildTag(): Update tags and cscope database
command -nargs=0 TagUpdate call BuildTag(g:src_root)
function BuildTag(path)
  if cscope_connection()==1
    cs kill -1
  endif
  call RemoveFile(s:tagfile)
  call RemoveFile(s:csfile)
  update
  " Create tag file
  let cmd = "ctags -R --c++-kinds=+p --tag-relative=yes --extra=+q --fields=+iaS "
  " let cmd = cmd . "-f " . s:tagfile . " " . a:path
  echo cmd
  echo system(cmd)
  if filereadable(s:tagfile)
    let cmd = "set tags=" . s:tagfile
    echo cmd
    echo system(cmd)
    " execute cmd
    echo "** Ctags updated **"
  else
    call Warning("** Failed to update ctags **")
  endif
  " Create CS database
  let cmd = "cscope -Rb -v" 
  " let cmd = "cscope -Rb -v -s " 
  " let cmd = cmd . a:path." -f " . s:csfile
  echo cmd
  echo system(cmd)
  if filereadable(s:csfile)
    let cmd = "cs add " . s:csfile
    execute cmd
    echo "** CS updated **"
  else
    call Warning("** Failed to update CS **")
  endif
  call UpdateSetting(a:path)
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cleanup before vim exit
autocmd VimLeavePre * call CleanupStuff()
function CleanupStuff()
  if cscope_connection() == 1
    cs kill -1
  endif
  call RemoveFile(s:tagfile)
  call RemoveFile(s:csfile)
  call RemoveFile(s:file_tmp)
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Coding style: Format C code with your favorite style, format a whole file.
command -nargs=0 Indentlzw call Indentlzw()
function Indentlzw()
  let fcur = bufname("")
  let cmd = "indent -gnu -npsl -ts4 -i4 -bli0 -npcs -nut -fc1 -ncs -st " . fcur
  call CmdInTmpFile(cmd)
  set filetype=c
endfunction
" Another style, change current file directly, no backup.
command -nargs=0 Indentlzwex call Indentlzwex()
function Indentlzwex()
  let fcur = bufname("")
  let cmd = "indent -gnu -npsl -ts4 -i4 -bli0 -npcs -nut -fc1 -ncs " . fcur
  setlocal autoread
  echo system(cmd)
  execute "checktime " . fcur
  redraw
  set autoread<
endfunction
" Format selected code only.
command -range -nargs=0 Rind <line1>,<line2>call Indentrange()
function Indentrange() range
  let src = getline(a:firstline, a:lastline)
  let ftmp = tempname() . "-zi"
  call writefile(src, ftmp, 'b')
  let cmd = "indent -gnu -npsl -ts4 -i4 -bli0 -npcs -nut -fc1 -ncs " . ftmp
  let result = system(cmd)
  execute a:firstline . "," . a:lastline . "d"
  execute a:firstline-1 . "read " . ftmp
  redraw
  call RemoveFile(ftmp)
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Display time
command -nargs=0 Timex call Timex()
function Timex()
  echo strftime("%Y-%m-%d %H:%M:%S (%W%w)")
endfunction
" Online translation
command -nargs=1 Dict call Dict(<f-args>)
function Dict(word)
  let ftmp = tempname() . "-zd-" . a:word
  let cmd = "wget -O " . ftmp . " http://dict.baidu.com/s?wd=" . a:word
  echo system(cmd)
  execute "vi " . ftmp
endfunction
" Online manpage
command -nargs=+ Manp call Manp(<f-args>)
function Manp(word, sec)
  let cachedir = "e:\\mydoc\\manpage\\"
  let fname = cachedir . a:word . "." . a:sec . ".man"
  if filereadable(fname)
    echo "file ready."
  else
    if a:sec == "" | let a:sec = "all" | endif
    let website = " \"http://man.he.net/?topic="
    let cmd = "wget -O " . fname . website . a:word . "&section=" . a:sec . "\""
    echo system(cmd)
  endif
  execute "vi " . fname
  setlocal filetype=man nomodifiable readonly
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Program build
let s:buildprg='!make '
if filereadable("build.bat") | let s:buildprg='!build.bat ' | endif
if filereadable("a.bat")     | let s:buildprg='!a.bat '     | endif
command -nargs=? Build call Build(<q-args>)
function Build(arg)
  exe s:buildprg . a:arg . ' 2>&1| tee ' . s:file_tmp
  exe 'cf ' . s:file_tmp
endfunction
command -nargs=? -complete=file Cppcheck call Cppcheck(<f-args>)
function Cppcheck(arg)
  exe '!cppcheck.exe --enable=all --template=gcc ' . a:arg . ' 2>&1| tee ' . s:file_tmp
  exe 'cf ' . s:file_tmp
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Temporary settings
filetype plugin on
set completeopt=menuone
nmap ,t :tag Main_Code<cr>
nmap ,r :tag ProcFunc<cr>
nmap ,n :exec "tag " . expand("<cword>") . "_Proxy"<cr>
command -nargs=0 Gsh !"C:\Program Files\Git\bin\sh.exe" --login -i
command -nargs=0 Cmd exe '!start C:\tools\console2\console.exe -d ' . expand('%:p:h')
command -nargs=? Bbb exe '!git commit -a -m "v: ' . <q-args> . '"'
""""""""""""""""""""""""""""""""""""""""""""taglist插件配置
let Tlist_Show_One_File = 1    "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1  "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口
" """""""""""""""""""""""""""""""""""""""Taglist快捷键定义
" taglist打开与关闭的切换,TlistOpen打开
nmap tl :TlistToggle<cr> ?
""""""""""""""""""""""""""""""""""""""""""""WinManager 文件管理器插件配置
let g:winManagerWindowLayout='FileExplorer'
nmap wm :WMToggle<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <leader>w :w!<cr>
nmap <leader>f :find<cr>
" 映射全选+复制 ctrl+a
map <C-A> ggvG
" map! <C-A> <Esc>ggVGY
" map <F12> gg=G
" 选中状态下 Ctrl+c 复制
vmap <C-c> "+y
"在插入模式中使用Ctrl+v粘贴全局剪贴板内容
inoremap <C-v> <esc>:set paste<cr>mui<C-R>+<esc>mv'uV'v=:set nopaste<cr>
"在Visual模式中使用Ctrl+c复制内容到全局剪贴板
vnoremap <C-c> "+y
"在Visual模式中使用Ctrl+x剪切内容到全局剪贴板
vnoremap <C-x> "+x
"新建标签  
map <M-F2> :tabnew<CR>  
"列出当前目录文件  
map <C-F3> :tabnew .<CR>  
"共享剪贴板  
set clipboard+=unnamed 
"自动保存
set autowrite
set ruler                   " 打开状态栏标尺
set cursorline              " 突出显示当前行
set magic                   " 设置魔术
set guioptions-=T           " 隐藏工具栏
set guioptions-=m           " 隐藏菜单栏
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
" 设置在状态行显示的信息
set foldcolumn=0
set foldmethod=indent 
set foldlevel=3 
set foldenable              " 开始折叠
" 设置主题颜色
colo molokai
set guifont=Consolas:h12
set fileencodings=ucs-bom,utf-8,chinese,cp936
set lines=45 columns=100
set autoindent
set smartindent
set nobackup
set completeopt=menu,menuone  
"let OmniCpp_MayCompleteDot=1    “  打开  . 操作符
"let OmniCpp_MayCompleteArrow=1  " 打开 -> 操作符
" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " 显示函数参数列表
let OmniCpp_MayCompleteDot = 1   " 输入 .  后自动补全
let OmniCpp_MayCompleteArrow = 1 " 输入 -> 后自动补全
let OmniCpp_MayCompleteScope = 1 " 输入 :: 后自动补全
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" 自动关闭补全窗口
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest
" set encoding=utf-8
" set fileencoding=utf-8
" language messages zh_CN.utf-8
" set number
" set autoindent
" set smartindent
" set tabstop=4
" set autochdir
" set shiftwidth=4
" set foldmethod=manual
" syntax enable
" set nocompatible
" 快速浏览和操作Buffer -- 插件: MiniBufExplorer
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplorerMoreThanOne=0


引用


vim 多文件骚操作,鼠标都不用碰一下[视频] - 知乎


30个Vim常用命令和使用技巧整理 (长期更新) | vim教程网


15个实用却不为人所熟知的Vim技巧 - 知乎

相关文章
|
22天前
|
开发框架 JavaScript 前端开发
百度富文本编辑器配置(vue3)
百度富文本编辑器配置(vue3)
|
22天前
|
Linux 开发工具 数据安全/隐私保护
Centos7:自动化配置vim | suoders信任列表添加普通用户
Centos7:自动化配置vim | suoders信任列表添加普通用户
28 0
|
22天前
|
IDE Java Shell
02|手把手教你安装JDK与配置主流IDE
02|手把手教你安装JDK与配置主流IDE
36 0
|
22天前
|
弹性计算 Unix Linux
Linux:文本编辑器 - vim
Linux:文本编辑器 - vim
21 1
|
22天前
|
Unix Shell Linux
在 Linux 上把 Vim 配置为默认编辑器
在 Linux 上把 Vim 配置为默认编辑器
|
22天前
|
运维 自然语言处理 开发工具
【专栏】NeoVim正逐渐取代Vim成为运维人员首选的文本编辑器。这 8 个原因或许是答案,命令对比一目了然!
【4月更文挑战第28天】NeoVim正逐渐取代Vim成为运维人员首选的文本编辑器。其优势包括更好的扩展性、现代化界面、多语言编程支持、异步处理能力、协作功能、持续更新及活跃社区。NeoVim的命令与Vim相似,但在启动配置、插件管理和窗口管理等方面有所优化。总的来说,NeoVim提供了更强大、灵活和现代的编辑体验。
|
22天前
|
Linux 开发工具
【专栏】Linux 必备技能:Vim文本编辑器中快速跳转到文件开头和结尾的方法
【4月更文挑战第28天】本文介绍了Vim文本编辑器中快速跳转到文件开头和结尾的方法。使用`gg`或`1G`可跳转到文件开头,`G`或`$`则用于跳转到结尾。此外,还提到了跳转到指定行(如`10G`)和查找特定字符(如`f`+字符)的技巧,以提升编辑效率。
|
22天前
|
程序员 开发工具
【专栏】Vim是知名文本编辑器,以其高效操作深受程序员喜爱
【4月更文挑战第28天】Vim是知名文本编辑器,以其高效操作深受程序员喜爱。本文到特定行的技巧,包括基础概念(普通模式与插入模式)、使用`G`命令、命令行、相对行号和搜索功能。此外,还分享了高级技巧,如使用标记和结合插件提升效率。掌握这些方法能提升Vim用户的工作效率。
|
22天前
|
前端开发 数据可视化 API
前端react 18.2整合ckeditor富文本编辑器——配置插件、自定义toolbar工具栏(二)
前端react 18.2整合ckeditor富文本编辑器——配置插件、自定义toolbar工具栏
48 0
前端react 18.2整合ckeditor富文本编辑器——配置插件、自定义toolbar工具栏(二)
|
22天前
|
前端开发 JavaScript CDN
前端react 18.2整合ckeditor富文本编辑器——配置插件、自定义toolbar工具栏(一)
前端react 18.2整合ckeditor富文本编辑器——配置插件、自定义toolbar工具栏
51 0