Saturday 4 April 2015

How to change your GRUB background image on your Linux machine

How to change your GRUB background image on your Linux machine :



When linux is booting up you will see GRUB splash box with black background color which is having multiple option to choose which linux version you want to run. You can change that background image by following trick.

I am currently using fedora 20 with grub-2. I think for all linux distribution this procedure will be same.

Changing background image:

Grub2 generally support PNG, JPG/JPEG, TGA image for the background.

1. First download one awesome HD wallpaper image for background. You can even download background image with your choice. for changing my grub background image i downloaded image from http://wallpapers55.com/wp-content/uploads/2013/11/hd-wallpaper-paradise-beach.jpg 

2. Then put this image in   /boot/grub2/themes/system/   folder of your linux machine.

3. Then open "/boot/grub2/themes/system/theme.txt"    file and replace desktop-image entry to 
 desktop-image: "your image name.png/jpg/jpeg"

4. Have a patience, you are almost done :) 

5. Then open   /etc/default/grub  file  and see the  "GRUB_TERMINAL_OUTPUT="console"  "  entry. This entry for secure boot stuff. If this entry present then add #  at start of line. "# " is for disabling console output for grub menu. Now your grub will use graphic mode again.

6. After that you will need to run 'grub2-mkconfig -o /boot/grub2/grub.cfg' command.  This command to update the live grub config after changing the file in /etc/default

 7. Congratulation!!!! you have successfully change your grub background image.







Saturday 9 August 2014

Linux: Managing double linked list in the Linux kerne

Linux: Managing double linked list in the Linux kernel

# LIST_HEAD(list_name): Creat an new double linked list.  
 
$ list_add(n,p): Inserts an element pointed to by n right after the specified element pointed to by p. To insert n at the beginning of the list, set p to the address of the list head.

 $ list_add_tail(n,p): Inserts an element pointed to by n right before the specified element pointed to by p. To insert n at the end of the list, set p to the address of the list head.

 $ list_del(p): Deletes an element pointed to by p

 $ list_empty(p): Checks if the list specified by the address p of its head is empty.

 $ list_entry(p,t,m): Returns the address of the data structure of type t in which the list_head field that has the name m and the address p is included.
                    #define list_entry(ptr, type, member)                                   \
                     ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

 $ list_for_each(p,h): Scans the elements of the list specified by the address h of the head; in each iteration, a pointer to the list_head structure of the list element is returned in p.
                  #define list_for_each(pos, head)                                        \
                   for (pos = (head)->next; pos != (head); pos = pos->next)

$ list_for_each_entry(p,h,m): Returns the address of the data structure embedding the list_head structure rather than the address of the list_head structure itself.

    #define list_for_each_entry(pos, head, member)                          \
       for (pos = list_entry((head)->next, typeof(*pos), member);      \
             &pos->member != (head);                                    \
             pos = list_entry(pos->member.next, typeof(*pos), member))



Why this is ((type*)0)->member, not (type*)->member????

Simply because (type*)->member would be invalid syntax, thus typeof would be impossible. So it uses a NULL pointer, which it doesn't dereference anyway - it's used just so typeof can refer to the member.
How this works:

  • The typeof trick is used to declare a pointer of the type of the member. This pointer gets is initialized with the pointer passed by the caller
  • The offset of that member in the struct is subtracted from the address of the pointer: this yields the address of the containing object

Thursday 7 August 2014

What is in your .vimrc (~/.vimrc) file.!!!!!

What is vimrc

The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. On Unix,Linux based systems, the file is named .vimrc,

 
You can customize Vim by putting suitable commands in your vimrc.
Here is a simple example:
 
**************************************
 Hear are some my favourite command that i use in .vimrc file. 
 
set autoindent                 " turn on auto-indenting (great for programmer)

set cursorline                 " show the current cursor postion all the time in all window
 
set colorcolumn=80             " set long vertical line at column 80
 
set ruler                      " show the cursor position all the time
 
syntax on                      " turn on syntax
 
set nu                         " set line no when you open any file using vim
 
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/
highlight ExtraWhitespace ctermbg=red guibg=red    " highlight extra white space with red color in your vim file

************************************ 

some more command are below 
 
