Solve the problem that Vim cannot automatically indent and highlight code.

Source: Internet
Author: User
Copy/usr/share/vim/vim61/vimrc_example.vim ~ /. Vimrc. My own: Anexampleforavimrcfile. Maintainer: brammoolenstmlt; Bram@vim.orggt; Lastchange: 2002May28Touseit, copyit copy a copy/usr/share/vim/vim61/vimrc_example.vim ~ /. Vimrc.

My own is as follows:

"An example for a vimrc file.
"
"Maintainer: Bram Moolenaar
"Last change: 2002 May 28
"
"To use it, copy it
"For Unix andOS/2 :~ /. Vimrc
"ForAmiga: s:. vimrc
"For MS-DOS and Win32: $ VIM \ _ vimrc
"ForOpenVMS: sys $ login:. vimrc

"When started as" evim ", evim. vim will already have done thesesettings.
If v: progname = ~? "Evim"
Finish
Endif

"Use Vim settings, rather then Vi settings (much better !).
"This must be first, because it changes other options as a sideeffect.
Set nocompatible

"Allow backspacing over everything in insert mode
Set backspace = indent, eol, start

Set shiftwidth = 4
Set tabstop = 4

Set autoindent "alwaysset autoindenting on
If has ("vms ")
Set nobackup "do not keep a backup file, use versions instead
Else
Set backup "keep a backup file
Endif
Set history = 50 "keep 50 lines of command line history
Set rsor "show the cursor position all the time
Set showcmd "display incomplete commands
Set incsearch "do incremental searching

"For Win32 GUI: remove 't'flag from 'guioptions': no tearoffmenu entries
"Let & guioptions = substitute (& guioptions," t "," "," g ")

"Don't use Ex mode, use Q for formatting
Map Q gq

"This is an alternative that also works in block mode, but thedeleted
"Text is lost and it only works for putting the currentregister.
"Vnoremap p" _ dp

"Switch syntax highlighting on, when the terminal hascolors
"Also switch on highlighting the last used search pattern.
If & t_Co> 2 | has ("gui_running ")
Syntax on
Set hlsearch
Endif

"Only do this part when compiled with support forautocommands.
If has ("autocmd ")

"Enable file type detection.
"Use the default filetype settings, so that mail gets 'tw 'set to 72,
"'Cindent 'is on in C files, etc.
"Also load indent files, to automatically dolanguage-dependent indenting.
Filetype plugin indent on

"For all text files set 'textidth' to 78characters.
Autocmd FileType text setlocal textwidth = 78

"When editing a file, always jump to the last knowncursor position.
"Don't do it when the position is invalid or wheninside an event handler
"(Happens when dropping a file on gvim ).
Autocmd BufReadPost *
\ If line ("'\" ")> 0 & line ("' \ "") <= line ("$") |
\ Exe "normal G' \" "|
\ Endif

Endif "has (" autocmd ")
Colors evening

Set cin
Set bdir = ~ /. Vimbk
Function CloseWindow ()
Lets: win_name = "/dev/null"
If s: win_name = "/dev/null"
Exec "close"
Endif
Endfunction

Function RunCmd (cmd)
If a: cmd = ""
Return
Endif

Exec "w"
Exec "sp! /Dev/null"
Exec "r! ". A: cmd." 2> & 1"
Exec "w"
Exec "normal \ J"
Exec "normal \ 8 -"
Normal gg
Endfunction

Function RunCurrentFile ()
Lets: filename = argv (argidx ())
If s: filename = ""
Return
Endif
CallRunCmd ("./". s: filename)
Endfunction

Map : CallRunCurrentFile ()
Map : CallCloseWindow ()
Map : CallRunCmd ("make ")

"Set fileencoding = UTF-8
"Set encoding = UTF-8

Set encoding = gb2312

Three functions are added to process three shortcut keys:
F12 runs the currently opened file and splits the window to store the output result.
F11 close current window
F10 run make

In addition, you need to create ~ /. Vimbk Directory, used to store backup files.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.