How to change Vim to source insight

Source: Internet
Author: User

In Windows, many people use source insight to write and view code. Vim can be used in Linux. At the beginning, VIM is considered as a notepad in windows. If it is used properly, it is not inferior to source insight.
Here, I will do my best to explain in detail how to turn Vim into source insight, but you still need to think positively and explore something on your own.
To avoid being too arrogant, I put the basic part behind it. If you think it is too simple, this article is not suitable for you; if you still have questions or do not understand what you are talking about, don't worry. There will be some necessary knowledge later.

1. Make good use of the built-in system software ctags
Most Unix systems have the ctags software, which works well with vim.
Purpose:
Generate a C-language Tag file to redirect between related C files.
Usage:
1. Generate a Tag file
In the current directory (run the command after the $ prompt ):
$ Ctags-R.
-R indicates recursive and recursion. It generates a Tag file for the c file in the current directory and Its subdirectory. The last one is in the current directory.
After running the current directory, one more file tags is the index file of the C tag.

2. Jump
1) Use Vim to open a c file with tags already created
2) Ctrl +] locate the tag definition location where the cursor is located
3) Ctrl + t return to the previous Tab
Note: Run Vim in the directory where the "tags" file is located. Otherwise, the "tags" file cannot be found. In vim, use the ": settags =" command to set the path of the "tags" file. For a slightly larger project, you may open Vim in any directory. However, generating a tags file in each directory is not a good idea. How can this problem be solved? The method is to add a line in. vimrc:
Set tags = tags ;/
This tells Vim to go to the upper-level directory to find the tags file when it cannot be found in the current directory.

2. Additional installation scripts:

1. taglist
Http://www.vim.org/scripts/script.php? Script_id = 1, 273
If the download address has changed, go to www.vim.org to find the correct address, which is very simple.

Purpose:
After opening the source code, you can view the overall architecture of the source code for easy jump. (Those who are used to source insight must recall some memories. ^_^)
Usage:
Download and install the plug-in. Enter the command in vim.
: Tlist
To open/close the taglist window.
A simple method is to set the shortcut key and add a line in. vimrc:
Nnoremap <silent> <F8>: tlisttoggle <CR>
In this way, press F8 in VIM to open/close the taglist.
For more configurations, see Introduction to. vimrc.

III. Basic Knowledge

Convention: for convenience and accuracy, we agree that the command after "$" is run on the terminal, and the command after ":" is run in vim.

Vim configuration files are generally stored in the user's main folder, and run on the terminal in non-root state.
$ Cd ~ /
The directory to which the file is named. vimrc.
Can't see it? There are two possibilities:
1. There is a dot before the file name, indicating that the file is hidden. You need to add the-A option when viewing the LS file.
$ LS-
2. You have not created a. vimrc file. Just create one by yourself. First, create an empty file. You can fill in the file continuously.
$ Touch. vimrc

There is also a. Vim folder in the main folder. Do not have mkdir on your own
$ Mkdir ~ /. Vim
In the. Vim folder, create two subfolders: plugin and Doc.
$ Mkdir ~ /. Vim/plugin
$ Mkdir ~ /. Vim/doc
Plugin folder is used to place the plug-in, and the doc folder is used to place the corresponding help document.
Go to the next taglist (should we call it a script or a plug-in? It is placed in the plugin folder, so it should be a plug-in; while in vim.org, it exists as a scripts, it should be a script .), Let's take an example.
Download a zip package and place it in ~ /. Vim directory, and then
$ Unzip filename.zip
You have automatically placed taglist.vimand taglist.txt In the plugin and Doc folders.
Restart vim.
$ Vim
Run
: Tlist
Is there a column next to it? If you open a c file and have generated a tags file, some useful information should be displayed.
At this time, the help document of taglist is already in ~ /. Vim/doc directory, but you have typed
: Help tlist
But there is no response, that is because Vim has not obtained the tag in the help document. The solution is in VIM
: Helptags ~ /. Vim/doc
Now
: Help tlist
Are there any responses?

About. vimrc
My own. vimrc is constantly being improved. In the process of perfection, I benefited from a lot of knowledge gained from the Internet. Thanks to the friends who provided the information, they also urged me to write this article. I paste part of my. vimrc below. You can add these to your. vimrc as needed.