1 syntax on                       " turns syntax highlighting on
  2 colorscheme default             " defines the color scheme of the syntax highlighting
  3 
  4 set nocompatible                " (cp) use Vim defaults (much better)
  5 set ruler                       " (ru) show the cursor position at all times
  6 set showcmd                     " (sc) display an incomplete command in the lower right
  7 set history=50                  " (hi) keep 50 lines of command history
  8 set number                      " (nu) show line numbers
  9 set showmatch                   " (sm) briefly jump to matching bracket when inserting one
 10 set autoindent                  " (ai) turn on auto-indenting (great for programers)
 11 set copyindent                  " (ci) when auto-indenting, use the indenting format of the previous line
 12 set tabstop=4                   " (ts)1 syntax on                       " turns syntax highlighting on
  2 colorscheme default             " defines the color scheme of the syntax highlighting
  3 
  4 set nocompatible                " (cp) use Vim defaults (much better)
  5 set ruler                       " (ru) show the cursor position at all times
  6 set showcmd                     " (sc) display an incomplete command in the lower right
  7 set history=50                  " (hi) keep 50 lines of command history
  8 set number                      " (nu) show line numbers
  9 set showmatch                   " (sm) briefly jump to matching bracket when inserting one
 10 set autoindent                  " (ai) turn on auto-indenting (great for programers)
 11 set copyindent                  " (ci) when auto-indenting, use the indenting format of the previous line
 12 set tabstop=4                   " (ts) width (in spaces) that a <tab> is displayed as
 13 set shiftwidth=4                " (sw) width (in spaces) used in each step of autoindent (aswell as << and >>)
 14 "set smarttab                   " (sta) 'shiftwidth' used in front of a line, but 'tabstop' used otherwise
 15 set textwidth=80                " (tw) number of columns before an automatic line break is inserted (see formatoptions)
 16 set formatoptions=croq          " (fo) influences how vim automatically formats text
 17 set backspace=indent,eol,start  " (bs) allows backspacing beyond starting point of insert mode, indents and line breaks
 18 set nrformats+=alpha            " (nf) adds alpha chars to list that gets incremented/decremented with ^A/^X
 19 set listchars+=tab:>-           " (lcs) strings used in 'list' mode to show hidden characters (default=eol:$)
 20 set listchars+=trail:-
 21 set winminheight=0              " (wmh) the minimal height of the window when it's not the current window
 22 
 23 "set nowrap                     " allows text to continue off the window (need horizontal scrolling)
 24 set linebreak                   " (lbr) wrap long lines at a space instead of in the middle of a word
 25 set sidescroll=5                " (ss) the minimal number of columns to scroll horizontally
 26 set listchars+=precedes:<       " (lcs) when 'nowrap', character to indicate that line continues off the page
 27 set listchars+=extends:>
 28 
 29 set wrapscan                    " (ws) allows search to wrap to top of document when the bottom has been hit
 30 set incsearch                   " (is) highlights what you are searching for as you type
 31 set hlsearch                    " (hls) highlights all instances of the last searched string
 32 set ignorecase                  " (ic) ignores case in search patterns
 33 set smartcase                   " (scs) don't ignore case when the search pattern has uppercase
 34 set infercase                   " (inf) during keyword completion, fix case of new word (when ignore case is on)
 35 
 36 set foldcolumn=6                " (fdc) width of fold column (to see where folds are)
 37 set foldmethod=indent           " (fdm) creates a fold for every level of indentation
 38 set foldlevel=99                " (fdl) when file is opened, don't close any folds
 39 set foldenable                  " (fen) enables or disables folding
 40 
 41 "set backup                     " (bk) will create a backup before overwriting a file
 42 "set backupext=.bkup            " (bex) defines the extension used in a backup file (default is '~')
 43 
 44 let html_use_css = 1            " the ':%TOhtml' command generates html without <font> tags
 45 
 46 
 47 " File Specific Settings
 48 " ------------------------------------------------------------
 49 
 50 au FileType xhtml,html,htm,php,xml setlocal tabstop=2
 51 au FileType xhtml,html,htm,php,xml setlocal shiftwidth=2
 52 "au FileType xhtml,html,htm,php,xml setlocal expandtab      " (et) expand tabs to spaces (use :retab to redo entire file)
 53 au FileType xhtml,html,htm,php,xml setlocal softtabstop=2   " (sts) makes spaces feel like tabs (like deleting)
 54 
 55 au FileType c,h,java,js setlocal mps+==:;                   " allow the match pairs operation (%) to work with '=' and ';'
 56 
 57 au FileType c,h setlocal cindent                            " enable the intelligent cindent (cin) feature for the following files
 58 au FileType java,js setlocal smartindent                    " enable the smartindenting (si) feature for the following files
 59 
 60 au FileType txt setlocal fo+=tn
 61 
 62 " before writing to any file, this function call will remove any extra white space at the end of a line
 63 "au! BufWrite,FileWritePre * call RemoveWhiteSpace()
 64 
 65 
 66 
 67 
 68 
 69 " Abbreviations
 70 " ------------------------------------------------------------
 71 
 72 abbreviate #i #include
 73 abbreviate #d #define
 74 
 75 abbreviate <a <a href=""></a><left><left><left><left><left>
 76 abbreviate <i <img src="" /><left><left><left>
 77 abbreviate l" &ldquo;&rdquo;<left><left><left><left><left><left>
 78 abbreviate r" &rdquo;
 79 abbreviate l' &lsquo;
 80 abbreviate r' &rsquo;
 81 abbreviate "" &quot;&quot;<left><left><left><left><left>
 82 
 83 abbreviate <? <?php?><left><left>
 84 
 85 
 86 
 87 
 88 " Miscellaneous Settings
 89 " ------------------------------------------------------------
 90 
 91 " (dict) dictionary used for keyword completion
 92 " to use: while in insertion mode and in the middle of a word, type <ctrl-n> and <ctrl-p>
 93 set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
 94 set complete-=k complete+=k
 95 
 96 " (tsr) thesaurus used for keyword completion
 97 " to use: while in insertion mode and at the BEGINNING of a word, type <ctrl-x> then <ctrl-n>
 98 "set thesaurus-=/usr/share/dict/mobythes.aur thesaurus+=/usr/share/dict/mobythes.aur
 99 "set complete-=k complete+=k
