Ruby learning Note 2 helps generate code for Vim to add code headers, rubyvim

Source: Internet
Author: User

Ruby learning Note 2 helps generate code for Vim to add code headers, rubyvim

The script language is too strong.

My goal is to add my default code header function to Vim.

/*******************************************************************************  COPYRIGHT NOTICE*  Copyright (c) 2014 All rights reserved*  ----Stay Hungry Stay Foolish----**  @author  : Shen*  @name   :*  @file   : G:\My Source Code\DefaultCode.cpp*  @date   : 2014/06/14 02:44*  @algorithm :******************************************************************************///#pragma GCC optimize ("O2")//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <bits/stdc++.h>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;template<class T>inline bool updateMin(T& a, T b){ return a > b ? a = b, 1: 0; }template<class T>inline bool updateMax(T& a, T b){ return a < b ? a = b, 1: 0; }/*//STL#include <map>#include <vector>#include <list>#include <stack>#include <deque>#include <queue>*//*//Computational Geometry#include <complex>#define x real()#define y imag()typedef complex<double> point;*/typedef long long int64;void solve(){}int main(){ return 0;}

Use the Ruby10 line to handle the string processing. It's amazing.

def load( path ) File.foreach(path) do |line|  line["\n"] = ""  str = "let l = l + 1 | call setline(l, \'#{line}\')"  File.open("s.txt", "a") do |f|   f << "#{str}\n"  end endendload("DefaultCode.cpp")

In the end, manually add the first and the last parts.