". Vimrc
"""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""
"General
"""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""
"For ctags, then it can find the 'tags' file even not in current directory
Set tags = tags ;/

"Get Out of VI's compatible mode ..
Set nocompatible

"Sets how many lines of history Vim Har to remember
Set history = 400

"Set to auto read when a file is changed from the outside
Set autoread

"Have the mouse enabled all the time:
"When you need to copy from vim, maybe you have to ': Set mouse = 'first
Set mouse =

"""""""""""""""""""""""""""""""""""""
"Colors and Fonts
"""""""""""""""""""""""""""""""""""""
"Enable syntax highlight
Syntax enable

"Set colorscheme
Colorscheme elflord
"Endif

"""""""""""""""""""""""""""""""""""""
"Vim userinterface
"""""""""""""""""""""""""""""""""""""
"Set 7 lines to the curors away from the border-when moving vertical ..
Set so = 7

"Turn on wild menu
Set wildmenu

"Always show current position
Set ruler

"The commandbar is 2 high
Set bytes Height = 2

"Show line number
Set nu

"Set backspace
Set backspace = EOL, start, indent

"Bbackspace and cursor keys wrap
Set whichwrap + = <,>, H, l

"Show matching bracets
Set showmatch

"How many tenths of a second to blink
Set MAT = 2

"Highlight search things
Set hlsearch
"Imediately show the search result
Set is

"""""""""""""""""""""""""""""""""""""
"Folding
"""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
Set nofen
Set FDL = 0

"""""""""""""""""""""""""""""""""""""
"Text options
"""""""""""""""""""""""""""""""""""""
Set expandtab
Set shiftwidth = 2
Set ambiwidth = double
Set smarttab
"Set Tab = 4 spaces
Set Ts = 4
Set LBR
Set Tw = 500
Set selection = random sive
""""""""""""""""""""""""""""""
"Indent
""""""""""""""""""""""""""""""
"Auto indent
Set AI
"Set auto indent width = 4 spaces
Set Sw = 4

"Smart indet
Set Si

"C-style indenting
Set cindent "Usage: Select codes, press '= 'key, the codes will autoindenting

"Wrap lines
Set wrap

"Encoding settings
If has ("multi_byte ")
"Set fileencoding priority
If getfsize (expand ("%")> 0
Set fileencodings = ucs-bom, UTF-8, cp936, big5, EUC-JP, EUC-KR, Latin1
Else
Set fileencodings = cp936, big5, EUC-JP, EUC-KR, Latin1
Endif

"CJK environment detection and corresponding setting
If V: lang = ~ "^ Zh_cn"
"Use cp936 to support GBK, EUC-Cn = gb2312
Set encoding = cp936
Set termencoding = cp936
Set fileencoding = cp936
Elseif V: lang = ~ "^ Zh_tw"
"Cp950, big5 or EUC-TW
"Are they equal to each other?
Set encoding = big5
Set termencoding = big5
Set fileencoding = big5
Elseif V: lang = ~ "^ Ko"
"Copied from someone's dotfile, untested
Set encoding = EUC-KR
Set termencoding = EUC-KR
Set fileencoding = EUC-KR
Elseif V: lang = ~ "^ Ja_jp"
"Copied from someone's dotfile, unteste
Set encoding = EUC-JP
Set termencoding = EUC-JP
Set fileencoding = EUC-JP
Endif
& Quot; detect UTF-8 locale, and replace CJK setting if needed
If V: lang = ~ "Utf8 $" | V: lang = ~ UTF-8 $"
Set encoding = UTF-8
Set termencoding = UTF-8
Set fileencoding = UTF-8
Endif
Else
Echoerr "sorry, this version of (g) Vim was not compiled with multi_byte"
Endif

"""""""""""""""""""""""""""""""""""""
"Plugins

"""""""""""""""""""""""""""""""""""""
"Tlist
If & diff
Let tlist_auto_open = 0 "Don't auto pen when compare two files
Else
Let tlist_auto_open = 1 "auto pen tlist when open a file
Endif

"Set taglist window in right, delete the following line if you don't like
Let tlist_use_right_window = 1
Let tlist_auto_update = 1
Let tlist_file_fold_auto_close = 1
"Auto close tlist when exiting file.
Let tlist_exit_onlywindow = 1

NMAP <F7>: Copen <CR>
NMAP <F6>: cClose <CR>

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.