100 
101 
102 
103 
104 
105 " Key Mappings
106 " ------------------------------------------------------------
107 
108 " allows moving between split windows much faster and more intuitive
109 map <C-J> <C-W>j<C-W>_
110 map <C-K> <C-W>k<C-W>_
111 
112 " <F2> applies a rot13 dmca-grade encryption scheme to your file
113 map <F2> mzggg?G`z      "(seems to be faster than mzggVGg?`z)
114 
115 " <F3> appends the current date and time after the cursor
116 map  <F3> a<C-R>=strftime("%c")<CR><Esc>
117 imap <F3>  <C-R>=strftime("%c")<CR>
118 
119 " <F6> sorts a paragraph of numbers using the external 'sort' program
120 map <F6> {V}k:!sort<CR>
121 
122 " <F7> toggles hidden characters
123 map  <F7> :set list!<CR>
124 imap <F7> <ESC>:set list!<CR>a
125 
126 " <F9> toggles word wrap
127 map  <F9> :set wrap!<CR>
128 imap <F9> <ESC>:set wrap!<CR>a
129 
130 " <F8> toggles whether the last searched string is highlighted
131 map  <F8> :set hls!<CR>
132 imap <F8> <ESC>:set hls!<CR>a
133 
137 
138 
139 
140 
141 
142 " Functions
143 " ------------------------------------------------------------
144 
145 " Renames param1 tags to be param2 tags
146 function! RenameTag(param1, param2)
147     :%s/<\(\/\?\)a:param1\(\_s*\)/<\1a:param2\2/gci
148 endfunction
149 
150 " Strips the tag defined by the parameter (for html pages)
151 function! StripTag(TagName)
152     :%s/a:TagName/hello/gci
153     ":% s/<[^>]\+>//gci
154 endfunction
155 
156 " Reverses all the lines in the file (top to bottom)
157 function! ReverseLines()
158     :g/^/m0
159 endfunction
160 
161 " Removes the ^M character from the end of every line
162 function! RemoveM()
163     :%s/^M$//g
164 endfunction
165 
166 " Replaces the ^M character with a carraige return native to the system
167 function! ReplaceM()
168     :%s/^M/\r/g
169 endfunction
170 
171 " Removes superfluous white space from the end of a line
172 function! RemoveWhiteSpace()
173     :%s/\s*$//g
174     :'^
175     "`.
176 endfunction
177 
178 
179 
180 
181 
182 " Command Reference
183 " ------------------------------------------------------------
184 
185 " *                     - searches for word under cursor
186 " gd                    - finds definition of variable/function under cursor
187 " ga                    - prints the ascii value of character under cursor
188 " gf                    - opens file under the cursor (in split view)
189 " gi                    - goes to insert mode in the same spot as you last inserted
190 " ~                     - changes case of character
191 " :r !<cmd>             - reads the output of the shell <cmd> into the file
192 " :% s/hello/A/gc       - typical search and replace command
193 
194 " :% !tidy              - runs the code through the 'tidy' program
195 
196 " :runtime! syntax/2html.vim
197 " :10,40TOhtml
198 
199 " command reference ->  " za : fold toggle  toggles between a fold being opened and closed (zA does it recursively)
200 "                       " zc : fold close   close 1 fold under the cursor (zC does it recursively)
201                         " zo : fold open    open 1 fold under the cursor (zO does it recursively)
202                         " zm : fold more    increases foldlevel by 1 (zM opens all folds)
203                         " zr : fold reduce  decreses foldlevel by 1 (zR closes all folds)
204 
205 " :retab                - when expandtab is set, replace all tabs in the file with the # of spaces defined in 'shiftwidth'
206 " :retab!               - when expandtab is not set, replace the number of spaces in 'shiftwidth' with a tab
207 if has("cscope")
208     set csprg=/usr/bin/cscope
209     set csto=0
210     set cst
211     set nocsverb
212     " add any database in current directory
213     if filereadable("cscope.out")
214         cs add cscope.out
215     " else add database pointed to by environment
216     elseif $CSCOPE_DB != ""
217         cs add $CSCOPE_DB
218     endif
219     set csverb
220 
221     "   's'   symbol: find all references to the token under cursor
222     "   'g'   global: find global definition(s) of the token under cursor
223     "   'c'   calls:  find all calls to the function name under cursor
224     "   't'   text:   find all instances of the text under cursor
225     "   'e'   egrep:  egrep search for the word under cursor
226     "   'f'   file:   open the filename under cursor
227     "   'i'   includes: find files that include the filename under cursor
228     "   'd'   called: find functions that function under cursor calls
229     nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
230     nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
231     nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
232     nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
233     nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
234     nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
235     nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
236     nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
237 endif
238  width (in spaces) that a <tab> is displayed as
 13 set shiftwidth=4                " (sw) width (in spaces) used in each step of autoindent (aswell as << and >>)
 14 "set smarttab                   " (sta) 'shiftwidth' used in front of a line, but 'tabstop' used otherwise
 15 set textwidth=80                " (tw) number of columns before an automatic line break is inserted (see formatoptions)
 16 set formatoptions=croq          " (fo) influences how vim automatically formats text
 17 set backspace=indent,eol,start  " (bs) allows backspacing beyond starting point of insert mode, indents and line breaks
 18 set nrformats+=alpha            " (nf) adds alpha chars to list that gets incremented/decremented with ^A/^X
 19 set listchars+=tab:>-           " (lcs) strings used in 'list' mode to show hidden characters (default=eol:$)
 20 set listchars+=trail:-
 21 set winminheight=0              " (wmh) the minimal height of the window when it's not the current window
 22 
 23 "set nowrap                     " allows text to continue off the window (need horizontal scrolling)
 24 set linebreak                   " (lbr) wrap long lines at a space instead of in the middle of a word
 25 set sidescroll=5                " (ss) the minimal number of columns to scroll horizontally
 26 set listchars+=precedes:<       " (lcs) when 'nowrap', character to indicate that line continues off the page
 27 set listchars+=extends:>
 28 
 29 set wrapscan                    " (ws) allows search to wrap to top of document when the bottom has been hit
 30 set incsearch                   " (is) highlights what you are searching for as you type
 31 set hlsearch                    " (hls) highlights all instances of the last searched string
 32 set ignorecase                  " (ic) ignores case in search patterns
 33 set smartcase                   " (scs) don't ignore case when the search pattern has uppercase
 34 set infercase                   " (inf) during keyword completion, fix case of new word (when ignore case is on)
 35 
 36 set foldcolumn=6                " (fdc) width of fold column (to see where folds are)
 37 set foldmethod=indent           " (fdm) creates a fold for every level of indentation
 38 set foldlevel=99                " (fdl) when file is opened, don't close any folds
 39 set foldenable                  " (fen) enables or disables folding
 40 
 41 "set backup                     " (bk) will create a backup before overwriting a file
 42 "set backupext=.bkup            " (bex) defines the extension used in a backup file (default is '~')
 43 
 44 let html_use_css = 1            " the ':%TOhtml' command generates html without <font> tags
 45 
 46 
 47 " File Specific Settings
 48 " ------------------------------------------------------------
 49 
 50 au FileType xhtml,html,htm,php,xml setlocal tabstop=2
 51 au FileType xhtml,html,htm,php,xml setlocal shiftwidth=2
 52 "au FileType xhtml,html,htm,php,xml se1 syntax on                       " turns syntax highlighting on
  2 colorscheme default             " defines the color scheme of the syntax highlighting
  3 
  4 set nocompatible                " (cp) use Vim defaults (much better)
  5 set ruler                       " (ru) show the cursor position at all times
  6 set showcmd                     " (sc) display an incomplete command in the lower right
  7 set history=50                  " (hi) keep 50 lines of command history
  8 set number                      " (nu) show line numbers
  9 set showmatch                   " (sm) briefly jump to matching bracket when inserting one
 10 set autoindent                  " (ai) turn on auto-indenting (great for programers)
 11 set copyindent                  " (ci) when auto-indenting, use the indenting format of the previous line
 12 set tabstop=4                   " (ts) width (in spaces) that a <tab> is displayed as
 13 set shiftwidth=4                " (sw) width (in spaces) used in each step of autoindent (aswell as << and >>)
 14 "set smarttab                   " (sta) 'shiftwidth' used in front of a line, but 'tabstop' used otherwise
 15 set textwidth=80                " (tw) number of columns before an automatic line break is inserted (see formatoptions)
 16 set formatoptions=croq          " (fo) influences how vim automatically formats text
 17 set backspace=indent,eol,start  " (bs) allows backspacing beyond starting point of insert mode, indents and line breaks
 18 set nrformats+=alpha            " (nf) adds alpha chars to list that gets incremented/decremented with ^A/^X
 19 set listchars+=tab:>-           " (lcs) strings used in 'list' mode to show hidden characters (default=eol:$)
 20 set listchars+=trail:-
 21 set winminheight=0              " (wmh) the minimal height of the window when it's not the current window
 22 
 23 "set nowrap                     " allows text to continue off the window (need horizontal scrolling)
 24 set linebreak                   " (lbr) wrap long lines at a space instead of in the middle of a word
 25 set sidescroll=5                " (ss) the minimal number of columns to scroll horizontally
 26 set listchars+=precedes:<       " (lcs) when 'nowrap', character to indicate that line continues off the page
 27 set listchars+=extends:>
 28 
 29 set wrapscan                    " (ws) allows search to wrap to top of document when the bottom has been hit
 30 set incsearch                   " (is) highlights what you are searching for as you type
 31 set hlsearch                    " (hls) highlights all instances of the last searched string
 32 set ignorecase                  " (ic) ignores case in search patterns
 33 set smartcase                   " (scs) don't ignore case when the search pattern has uppercase
 34 set infercase                   " (inf) during keyword completion, fix case of new word (when ignore case is on)
 35 
 36 set foldcolumn=6                " (fdc) width of fold column (to see where folds are)
 37 set foldmethod=indent           " (fdm) creates a fold for every level of indentation
 38 set foldlevel=99                " (fdl) when file is opened, don't close any folds
 39 set foldenable                  " (fen) enables or disables folding
 40 
 41 "set backup                     " (bk) will create a backup before overwriting a file
 42 "set backupext=.bkup            " (bex) defines the extension used in a backup file (default is '~')
 43 
 44 let html_use_css = 1            " the ':%TOhtml' command generates html without <font> tags
 45 
 46 
 47 " File Specific Settings
 48 " ------------------------------------------------------------
 49 
 50 au FileType xhtml,html,htm,php,xml setlocal tabstop=2
 51 au FileType xhtml,html,htm,php,xml setlocal shiftwidth=2
 52 "au FileType xhtml,html,htm,php,xml setlocal expandtab      " (et) expand tabs to spaces (use :retab to redo entire file)
 53 au FileType xhtml,html,htm,php,xml setlocal softtabstop=2   " (sts) makes spaces feel like tabs (like deleting)
 54 
 55 au FileType c,h,java,js setlocal mps+==:;                   " allow the match pairs operation (%) to work with '=' and ';'
 56 
 57 au FileType c,h setlocal cindent                            " enable the intelligent cindent (cin) feature for the following files
 58 au FileType java,js setlocal smartindent                    " enable the smartindenting (si) feature for the following files
 59 
 60 au FileType txt setlocal fo+=tn
 61 
 62 " before writing to any file, this function call will remove any extra white space at the end of a line
 63 "au! BufWrite,FileWritePre * call RemoveWhiteSpace()
 64 
 65 
 66 
 67 
 68 
 69 " Abbreviations
 70 " ------------------------------------------------------------
 71 
 72 abbreviate #i #include
 73 abbreviate #d #define
 74 
 75 abbreviate <a <a href=""></a><left><left><left><left><left>
 76 abbreviate <i <img src="" /><left><left><left>
 77 abbreviate l" &ldquo;&rdquo;<left><left><left><left><left><left>
 78 abbreviate r" &rdquo;
 79 abbreviate l' &lsquo;
 80 abbreviate r' &rsquo;
 81 abbreviate "" &quot;&quot;<left><left><left><left><left>
 82 
 83 abbreviate <? <?php?><left><left>
 84 
 85 
 86 
 87 
 88 " Miscellaneous Settings
 89 " ------------------------------------------------------------
 90 
 91 " (dict) dictionary used for keyword completion
 92 " to use: while in insertion mode and in the middle of a word, type <ctrl-n> and <ctrl-p>
 93 set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
 94 set complete-=k complete+=k
 95 
 96 " (tsr) thesaurus used for keyword completion
 97 " to use: while in insertion mode and at the BEGINNING of a word, type <ctrl-x> then <ctrl-n>
 98 "set thesaurus-=/usr/share/dict/mobythes.aur thesaurus+=/usr/share/dict/mobythes.aur
 99 "set complete-=k complete+=k