"F4 Add a file header map <F4>: call TitleDet () <cr> function AddTitle () let l = 0let l = l + 1 | call setline (l, '/************************************** **************************************** ') let l = l + 1 | call setline (l, '* copyright notice') let l = l + 1 | call setline (l, '* Copyright (c) 2014 All rights reserved ') let l = l + 1 | call setline (l,' * ---- Stay Hungry Stay Foolish ---- ') let l = l + 1 | call set Line (l, '*') let l = l + 1 | call setline (l, '* @ author: shen') let l = l + 1 | call setline (l, '* @ name:') let l = l + 1 | call setline (l, '* @ file :'. expand ("%: p: h "). "\\". expand ("%: t") let l = l + 1 | call setline (l, '* @ date :'. strftime ("% Y/% m/% d % H: % M") let l = l + 1 | call setline (l, '* @ algorithm :') let l = l + 1 | call setline (l, '*************************************** ******************** * *****************/') Let l = l + 1 | call setline (l ,'') let l = l + 1 | call setline (l, '// # pragma GCC optimize ("O2")') let l = l + 1 | call setline (l, '// # pragma comment (linker, "/STACK: 1024000000,1024000000")') let l = l + 1 | call setline (l ,'') let l = l + 1 | call setline (l, '# include <bits/stdc ++. h> ') let l = l + 1 | call setline (l,' # include <cmath> ') let l = l + 1 | call setline (l,' # include <Cstdio> ') let l = l + 1 | call setline (l,' # include <string> ') let l = l + 1 | call setline (l, '# include <cstring>') let l = l + 1 | call setline (l, '# include <iomanip>') let l = l + 1 | call setline (l, '# include <iostream>') let l = l + 1 | call setline (l, '# include <algorithm>') let l = l + 1 | call setline (l, 'Using namespace std; ') let l = l + 1 | call setline (l, 'template <class T> inline bool update Min (T & a, T B) {return a> B? A = B, 1: 0;} ') let l = l + 1 | call setline (l, 'template <class T> inline bool updateMax (T & a, T B) {return a <B? A = B, 1: 0;} ') let l = l + 1 | call setline (l, '') let l = l + 1 | call setline (l, '/* // STL') let l = l + 1 | call setline (l, '# include <map>') let l = l + 1 | call setline (l, '# include <vector>') let l = l + 1 | call setline (l, '# include <list>') let l = l + 1 | call setline (l, '# include <stack>') let l = l + 1 | call setline (l, '# include <deque>') let l = l + 1 | call setline (l, '# include <queue>') let L = l + 1 | call setline (l, '*/') let l = l + 1 | call setline (l ,'') let l = l + 1 | call setline (l, '/* // Computational ry') let l = l + 1 | call setline (l, '# include <complex>') let l = l + 1 | call setline (l, '# define x real ()') let l = l + 1 | call setline (l, '# define y imag ()') let l = l + 1 | call setline (l, 'typedef complex <double> point; ') let l = l + 1 | call setline (l,' */') let l = l + 1 | Call setline (l, '') let l = l + 1 | call setline (l, 'typedef long int64 ;') let l = l + 1 | call setline (l, '') let l = l + 1 | call setline (l, 'void solve ()') let l = l + 1 | call setline (l, '{') let l = l + 1 | call setline (l ,'') let l = l + 1 | call setline (l, '}') let l = l + 1 | call setline (l ,'') let l = l + 1 | call setline (l, 'int main () ') let l = l + 1 | call setline (l ,'{') let l = l + 1 | Call setline (l, '') let l = l + 1 | call setline (l, 'Return 0; ') let l = l + 1 | call setline (l, '}') endfunction "updates the last modification time and file name function UpdateTitle () call setline (8, '* @ file :'. expand ("%: p: h "). "\\". expand ("%: t") call setline (9, '* @ date :'. strftime ("% Y/% m/% d % H: % M") endfunction "determines whether the word copyright notice exists in the first 10 lines of code." If not, indicates that the author information has not been added and needs to be added. "If yes, you only need to update function TitleDet () let n = 2" by default T line = getline (n) let str = '^ * copyright notice $' if line = ~ Str call UpdateTitle () return endif call AddTitle () endfunction


High score win7 gvim PHP code development tips, Automatic completion can be my vim_73 version

I use neocomplcache for Automatic completion, but it is not for a specific language. The following is my configuration. The ctrl + k dialog box is displayed.

"Neocomplcache switch.
Map <F4>: NeoComplCacheToggle <CR>
Imap <F4> <ESC>: NeoComplCacheToggle <CR>

"Disable AutoComplPop.
"Let g: acp_enableAtStartup = 0
"Enable neocomplcache. 1 is open
Let g: neocomplcache_enable_at_startup = 1
"Enable smartcase. It is case sensitive only when uppercase letters are entered.
"Let g: neocomplcache_enable_smart_case = 1
"Enable uppercase letter completion. When you enter uppercase letters, you can perform fuzzy search for possible words. For example, when you enter AE, ArgumentsException is matched.
Let g: neocomplcache_enable_camel_case_completion = 1
"Enable underline completion. Fuzzy search for matching words. For example, when 'P _ H' is input, it matches 'public _ html '. The default value is 0.
Let g: neocomplcache_enable_underbar_completion = 1
"Set the minimum syntax keyword length.
Let g: neocomplcache_min_syntax_length = 3
Let g: neocomplcache_lock_buffer_name_pattern = '\ * ku \*'

"Define dictionary.
"Let g: neocomplcache_dictionary_filetype_lists = {
"\ 'Default ':'',
"\ 'Vimshell': $ HOME. '/. vimshell_hist ',
"\ 'Scheme ': $ HOME.'/. gosh_completions'
"\}

"Define keywords.
If! Exists ('G: neocomplcache_keyword_patterns ')
Let g: neocomplcache_keyword_patterns = {}
Endif
Let g: neocomplcache_keyword_patterns ['default'] = '\ h \ w *'

"Plug-in key ing.
Imap <C-k> <Plug> (neocomplcache_snippets_expand)
Smap <C-k> <Plug> (neocomplcache_snippets_expand)
Inoremap <expr> <C-g> neocomplcache # undo_completion ()
Inoremap & l ...... remaining full text>

Where is vim and emacs better than ultraedit and notepad2/++?

The capabilities of vim and emacs are indeed powerful, and the customization capability is also very strong.

For example, vim allows you to customize syntax highlighting, color schemes, text encoding, display row numbers, automatic indentation, automatic saving, and search result highlighting. You can set a function key to run a program, VIM should be a programmer's editor. Now I write C, python, ruby, rails and other programs in vim, and run them directly by F4.

Emacs is much more complex than vim, but as long as we can solve our tasks, we don't have to master all emacs functions. Now I also use emacs to write python programs, press ctrl-c to run directly, and run c and ruby with emacs.

Vim's custom file is. vimrc, and emacs's custom file is. emacs. After customized configuration files and various plug-ins are downloaded, almost all desired functions are implemented.

Emacs has better text processing capability than vim, and stronger binary processing capability than vim. emacs is larger than vim. If a file is displayed in hexadecimal mode in vim, the file is displayed correctly in hexadecimal mode in emacs. Emacs and vim open a large file, which is faster than other common programs.

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.