Unix_Linux Learning (1) -- learning how to use the vim Editor

Source: Internet
Author: User
Tags set background

Recently I want to read this book on Unix advanced programming. I wanted to use the Code: Blocks under Ubuntu. It was quite uncomfortable to use it alone. Finally, I decided to use the simple Vim. below is the configuration of the programming environment.
I. First, install gcc and Vim
Install gcc:
Sudo apt-get build-depgcc or sudo apt-get install build-essential
I have installed it before I configured an environment.
In Tminal, enter gcc-v to display the gcc version information. I am 4.4.5.
Install Vim
Apt-get install vim-full
Configure vimrc
First modify the File Permission
1. Use cd/to go to the file system;
2. Switch cd/etc/vim to the vim directory;
3. Modify the File Permission: sudo chmod 777 vimrc. You will be prompted to enter the password and enter the password;
4. Run vim vimrc to open the vim file and modify the content. I directly stick it to the Internet. Remember to back up the file before modification.




"All system-wide defaults are set in $ VIMRUNTIME/debian. vim (usually just
"/Usr/share/vim/vimcurrent/debian. vim) and sourced by the call to: runtime
"You can find below. If you wish to change any of those settings, you showould
"Do it in this file (/etc/vim/vimrc), since debian. vim will be overwritten
"Everytime an upgrade of the vim packages is saved med. It is recommended
"Make changes after sourcing debian. vim since it alters the value of
"'Compute' option.


"This line shoshould not be removed as it ensures that varous options are
"Properly set to work with the Vim-related packages available in Debian.
Runtime! Debian. vim


"Uncomment the next line to make Vim more Vi-compatible
"NOTE: debian. vim sets 'nocomputed'. Setting 'computed' changes numerous
"Options, so any other options shoshould be set AFTER setting 'compute '.
"Set compatible


"Vim5 and later versions support syntax highlighting. Uncommenting
"Following enables syntax highlighting by default.
If has ("syntax ")
Syntax on
Endif


"If using a dark background within the editing area and syntax highlighting
"Turn on this option as well
"Set background = dark


"Uncomment the following to have Vim jump to the last position when
"Reopening a file
"If has (" autocmd ")
"Au BufReadPost * if line (" '\ "")> 1 & line ("' \" ") <= line (" $ ") | exe" normal! G' \ "" | endif
"Endif


"Uncomment the following to have Vim load indentation rules and plugins
"According to the detected filetype.
"If has (" autocmd ")
"Filetype plugin indent on
"Endif


"The following are commented out as they cause vim to behave a lot
"Differently from regular Vi. They are highly recommended though.
"Set showcmd" Show (partial) command in status line.
"Set showmatch" Show matching brackets.
"Set ignorecase" Do case insensitive matching
"Set smartcase" Do smart case matching
"Set incsearch" Incremental search
"Set autowrite" Automatically save before commands like: next and: make
"Set hidden" Hide buffers when they are abandoned
"Set mouse = a" Enable mouse usage (all modes)