100 
101 
102 
103 
104 
105 " Key Mappings
106 " ------------------------------------------------------------
107 
108 " allows moving between split windows much faster and more intuitive
109 map <C-J> <C-W>j<C-W>_
110 map <C-K> <C-W>k<C-W>_
111 
112 " <F2> applies a rot13 dmca-grade encryption scheme to your file
113 map <F2> mzggg?G`z      "(seems to be faster than mzggVGg?`z)
114 
115 " <F3> appends the current date and time after the cursor
116 map  <F3> a<C-R>=strftime("%c")<CR><Esc>
117 imap <F3>  <C-R>=strftime("%c")<CR>
118 
119 " <F6> sorts a paragraph of numbers using the external 'sort' program
120 map <F6> {V}k:!sort<CR>
121 
122 " <F7> toggles hidden characters
123 map  <F7> :set list!<CR>
124 imap <F7> <ESC>:set list!<CR>a
125 
126 " <F9> toggles word wrap
127 map  <F9> :set wrap!<CR>
128 imap <F9> <ESC>:set wrap!<CR>a
129 
130 " <F8> toggles whether the last searched string is highlighted
131 map  <F8> :set hls!<CR>
132 imap <F8> <ESC>:set hls!<CR>a
133 
137 
138 
139 
140 
141 
142 " Functions
143 " ------------------------------------------------------------
144 
145 " Renames param1 tags to be param2 tags
146 function! RenameTag(param1, param2)
147     :%s/<\(\/\?\)a:param1\(\_s*\)/<\1a:param2\2/gci
148 endfunction
149 
150 " Strips the tag defined by the parameter (for html pages)
151 function! StripTag(TagName)
152     :%s/a:TagName/hello/gci
153     ":% s/<[^>]\+>//gci
154 endfunction
155 
156 " Reverses all the lines in the file (top to bottom)
157 function! ReverseLines()
158     :g/^/m0
159 endfunction
160 
161 " Removes the ^M character from the end of every line
162 function! RemoveM()
163     :%s/^M$//g
164 endfunction
165 
166 " Replaces the ^M character with a carraige return native to the system
167 function! ReplaceM()
168     :%s/^M/\r/g
169 endfunction
170 
171 " Removes superfluous white space from the end of a line
172 function! RemoveWhiteSpace()
173     :%s/\s*$//g
174     :'^
175     "`.
176 endfunction
177 
178 
179 
180 
181 
182 " Command Reference
183 " ------------------------------------------------------------
184 
185 " *                     - searches for word under cursor
186 " gd                    - finds definition of variable/function under cursor
187 " ga                    - prints the ascii value of character under cursor
188 " gf                    - opens file under the cursor (in split view)
189 " gi                    - goes to insert mode in the same spot as you last inserted
190 " ~                     - changes case of character
191 " :r !<cmd>             - reads the output of the shell <cmd> into the file
192 " :% s/hello/A/gc       - typical search and replace command
193 
194 " :% !tidy              - runs the code through the 'tidy' program
195 
196 " :runtime! syntax/2html.vim
197 " :10,40TOhtml
198 
199 " command reference ->  " za : fold toggle  toggles between a fold being opened and closed (zA does it recursively)
200 "                       " zc : fold close   close 1 fold under the cursor (zC does it recursively)
201                         " zo : fold open    open 1 fold under the cursor (zO does it recursively)
202                         " zm : fold more    increases foldlevel by 1 (zM opens all folds)
203                         " zr : fold reduce  decreses foldlevel by 1 (zR closes all folds)
204 
205 " :retab                - when expandtab is set, replace all tabs in the file with the # of spaces defined in 'shiftwidth'
206 " :retab!               - when expandtab is not set, replace the number of spaces in 'shiftwidth' with a tab
207 if has("cscope")
208     set csprg=/usr/bin/cscope
209     set csto=0
210     set cst
211     set nocsverb
212     " add any database in current directory
213     if filereadable("cscope.out")
214         cs add cscope.out
215     " else add database pointed to by environment
216     elseif $CSCOPE_DB != ""
217         cs add $CSCOPE_DB
218     endif
219     set csverb
220 
221     "   's'   symbol: find all references to the token under cursor
222     "   'g'   global: find global definition(s) of the token under cursor
223     "   'c'   calls:  find all calls to the function name under cursor
224     "   't'   text:   find all instances of the text under cursor
225     "   'e'   egrep:  egrep search for the word under cursor
226     "   'f'   file:   open the filename under cursor
227     "   'i'   includes: find files that include the filename under cursor
228     "   'd'   called: find functions that function under cursor calls
229     nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
230     nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
231     nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
232     nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
233     nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
234     nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
235     nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
236     nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
237 endif
238 tlocal expandtab      " (et) expand tabs to spaces (use :retab to redo entire file)
 53 au FileType xhtml,html,htm,php,xml setlocal softtabstop=2   " (sts) makes spaces feel like tabs (like deleting)
 54 
 55 au FileType c,h,java,js setlocal mps+==:;                   " allow the match pairs operation (%) to work with '=' and ';'
 56 
 57 au FileType c,h setlocal cindent                            " enable the intelligent cindent (cin) feature for the following files
 58 au FileType java,js setlocal smartindent                    " enable the smartindenting (si) feature for the following files
 59 
 60 au FileType txt setlocal fo+=tn
 61 
 62 " before writing to any file, this function call will remove any extra white space at the end of a line
 63 "au! BufWrite,FileWritePre * call RemoveWhiteSpace()
 64 
 65 
 66 
 67 
 68 
 69 " Abbreviations
 70 " ------------------------------------------------------------
 71 
 72 abbreviate #i #include
 73 abbreviate #d #define
 74 
 75 abbreviate <a <a href=""></a><left><left><left><left><left>
 76 abbreviate <i <img src="" /><left><left><left>
 77 abbreviate l" &ldquo;&rdquo;<left><left><left><left><left><left>
 78 abbreviate r" &rdquo;
 79 abbreviate l' &lsquo;
 80 abbreviate r' &rsquo;
 81 abbreviate "" &quot;&quot;<left><left><left><left><left>
 82 
 83 abbreviate <? <?php?><left><left>
 84 
 85 
 86 
 87 
 88 " Miscellaneous Settings
 89 " ------------------------------------------------------------
 90 
 91 " (dict) dictionary used for keyword completion
 92 " to use: while in insertion mode and in the middle of a word, type <ctrl-n> and <ctrl-p>
 93 set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
 94 set complete-=k complete+=k
 95 
 96 " (tsr) thesaurus used for keyword completion
 97 " to use: while in insertion mode and at the BEGINNING of a word, type <ctrl-x> then <ctrl-n>
 98 "set thesaurus-=/usr/share/dict/mobythes.aur thesaurus+=/usr/share/dict/mobythes.aur
 99 "set complete-=k complete+=k
