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

Source: Internet
Author: User

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.

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.