Set tabstop = 4
Set softtabstop = 4
Set shiftwidth = 4
Set autoindent
Set cindent
Set cinoptions = {s, t0, N-2, p2s, (03 s, =. 5 s,> 1 s, = 1 s,: 1 s
Set nu
If & term = "xterm"
Set t_Co = 8
Set t_Sb = ^ [4% dm
Set t_Sf = ^ [3% dm
Endif


"Source a global configuration file if available
If filereadable ("/etc/vim/vimrc. local ")
Source/etc/vim/vimrc. local
Endif
""""""""""""""""""""""""""""""""""""""
"Syntax coloring and highlighting settings
""""""""""""""""""""""""""""""""""""""


"Enable syntax highlighting
Syntax enable
Syntax on


"Color Scheme
"Colo ruki
"Colors ruki
"The ruki plug-in is not found. temporarily disable this function. After finding the plug-in, enable this function.


"Set highlight search
: Set hlsearch


""""""""""""""""""""""""""""""""""""""
"File Settings
""""""""""""""""""""""""""""""""""""""


Set encoding = UTF-8
Set fileencoding = chinese
Set fileencodings = ucs-bom, UTF-8, chinese
Set ambiwidth = double


"Check file type
Filetype on


"No backup by default
: Set nobackup
: Set nowritebackup


""""""""""""""""""""""""""""""""""""""
"Mouse settings
""""""""""""""""""""""""""""""""""""""


"Mouse support
If has ('mouse ')
: Set mouse =
Endif


"Using the mouse like Microsoft Windows seems to solve the problem of multiple consecutive lines of indentation and the problem of backspace
: Behave mswin


""""""""""""""""""""""""""""""""""""""
"Editor settings
""""""""""""""""""""""""""""""""""""""


"Display row number
Set number


"Tab width
: Set ts = 4


"Auto indent
: Set sw = 4


"C/C ++ Style Auto indent
: Set cin
"Option for setting automatic indentation of C/C ++ Style
: Set cino =: 0g0t0 (sus


"Enable Automatic indentation for common file types
: Set ai


"The status line at the cursor position is displayed in the lower right corner during editing.
: Set ruler


"Display matching brackets
: Set showmatch


"The deletion key can be used in insert mode.
: Set backspace = indent, eol, start


"Code folding, command za
: Set foldmethod = syntax
: Set foldlevel = 100 "do not automatically collapse the code when vim is started.


"Set Font
": Set guifont = courier/9


"When you right-click a window, a shortcut menu is displayed.
: Set mousemodel = popup


"Automatic line feed
If (has ("gui_running") "Gui settings


"Do not fold rows. If a line is too long and exceeds the screen width, it will extend to the right side to the outside of the screen
: Set nowrap
"Add a horizontal scroll bar. If you specify no rows, it is necessary to add a horizontal scroll bar for the window.
: Set guioptions + = B


Settings on the else character Interface
Set wrap
Endif


""""""""""""""""""""""""""""""""""""""
"Shortcut key settings
""""""""""""""""""""""""""""""""""""""
"<F1> dynamic switching between menu bar and toolbar hide and display
Set guioptions-= m
Set guioptions-= T
Map <silent> <F1>: if & guioptions = ~ # 'T' <Bar>
\ Set guioptions-= T <Bar>
\ Set guioptions-= m <bar>
\ Else <Bar>
\ Set guioptions + = T <Bar>
\ Set guioptions + = m <Bar>
\ Endif <CR>


"<F2> code_complete.vim Plugin: The function is automatically completed.
If! Exists ("g: completekey ")
Let g: completekey = "<F2>" "hotkey
Endif


"<F3> <F4> case-insensitive Conversion
Map <F3> gu
Map <F4> gU


"The current directory generates a tags syntax file for Automatic completion. Function prompt: code_complete.vim OmniCppComplete. vim...
"Map <F5> :! Ctags-R -- c-kinds = + p -- fields = + S. <CR>
Map <F5> :! Ctags-R -- c-kinds = + p -- c ++-kinds = + p -- fields = + iaS -- extra = + q. <CR>


"Function and Variable list
Map <F6>: TlistToggle <CR>


"File Browser
Map <F7>: WMToggle <CR>
Let g: winManagerWindowLayout = "FileExplorer"


"File tree list
Map <F8>: NERDTree <CR>


"Copy, paste, and clipboard ctrl ing ctrl + c ctrl + v ctrl + x
: Map <C-V> "+ pa <Esc>
: Map! <C-V> <Esc> "+ pa
: Map <C-C> "+ y
: Map <C-X> "+ x


"Select ctrl + a for all mappings.
: Map <C-A> ggVG
: Map! <C-A> <Esc> ggVG


"Multi-line indent
: Map <Tab>
: Map <S-Tab> <


""""""""""""""""""""""""""""""""""""""
"Plugin settings
""""""""""""""""""""""""""""""""""""""


"Enable OmniCppComplete. vim
Set nocp
Filetype plugin on


"2Html plug-in, enabling XHtml css
: Let html_number_lines = 1
: Let html_use_css = 1
: Let use_xhtml = 1


"Fencview. vim plug-in settings
Let g: fencview_autodetect = 1 "automatically identifies the encoding when the file is opened
Let g: fencview_checklines = 10 "check the first 10 lines to determine the encoding.


"Autocomplpop. vim & supertab. vim plug-in settings
Let g: AutoComplPop_IgnoreCaseOption = 1
Set ignorecase


""""""""""""""""""""""""""""""""""""""
"Other settings
""""""""""""""""""""""""""""""""""""""


"Remove the annoying vi consistency mode to avoid bugs and limitations in earlier versions.
: Set nocompatible
5. Save and exit


Next, compile a Helloworld in Vim and then compile and run it with gcc.
Find GVim in the application,
1. Run the following code:
# Include <stdio. h>


Int
Main (void)
{
Printf ("Hello, world ");
Return 0;
}
Save as h.c;
(Note: the basic operations of Vim can be learned at http://www.chinavim.org)
2. In Vim, enter :! Gcc-Wall c/h. c-o hello
For a brief explanation ,:! In Vim, external commands are called.-Wall is the prompt of the compiler, followed by the location of the source file, and-o is followed by the file name of the target file.
3. Run./hello again. Result (Note: The final file generated after gcc compilation is in the current directory of the command, rather than the directory of the source file.-Wall should be added );
4. Close the job.

In the future, you will be able to get rid of those complex IDES and restore the programming itself.




The author's left brain designs right brain Programming

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.