100 
101 
102 
103 
104 
105 " Key Mappings
106 " ------------------------------------------------------------
107 
108 " allows moving between split windows much faster and more intuitive
109 map <C-J> <C-W>j<C-W>_
110 map <C-K> <C-W>k<C-W>_
111 
112 " <F2> applies a rot13 dmca-grade encryption scheme to your file
113 map <F2> mzggg?G`z      "(seems to be faster than mzggVGg?`z)
114 
115 " <F3> appends the current date and time after the cursor
116 map  <F3> a<C-R>=strftime("%c")<CR><Esc>
117 imap <F3>  <C-R>=strftime("%c")<CR>
118 
119 " <F6> sorts a paragraph of numbers using the external 'sort' program
120 map <F6> {V}k:!sort<CR>
121 
122 " <F7> toggles hidden characters
123 map  <F7> :set list!<CR>
124 imap <F7> <ESC>:set list!<CR>a
125 
126 " <F9> toggles word wrap
127 map  <F9> :set wrap!<CR>
128 imap <F9> <ESC>:set wrap!<CR>a
129 
130 " <F8> toggles whether the last searched string is highlighted
131 map  <F8> :set hls!<CR>
132 imap <F8> <ESC>:set hls!<CR>a
133 
137 
138 
139 
140 
141 
142 " Functions
143 " ------------------------------------------------------------
144 
145 " Renames param1 tags to be param2 tags
146 function! RenameTag(param1, param2)
147     :%s/<\(\/\?\)a:param1\(\_s*\)/<\1a:param2\2/gci
148 endfunction
149 
150 " Strips the tag defined by the parameter (for html pages)
151 function! StripTag(TagName)
152     :%s/a:TagName/hello/gci
153     ":% s/<[^>]\+>//gci
154 endfunction
155 
156 " Reverses all the lines in the file (top to bottom)
157 function! ReverseLines()
158     :g/^/m0
159 endfunction
160 
161 " Removes the ^M character from the end of every line
162 function! RemoveM()
163     :%s/^M$//g
164 endfunction
165 
166 " Replaces the ^M character with a carraige return native to the system
167 function! ReplaceM()
168     :%s/^M/\r/g
169 endfunction
170 
171 " Removes superfluous white space from the end of a line
172 function! RemoveWhiteSpace()
173     :%s/\s*$//g
174     :'^
175     "`.
176 endfunction
177 
178 
179 
180 
181 
182 " Command Reference
183 " ------------------------------------------------------------
184 
185 " *                     - searches for word under cursor
186 " gd                    - finds definition of variable/function under cursor
187 " ga                    - prints the ascii value of character under cursor
188 " gf                    - opens file under the cursor (in split view)
189 " gi                    - goes to insert mode in the same spot as you last inserted
190 " ~                     - changes case of character
191 " :r !<cmd>             - reads the output of the shell <cmd> into the file
192 " :% s/hello/A/gc       - typical search and replace command
193 
194 " :% !tidy              - runs the code through the 'tidy' program
195 
196 " :runtime! syntax/2html.vim
197 " :10,40TOhtml
198 
199 " command reference ->  " za : fold toggle  toggles between a fold being opened and closed (zA does it recursively)
200 "                       " zc : fold close   close 1 fold under the cursor (zC does it recursively)
201                         " zo : fold open    open 1 fold under the cursor (zO does it recursively)
202                         " zm : fold more    increases foldlevel by 1 (zM opens all folds)
203                         " zr : fold reduce  decreses foldlevel by 1 (zR closes all folds)
204 
205 " :retab                - when expandtab is set, replace all tabs in the file with the # of spaces defined in 'shiftwidth'
206 " :retab!               - when expandtab is not set, replace the number of spaces in 'shiftwidth' with a tab
207 if has("cscope")
208     set csprg=/usr/bin/cscope
209     set csto=0
210     set cst
211     set nocsverb
212     " add any database in current directory
213     if filereadable("cscope.out")
214         cs add cscope.out
215     " else add database pointed to by environment
216     elseif $CSCOPE_DB != ""
217         cs add $CSCOPE_DB
218     endif
219     set csverb
220 
221     "   's'   symbol: find all references to the token under cursor
222     "   'g'   global: find global definition(s) of the token under cursor
223     "   'c'   calls:  find all calls to the function name under cursor
224     "   't'   text:   find all instances of the text under cursor
225     "   'e'   egrep:  egrep search for the word under cursor
226     "   'f'   file:   open the filename under cursor
227     "   'i'   includes: find files that include the filename under cursor
228     "   'd'   called: find functions that function under cursor calls
229     nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
230     nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
231     nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
232     nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
233     nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
234     nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
235     nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
236     nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
237 endif
238