windows下使用vim及其带来的问题

Posted 王玉成的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了windows下使用vim及其带来的问题相关的知识,希望对你有一定的参考价值。

一般在家还是用windows环境。看看代码,一般还是需要用vim和两个插件ctags.exe和taglist.

 

首先下载windows下的vim,安装,没有问题。

 

接着找到ctags.exe和taglist插件,下载。也没问题

 

为了省事,直接把ctags.exe拷到你的windows的system32目录下。

 

在windows系统下必须注意这一点

把taglist拷到你VIM的安装目录的vimfiles目录下,两个文件,doc下的帮助和plugin下的VIM脚本。

打开GVIM,然后敲下列命令

:cd $VIM/vimfiles/doc
:help taglist .

其中$VIM代表你VIM的安装路径。

别忘了,在命令行下,你的源代码的顶级目录下执行一下

ctags -R

生成tags文件

 

然后在vim的目录下,注意不是vim73或者是vimfiles目录下,把下面的内容补充到_vimrc文件里。

 

set nocompatible    " use vim defaults
set ls=2            " allways show status line
set tabstop=4       " numbers of spaces of tab character
set shiftwidth=4    " numbers of spaces to (auto)indent
set scrolloff=3     " keep 3 lines when scrolling
set showcmd         " display incomplete commands
set hlsearch        " highlight searches
set incsearch       " do incremental searching
set ruler           " show the cursor position all the time
set visualbell t_vb=    " turn off error beep/flash
set novisualbell    " turn off visual bell
set nobackup        " do not keep a backup file
set number          " show line numbers
set ignorecase      " ignore case when searching
"set noignorecase   " don't ignore case
set title           " show title in console title bar
set ttyfast         " smoother changes
"set ttyscroll=0        " turn off scrolling, didn't work well with PuTTY
set modeline        " last lines in document sets vim mode
set modelines=3     " number lines checked for modelines
set shortmess=atI   " Abbreviate messages
set nostartofline   " don't jump to first character when paging
set whichwrap=b,s,h,l,<,>,[,]   " move freely between files
"set viminfo='20,<50,s10,h

"set autoindent     " always set autoindenting on
"set smartindent        " smart indent
"set cindent            " cindent
set noautoindent
set nosmartindent
set nocindent  

"set autowrite      " auto saves changes when quitting and swiching buffer
"set expandtab      " tabs are converted to spaces, use only when required
"set sm             " show matching braces, somewhat annoying...
"set nowrap         " don't wrap lines

syntax on           " syntax highlighing
colorscheme elflord    " use this color scheme
set background=dark        " adapt colors for background

if has("autocmd")
" Restore cursor position
au BufReadPost * if line("'/"") > 0|if line("'/"") <= line("$")|exe("norm '/"")|else|exe "norm $"|endif|endif

" Filetypes (au = autocmd)
au FileType helpfile set nonumber      " no line numbers when viewing help
au FileType helpfile nnoremap    " Enter selects subject
au FileType helpfile nnoremap    " Backspace to go back

" When using mutt, text width=72
au FileType mail,tex set textwidth=72
au FileType cpp,c,java,sh,pl,php,asp  set autoindent
au FileType cpp,c,java,sh,pl,php,asp  set smartindent
au FileType cpp,c,java,sh,pl,php,asp  set cindent
"au BufRead mutt*[0-9] set tw=72

" Automatically chmod +x Shell and Perl scripts
"au BufWritePost   *.sh             !chmod +x %
"au BufWritePost   *.pl             !chmod +x %

" File formats
au BufNewFile,BufRead  *.pls    set syntax=dosini
au BufNewFile,BufRead  modprobe.conf    set syntax=modconf
endif

" Keyboard mappings
map :previous  " map F1 to open previous buffer
map :next      " map F2 to open next buffer
map :silent noh " turn off highlighted search
map ,v :sp ~/.vimrc " edit my .vimrc file in a split
map ,e :e ~/.vimrc      " edit my .vimrc file
map ,u :source ~/.vimrc " update the system settings from my vimrc file
"----- write out html file
map ,h :source $VIM/vim71/syntax/2html.vim:w:clo


" Common command line typos
"cmap W w
"cmap Q q

" Keyboard mapping for numeric keypad
"imap OM 
" map OM 
"imap OP 
" map OP 
"imap OQ /
" map OQ /
"imap OR *
" map OR *
"imap OS -
" map OS -

"imap Ol +
"imap Om -
"imap On ,
    "imap Op 0
    "imap Oq 1
    "imap Or 2
    "imap Os 3
    "imap Ot 4
    "imap Ou 5
    "imap Ov 6
    "imap Ow 7
    "imap Ox 8
    "imap Oy 9
    "imap Oz 0


set cursorline "add edit line"


set tags=tags;
set autochdir

let Tlist_Ctags_Cmd='ctagsctags'
let Tlist_Use_LEFT_Window=1
let Tlist_File_Fold_Auto_Close=1
let Tlist_Show_One_File=1
let Tlist_GainFocus_On_ToggleOpen=1
let Tlist_Exit_OnlyWindow=1
nmap tl :Tlist<cr>

 

这个配置文件中关于

if has("autocmd")

以及下面的自动命令的设置估计会报错,如果不需要,可以把关于aoutocmd的这一片东西都去掉。

前面的是一大段是关于VIM的配置,按下不表,从后面

set tags=tags;
set autochdir

意思说,tag是用的tags的命名文件夹。打开任意一代码,如果在当前目录下没找到tags文件,会递归的往上级目录去找。一直到找到为止。

这样,就可以不用打开VIM,在冒号下切换tags所在的路径了。

let Tlist_Ctags_Cmd='ctagsctags'

上一条命令大概是taglist在windows下的BUG引起的,前面加ctags是为了偏移出5个字符,这样可以调用ctags命令。

后面这几条是关于taglist的缩写和一些配置,可有可无。
let Tlist_Use_LEFT_Window=1
let Tlist_File_Fold_Auto_Close=1
let Tlist_Show_One_File=1
let Tlist_GainFocus_On_ToggleOpen=1
let Tlist_Exit_OnlyWindow=1
nmap tl :Tlist<cr>


 

 

以上是关于windows下使用vim及其带来的问题的主要内容,如果未能解决你的问题,请参考以下文章

linux下的vim使用笔记

vim 配置问题 :ctags 在windows 下怎样安装?

如何在 Ubuntu 下正确显示 vim-airline 的箭头符号

如何在vim中搜索文件目录?

我可以在将文件保存到 Vim 之前查看更改吗?

vim编辑器介绍及其常用命令