【原创】Ubuntu下vim配置

1、安装vim

       sudo apt-get install vim

2、配置文件的位置

在目录 /etc/vim下面,有个名为vimrc的文件,首先把vimrc备份一下。

sudo cp vimrc vimrc_backup

这是系统中公共的vim配置文件,对所有用户都有效。

3、配置文件替换

新建一个文件,名为vimrc,将以下代码贴进去,保存。

把该文件复制到/etc/vim/目录下即可。

然后可以用vim编辑一个文件看看格式是否发生变化。

 

注意问题:

建立文件vimrc后,不要用记事本打开编辑,因为格式可能会很乱。用Notepad++或者Editplus等编辑工具进行编辑,保存。之后在用任何编辑器打开,格式都不会乱(包括记事本)。

 

 

 
  1. <span style="font-size:18px;">" An example for a vimrc file.

  2. "

  3. " Maintainer: Bram Moolenaar <Bram@vim.org>

  4. " Last change: 2001 Jul 18

  5. "

  6. " To use it, copy it to

  7. " for Unix and OS/2: ~/.vimrc

  8. " for Amiga: s:.vimrc

  9. " for MS-DOS and Win32: $VIM\_vimrc

  10. " for OpenVMS: sys$login:.vimrc

  11.  
  12. set encoding=utf-8

  13. set fileencodings=utf-8,gbk,gb2312,gb18030,ucs-bom,latin1

  14.  
  15. set tags=tags;

  16. set shiftwidth=4

  17. set ts=4

  18. "set nu

  19. set vb t_vb=

  20. " When started as "evim", evim.vim will already have done these settings.

  21. if v:progname =~? "evim"

  22. finish

  23. endif

  24.  
  25. " Use Vim settings, rather then Vi settings (much better!).

  26. " This must be first, because it changes other options as a side effect.

  27. set nocompatible

  28.  
  29. " allow backspacing over everything in insert mode

  30. set backspace=indent,eol,start

  31.  
  32. set autoindent " always set autoindenting on

  33. set nobackup " do not keep a backup file, use versions instead

  34. "if has("vms")

  35. " set nobackup " do not keep a backup file, use versions instead

  36. "else

  37. " set backup " keep a backup file

  38. "endif

  39. set history=50 " keep 50 lines of command line history

  40. set ruler " show the cursor position all the time

  41. set showcmd " display incomplete commands

  42. set incsearch " do incremental searching

  43.  
  44. set nobackup " do not keep a backup file, use versions instead

  45.  
  46. " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries

  47. " let &guioptions = substitute(&guioptions, "t", "", "g")

  48.  
  49. " Don't use Ex mode, use Q for formatting

  50. map Q gq

  51.  
  52. " Make p in Visual mode replace the selected text with the "" register.

  53. vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>

  54.  
  55. " This is an alternative that also works in block mode, but the deleted

  56. " text is lost and it only works for putting the current register.

  57. "vnoremap p "_dp

  58.  
  59. " Switch syntax highlighting on, when the terminal has colors

  60. " Also switch on highlighting the last used search pattern.

  61. if &t_Co > 2 || has("gui_running")

  62. syntax on

  63. set hlsearch

  64. endif

  65.  
  66. " Only do this part when compiled with support for autocommands.

  67. if has("autocmd")

  68.  
  69. " Enable file type detection.

  70. " Use the default filetype settings, so that mail gets 'tw' set to 72,

  71. " 'cindent' is on in C files, etc.

  72. " Also load indent files, to automatically do language-dependent indenting.

  73. filetype plugin indent on

  74.  
  75. " For all text files set 'textwidth' to 78 characters.

  76. autocmd FileType text setlocal textwidth=78

  77.  
  78. " When editing a file, always jump to the last known cursor position.

  79. " Don't do it when the position is invalid or when inside an event handler

  80. " (happens when dropping a file on gvim).

  81. autocmd BufReadPost *

  82. \ if line("'\"") > 0 && line("'\"") <= line("$") |

  83. \ exe "normal g`\"" |

  84. \ endif

  85.  
  86. endif " has("autocmd")

  87.  
  88. if has("cscope")

  89. let current = "."

  90. let num = 1

  91. while num < 20

  92. if filereadable(current . "/cscope.out")

  93. let $CSCOPE_DB = current . "/cscope.out"

  94. cs add $CSCOPE_DB

  95. break

  96. else

  97. let current = current . "/.."

  98. let num = num + 1

  99. endif

  100. endwhile

  101. endif

  102.  
  103.  
  104. syntax enable

  105. syntax on

  106. colorscheme desert

  107.  
  108.  
  109. filetype plugin indent on

  110. set completeopt=longest,menu

  111.  
  112.  
  113.  
  114. set cst

  115. set csto=1

  116. set cscopequickfix=s-,c-,d-,i-,t-,e-,f-

  117. " cs add /home/yangxl/readcode/cscope-kernel/cscope.out

  118. " cs add /home/yangxl/readcode/cscope-app/cscope.out

  119. let Tlist_Enable_Fold_Column = 0

  120. let Tlist_WinWidth = 30

  121. let Tlist_Show_One_File = 1

  122. let g:miniBufExplMapCTabSwitchBufs = 1

  123. let g:miniBufExplMapWindowNavVim = 1

  124. let g:miniBufExplMapWindowNavArrows = 1

  125. let g:winManagerWindowLayout='FileExplorer|TagList'

  126. let g:SuperTabRetainCompletionType=2

  127. nmap wm :WMToggle<cr>

  128. set tabstop=4

  129. "nmap <F2> :cs find d <C-R><C-W><CR>

  130. "nmap <F3> :cs find c <C-R><C-W><CR>

  131. "nmap <F4> :cs find t <C-R><C-W><CR>

  132. "nmap <F5> :cs find e <C-R><C-W><CR>

  133. "nmap <F6> :cs find f <C-R><C-W><CR>

  134. "nmap <F7> :cs find i <C-R><C-W><CR>

  135. nmap <F5> :TlistToggle <CR>

  136.  
  137. nmap <F2> :cs find c <C-R>=expand("<cword>")<CR><CR>

  138. nmap <F3> :cs find s <C-R>=expand("<cword>")<CR><CR>

  139. nmap <F4> :cs find g <C-R>=expand("<cword>")<CR><CR>

  140. nmap <F6> :cs find f

  141. nmap <C-n> :cn<CR>

  142. nmap <C-p> :cp<CR>

  143. "nmap :cs find t <C-R>=expand("<cword>")<CR><CR>

  144. "nmap :cs find e <C-R>=expand("<cword>")<CR><CR>

  145. "nmap :cs find f <C-R>=expand("<cfile>")<CR><CR>

  146. "nmap :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>

  147. "nmap :cs find d <C-R>=expand("<cword>")<CR><CR>

  148.  
  149. " Using 'CTRL-spacebar' then a search type makes the vim window

  150. " split horizontally, with search result displayed in

  151. " the new window.

  152.  
  153. "nmap <C-Space>s :scs find s <C-R>=expand("<cword>")<CR><CR>

  154. "nmap <C-Space>g :scs find g <C-R>=expand("<cword>")<CR><CR>

  155. "nmap <C-Space>c :scs find c <C-R>=expand("<cword>")<CR><CR>

  156. "nmap <C-Space>t :scs find t <C-R>=expand("<cword>")<CR><CR>

  157. "nmap <C-Space>e :scs find e <C-R>=expand("<cword>")<CR><CR>

  158. "nmap <C-Space>f :scs find f <C-R>=expand("<cfile>")<CR><CR>

  159. "nmap <C-Space>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>

  160. "nmap <F2> :scs find d <C-R>=expand("<cword>")<CR><CR>

  161.  
  162. " Hitting CTRL-space *twice* before the search type does a vertical

  163. " split instead of a horizontal one

  164.  
  165. "nmap <C-Space><C-Space>s

  166. \:vert scs find s <C-R>=expand("<cword>")<CR><CR>

  167. "nmap <C-Space><C-Space>g

  168. \:vert scs find g <C-R>=expand("<cword>")<CR><CR>

  169. "nmap <C-Space><C-Space>c

  170. \:vert scs find c <C-R>=expand("<cword>")<CR><CR>

  171. "nmap <C-Space><C-Space>t

  172. \:vert scs find t <C-R>=expand("<cword>")<CR><CR>

  173. "nmap <C-Space><C-Space>e

  174. \:vert scs find e <C-R>=expand("<cword>")<CR><CR>

  175. "nmap <C-Space><C-Space>i

  176. \:vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>

  177. "nmap <F2>

  178. \:vert scs find d <C-R>=expand("<cword>")<CR><CR>

  179.  
  180. set nu

  181. set mouse=a

  182. set autoindent

  183. set cindent

  184. </span>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值