Advertisement
Guest User

mfukar

a guest
Oct 22nd, 2009
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.23 KB | None | 0 0
  1. " .vimrc
  2. "
  3. " mfukar's .vimrc
  4. "
  5. " 2009 Jun 16
  6. "
  7. " This vimrc is divided into these sections:
  8. "
  9. " * Terminal Settings
  10. " * User Interface
  11. " * Text Formatting -- General
  12. " * Text Formatting -- Specific File Formats
  13. " * Search & Replace
  14. " * Spelling
  15. " * Keystrokes -- Moving Around
  16. " * Keystrokes -- Formatting
  17. " * Keystrokes -- Toggles
  18. " * Keystrokes -- Insert Mode
  19. " * Keystrokes -- For HTML Files
  20. " * `SLRN' Behaviour
  21. " * Functions Referred to Above
  22. " * Automatic Code Completion
  23. "
  24. " This file contains no control codes and no `top bit set' characters above the
  25. " normal Ascii range, and all lines contain a maximum of 89 characters. With a
  26. " bit of luck, this should make it resilient to being uploaded, downloaded,
  27. " e-mailed, posted, encoded, decoded, transmitted by morse code, or whatever.
  28.  
  29.  
  30. " first clear any existing autocommands:
  31. autocmd!
  32.  
  33.  
  34. " * Terminal Settings
  35.  
  36. " `XTerm', `RXVT', `Gnome Terminal', and `Konsole' all claim to be "xterm";
  37. " `KVT' claims to be "xterm-color":
  38. if &term =~ 'xterm'
  39.  
  40. " `Gnome Terminal' fortunately sets $COLORTERM; it needs <BkSpc> and <Del>
  41. " fixing, and it has a bug which causes spurious "c"s to appear, which can be
  42. " fixed by unsetting t_RV:
  43. "if $COLORTERM == 'gnome-terminal'
  44. "execute 'set t_kb=' . nr2char(8)
  45. " [Char 8 is <Ctrl>+H.]
  46. "fixdel
  47. "set t_RV=
  48.  
  49. " `XTerm', `Konsole', and `KVT' all also need <BkSpc> and <Del> fixing;
  50. " there's no easy way of distinguishing these terminals from other things
  51. " that claim to be "xterm", but `RXVT' sets $COLORTERM to "rxvt" and these
  52. " don't:
  53. if $COLORTERM == ''
  54. execute 'set t_kb=' . nr2char(8)
  55. fixdel
  56.  
  57. " The above won't work if an `XTerm' or `KVT' is started from within a `Gnome
  58. " Terminal' or an `RXVT': the $COLORTERM setting will propagate; it's always
  59. " OK with `Konsole' which explicitly sets $COLORTERM to "".
  60.  
  61. endif
  62. endif
  63.  
  64.  
  65. " * User Interface
  66.  
  67. " Easy Tag List plugin on/off switching.
  68. "function! TagListToggle()
  69. " silent execute ":TlistToggle"
  70. "endfunction
  71. "command! -complete=command TLT call TagListToggle()
  72.  
  73. " Added tags for quickly jumping around C, Python code.
  74. set tags+=$HOME/.vim/tags/c.ctags
  75. set tags+=$HOME/.vim/tags/python.ctags
  76.  
  77. " have syntax highlighting in terminals which can display colours:
  78. if has('syntax') && (&t_Co > 2)
  79. syntax on
  80. endif
  81.  
  82. " have fifty lines of command-line (etc) history:
  83. set history=50
  84. " remember all of these between sessions, but only 10 search terms; also
  85. " remember info for 10 files, but never any on removable disks, don't remember
  86. " marks in files, don't rehighlight old search patterns, and only save up to
  87. " 100 lines of registers; including @10 in there should restrict input buffer
  88. " but it causes an error for me:
  89. set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
  90.  
  91. " have command-line completion <Tab> (for filenames, help topics, option names)
  92. " first list the available options and complete the longest common part, then
  93. " have further <Tab>s cycle through the possibilities:
  94. set wildmode=list:longest,full
  95.  
  96. " use "[RO]" for "[readonly]" to save space in the message line:
  97. set shortmess+=r
  98.  
  99. " display the current mode and partially-typed commands in the status line:
  100. set showmode
  101. set showcmd
  102.  
  103. " when using list, keep tabs at their full width and display `arrows':
  104. execute 'set listchars+=tab:' . nr2char(187) . nr2char(183)
  105. " (Character 187 is a right double-chevron, and 183 a mid-dot.)
  106.  
  107. " have the mouse enabled all the time:
  108. set mouse=a
  109.  
  110. " don't have files trying to override this .vimrc:
  111. set nomodeline
  112.  
  113.  
  114. " * Text Formatting -- General
  115.  
  116. " don't make it look like there are line breaks where there aren't:
  117. set nowrap
  118.  
  119. " use line numbering
  120. set nu
  121.  
  122. " use tabs, and have them copied down lines:
  123. " set shiftwidth=8
  124. " set shiftround
  125. " set expandtab
  126. set autoindent
  127.  
  128. " normally don't automatically format `text' as it is typed, IE only do this
  129. " with comments, at 89 characters:
  130. set formatoptions-=t
  131. set textwidth=89
  132.  
  133. " treat lines starting with a quote mark as comments (for `Vim' files, such as
  134. " this very one!), and colons as well so that reformatting usenet messages from
  135. " `Tin' users works OK:
  136. set comments+=b:\"
  137. set comments+=n::
  138.  
  139.  
  140. " * Text Formatting -- Specific File Formats
  141.  
  142. " enable filetype detection:
  143. filetype on
  144.  
  145. " recognize anything in my .Postponed directory as a news article, and anything
  146. " at all with a .txt extension as being human-language text [this clobbers the
  147. " `help' filetype, but that doesn't seem to prevent help from working
  148. " properly]:
  149. augroup filetype
  150. autocmd BufNewFile,BufRead */.Postponed/* set filetype=mail
  151. autocmd BufNewFile,BufRead *.txt set filetype=human
  152. augroup END
  153.  
  154. " in human-language files, automatically format everything at 72 chars:
  155. autocmd FileType mail,human set formatoptions+=t textwidth=72
  156.  
  157. " for C-like programming, have automatic indentation:
  158. autocmd FileType c,cpp,slang set cindent
  159.  
  160. " for actual C (not C++) programming where comments have explicit end
  161. " characters, if starting a new line in the middle of a comment automatically
  162. " insert the comment leader characters:
  163. autocmd FileType c set formatoptions+=ro
  164.  
  165. " for Perl programming, have things in braces indenting themselves:
  166. autocmd FileType perl set smartindent
  167.  
  168. " for CSS, also have things in braces indented:
  169. autocmd FileType css set smartindent
  170.  
  171. " for HTML, generally format text, but if a long line has been created leave it
  172. " alone when editing:
  173. autocmd FileType html set formatoptions+=tl
  174.  
  175. " for both CSS and HTML, use genuine tab characters for indentation, to make
  176. " files a few bytes smaller:
  177. autocmd FileType html,css set noexpandtab tabstop=2
  178.  
  179. " in makefiles, don't expand tabs to spaces, since actual tab characters are
  180. " needed, and have indentation at 8 chars to be sure that all indents are tabs
  181. " (despite the mappings later):
  182. autocmd FileType make set noexpandtab shiftwidth=8
  183.  
  184.  
  185. " * Search & Replace
  186.  
  187. " make searches case-insensitive, unless they contain upper-case letters:
  188. set ignorecase
  189. set smartcase
  190.  
  191. " show the `best match so far' as search strings are typed:
  192. set incsearch
  193.  
  194. " assume the /g flag on :s substitutions to replace all matches in a line:
  195. set gdefault
  196.  
  197.  
  198. " * Spelling
  199.  
  200. " define `Ispell' language and personal dictionary, used in several places
  201. " below:
  202. let IspellLang = 'british'
  203. let PersonalDict = '~/.ispell_' . IspellLang
  204.  
  205. " try to avoid misspelling words in the first place -- have the insert mode
  206. " <Ctrl>+N/<Ctrl>+P keys perform completion on partially-typed words by
  207. " checking the Linux word list and the personal `Ispell' dictionary; sort out
  208. " case sensibly (so that words at starts of sentences can still be completed
  209. " with words that are in the dictionary all in lower case):
  210. execute 'set dictionary+=' . PersonalDict
  211. set dictionary+=/usr/dict/words
  212. set complete=.,w,k
  213. set infercase
  214.  
  215. " correct my common typos without me even noticing them:
  216. abbreviate teh the
  217. abbreviate spolier spoiler
  218. abbreviate Comny Conmy
  219. abbreviate atmoic atomic
  220.  
  221. " Spell checking operations are defined next. They are all set to normal mode
  222. " keystrokes beginning \s but function keys are also mapped to the most common
  223. " ones. The functions referred to are defined at the end of this .vimrc.
  224.  
  225. " \si ("spelling interactive") saves the current file then spell checks it
  226. " interactively through `Ispell' and reloads the corrected version:
  227. execute 'nnoremap \si :w<CR>:!ispell -x -d ' . IspellLang . ' %<CR>:e<CR><CR>'
  228.  
  229. " \sl ("spelling list") lists all spelling mistakes in the current buffer,
  230. " but excludes any in news/mail headers or in ("> ") quoted text:
  231. execute 'nnoremap \sl :w ! grep -v "^>" <Bar> grep -E -v "^[[:alpha:]-]+: " ' .
  232. \ '<Bar> ispell -l -d ' . IspellLang . ' <Bar> sort <Bar> uniq<CR>'
  233.  
  234. " \sh ("spelling highlight") highlights (in red) all misspelt words in the
  235. " current buffer, and also excluding the possessive forms of any valid words
  236. " (EG "Lizzy's" won't be highlighted if "Lizzy" is in the dictionary); with
  237. " mail and news messages it ignores headers and quoted text; for HTML it
  238. " ignores tags and only checks words that will appear, and turns off other
  239. " syntax highlighting to make the errors more apparent [function at end of
  240. " file]:
  241. nnoremap \sh :call HighlightSpellingErrors()<CR><CR>
  242. nmap <F9> \sh
  243.  
  244. " \sc ("spelling clear") clears all highlighted misspellings; for HTML it
  245. " restores regular syntax highlighting:
  246. nnoremap \sc :if &ft == 'html' <Bar> sy on <Bar>
  247. \ else <Bar> :sy clear SpellError <Bar> endif<CR>
  248. nmap <F10> \sc
  249.  
  250. " \sa ("spelling add") adds the word at the cursor position to the personal
  251. " dictionary (but for possessives adds the base word, so that when the cursor
  252. " is on "Ceri's" only "Ceri" gets added to the dictionary), and stops
  253. " highlighting that word as an error (if appropriate) [function at end of
  254. " file]:
  255. nnoremap \sa :call AddWordToDictionary()<CR><CR>
  256. nmap <F8> \sa
  257.  
  258.  
  259. " * Keystrokes -- Moving Around
  260.  
  261. " have the h and l cursor keys wrap between lines (like <Space> and <BkSpc> do
  262. " by default), and ~ covert case over line breaks; also have the cursor keys
  263. " wrap in insert mode:
  264. set whichwrap=h,l,~,[,]
  265.  
  266. " page down with <Space> (like in `Lynx', `Mutt', `Pine', `Netscape Navigator',
  267. " `SLRN', `Less', and `More'); page up with - (like in `Lynx', `Mutt', `Pine'),
  268. " or <BkSpc> (like in `Netscape Navigator'):
  269. noremap <Space> <PageDown>
  270. noremap <BS> <PageUp>
  271. noremap - <PageUp>
  272. " [<Space> by default is like l, <BkSpc> like h, and - like k.]
  273.  
  274. " scroll the window (but leaving the cursor in the same place) by a couple of
  275. " lines up/down with <Ins>/<Del> (like in `Lynx'):
  276. noremap <Ins> 2<C-Y>
  277. noremap <Del> 2<C-E>
  278. " [<Ins> by default is like i, and <Del> like x.]
  279.  
  280. " use <F6> to cycle through split windows (and <Shift>+<F6> to cycle backwards,
  281. " where possible):
  282. nnoremap <F6> <C-W>w
  283. nnoremap <S-F6> <C-W>W
  284.  
  285. " use <Ctrl>+N/<Ctrl>+P to cycle through files:
  286. nnoremap <C-N> :next<CR>
  287. nnoremap <C-P> :prev<CR>
  288. " [<Ctrl>+N by default is like j, and <Ctrl>+P like k.]
  289.  
  290. " have % bounce between angled brackets, as well as t'other kinds:
  291. set matchpairs+=<:>
  292.  
  293. " have <F1> prompt for a help topic, rather than displaying the introduction
  294. " page, and have it do this from any mode:
  295. nnoremap <F1> :help<Space>
  296. vmap <F1> <C-C><F1>
  297. omap <F1> <C-C><F1>
  298. map! <F1> <C-C><F1>
  299.  
  300.  
  301. " * Keystrokes -- Formatting
  302.  
  303. " have Q reformat the current paragraph (or selected text if there is any):
  304. nnoremap Q gqap
  305. vnoremap Q gq
  306.  
  307. " have the usual indentation keystrokes still work in visual mode:
  308. vnoremap <C-T> >
  309. vnoremap <C-D> <LT>
  310. vmap <Tab> <C-T>
  311. vmap <S-Tab> <C-D>
  312.  
  313. " have Y behave analogously to D and C rather than to dd and cc (which is
  314. " already done by yy):
  315. noremap Y y$
  316.  
  317.  
  318. " * Keystrokes -- Toggles
  319.  
  320. " Keystrokes to toggle options are defined here. They are all set to normal
  321. " mode keystrokes beginning \t but some function keys (which won't work in all
  322. " terminals) are also mapped.
  323.  
  324. " have \tp ("toggle paste") toggle paste on/off and report the change, and
  325. " where possible also have <F4> do this both in normal and insert mode:
  326. nnoremap \tp :set invpaste paste?<CR>
  327. nmap <F4> \tp
  328. imap <F4> <C-O>\tp
  329. set pastetoggle=<F4>
  330.  
  331. " have \tf ("toggle format") toggle the automatic insertion of line breaks
  332. " during typing and report the change:
  333. nnoremap \tf :if &fo =~ 't' <Bar> set fo-=t <Bar> else <Bar> set fo+=t <Bar>
  334. \ endif <Bar> set fo?<CR>
  335. nmap <F3> \tf
  336. imap <F3> <C-O>\tf
  337.  
  338. " have \tl ("toggle list") toggle list on/off and report the change:
  339. nnoremap \tl :set invlist list?<CR>
  340. nmap <F2> \tl
  341.  
  342. " have \th ("toggle highlight") toggle highlighting of search matches, and
  343. " report the change:
  344. nnoremap \th :set invhls hls?<CR>
  345.  
  346.  
  347. " * Keystrokes -- Insert Mode
  348.  
  349. " allow <BkSpc> to delete line breaks, beyond the start of the current
  350. " insertion, and over indentations:
  351. set backspace=eol,start,indent
  352.  
  353. " have <Tab> (and <Shift>+<Tab> where it works) change the level of
  354. " indentation:
  355. inoremap <Tab> <C-T>
  356. inoremap <S-Tab> <C-D>
  357. " [<Ctrl>+V <Tab> still inserts an actual tab character.]
  358.  
  359. " abbreviations:
  360. iabbrev lorem Loremipsumdolorsitamet,consecteturadipisicingelit,seddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua.Utenimadminimveniam,quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproident,suntinculpaquiofficiadeseruntmollitanimidestlaborum.
  361. iabbrev hse he/she
  362. iabbrev mf mfukar
  363.  
  364.  
  365. " * Keystrokes -- For HTML Files
  366.  
  367. " Some automatic HTML tag insertion operations are defined next. They are
  368. " allset to normal mode keystrokes beginning \h. Insert mode function keys are
  369. " also defined, for terminals where they work. The functions referred to are
  370. " defined at the end of this .vimrc.
  371.  
  372. " \hc ("HTML close") inserts the tag needed to close the current HTML construct
  373. " [function at end of file]:
  374. nnoremap \hc :call InsertCloseTag()<CR>
  375. imap <F8> <Space><BS><Esc>\hca
  376.  
  377. " \hp ("HTML previous") copies the previous (non-closing) HTML tag in full,
  378. " including attributes; repeating this straight away removes that tag and
  379. " copies the one before it [function at end of file]:
  380. nnoremap \hp :call RepeatTag(0)<CR>
  381. imap <F9> <Space><BS><Esc>\hpa
  382. " \hn ("HTML next") does the same thing, but copies the next tag; so \hp and
  383. " \hn can be used to cycle backwards and forwards through the tags in the file
  384. " (like <Ctrl>+P and <Ctrl>+N do for insert mode completion):
  385. nnoremap \hn :call RepeatTag(1)<CR>
  386. imap <F10> <Space><BS><Esc>\hna
  387.  
  388. " there are other key mappings that it's useful to have for typing HTML
  389. " character codes, but that are definitely not wanted in other files (unlike
  390. " the above, which won't do any harm), so only map these when entering an HTML
  391. " file and unmap them on leaving it:
  392. autocmd BufEnter * if &filetype == "html" | call MapHTMLKeys() | endif
  393. function! MapHTMLKeys(...)
  394. " sets up various insert mode key mappings suitable for typing HTML, and
  395. " automatically removes them when switching to a non-HTML buffer
  396.  
  397. " if no parameter, or a non-zero parameter, set up the mappings:
  398. if a:0 == 0 || a:1 != 0
  399.  
  400. " require two backslashes to get one:
  401. inoremap \\ \
  402.  
  403. " then use backslash followed by various symbols insert HTML characters:
  404. inoremap \& &amp;
  405. inoremap \< &lt;
  406. inoremap \> &gt;
  407. inoremap \. &middot;
  408.  
  409. " em dash -- have \- always insert an em dash, and also have _ do it if
  410. " ever typed as a word on its own, but not in the middle of other words:
  411. inoremap \- &#8212;
  412. iabbrev _ &#8212;
  413.  
  414. " hard space with <Ctrl>+Space, and \<Space> for when that doesn't work:
  415. inoremap \<Space> &nbsp;
  416. imap <C-Space> \<Space>
  417.  
  418. " have the normal open and close single quote keys producing the character
  419. " codes that will produce nice curved quotes (and apostophes) on both Unix
  420. " and Windows:
  421. inoremap ` &#8216;
  422. inoremap ' &#8217;
  423. " then provide the original functionality with preceding backslashes:
  424. inoremap \` `
  425. inoremap \' '
  426.  
  427. " curved double open and closed quotes (2 and " are the same key for me):
  428. inoremap \2 &#8220;
  429. inoremap \" &#8221;
  430.  
  431. " when switching to a non-HTML buffer, automatically undo these mappings:
  432. autocmd! BufLeave * call MapHTMLKeys(0)
  433.  
  434. " parameter of zero, so want to unmap everything:
  435. else
  436. iunmap \\
  437. iunmap \&
  438. iunmap \<
  439. iunmap \>
  440. iunmap \-
  441. iunabbrev _
  442. iunmap \<Space>
  443. iunmap <C-Space>
  444. iunmap `
  445. iunmap '
  446. iunmap \`
  447. iunmap \'
  448. iunmap \2
  449. iunmap \"
  450.  
  451. " once done, get rid of the autocmd that called this:
  452. autocmd! BufLeave *
  453.  
  454. endif " test for mapping/unmapping
  455.  
  456. endfunction " MapHTMLKeys()
  457.  
  458.  
  459. " * `SLRN' Behaviour
  460.  
  461. " when using `SLRN' to compose a new news article without a signature, the
  462. " cursor will be at the end of the file, the blank line after the header, so
  463. " duplicate this line ready to start typing on; when composing a new article
  464. " with a signature, `SLRN' includes an appropriate blank line but places the
  465. " cursor on the following one, so move it up one line [if re-editing a
  466. " partially-composed article, `SLRN' places the cursor on the top line, so
  467. " neither of these will apply]:
  468. autocmd VimEnter .article if line('.') == line('$') | yank | put |
  469. \ elseif line('.') != 1 | -
  470.  
  471. " when following up articles from people with long names and/or e-mail
  472. " addresses, the `SLRN'-generated attribution line can have over 80 characters,
  473. " which will then cause `SLRN' to complain when trying to post it(!), so if
  474. " editing a followup for the first time, reformat the line (then put the cursor
  475. " back):
  476. autocmd VimEnter .followup if line('.') != 1 | normal gq${j
  477.  
  478.  
  479. " * Functions Referred to Above
  480.  
  481. function! HighlightSpellingErrors()
  482. " highlights spelling errors in the current window; used for the \sh operation
  483. " defined above;
  484. " requires the ispell, sort, and uniq commands to be in the path;
  485. " requires the global variable IspellLang to be defined above, and to contain
  486. " the preferred `Ispell' language;
  487. " for mail/news messages, requires the grep command to be in the path;
  488. " for HTML documents, saves the file to disk and requires the lynx command to
  489. " be in the path
  490. "
  491. " by Smylers http://www.stripey.com/vim/
  492. " (inspired by Krishna Gadepalli and Neil Schemenauer's vimspell.sh)
  493. "
  494. " 2000 Jun 1: for `Vim' 5.6
  495.  
  496. " for HTML files, remove all current syntax highlighting (so that
  497. " misspellings show up clearly), and note it's HTML for future reference:
  498. if &filetype == 'html'
  499. let HTML = 1
  500. syntax clear
  501.  
  502. " for everything else, simply remove any previously-identified spelling
  503. " errors (and corrections):
  504. else
  505. let HTML = 0
  506. if hlexists('SpellError')
  507. syntax clear SpellError
  508. endif
  509. if hlexists('Normal')
  510. syntax clear Normal
  511. endif
  512. endif
  513.  
  514. " form a command that has the text to be checked piping through standard
  515. " output; for HTML files this involves saving the current file and processing
  516. " it with `Lynx'; for everything else, use all the buffer except quoted text
  517. " and mail/news headers:
  518. if HTML
  519. write
  520. let PipeCmd = '! lynx --dump --nolist % |'
  521. else
  522. let PipeCmd = 'write !'
  523. if &filetype == 'mail'
  524. let PipeCmd = PipeCmd . ' grep -v "^> " | grep -E -v "^[[:alpha:]-]+:" |'
  525. endif
  526. endif
  527.  
  528. " execute that command, then generate a unique list of misspelt words and
  529. " store it in a temporary file:
  530. let ErrorsFile = tempname()
  531. execute PipeCmd . ' ispell -l -d '. g:IspellLang .
  532. \ ' | sort | uniq > ' . ErrorsFile
  533.  
  534. " open that list of words in another window:
  535. execute 'split ' . ErrorsFile
  536.  
  537. " for every word in that list ending with "'s", check if the root form
  538. " without the "'s" is in the dictionary, and if so remove the word from the
  539. " list:
  540. global /'s$/ execute 'read ! echo ' . expand('<cword>') .
  541. \ ' | ispell -l -d ' . g:IspellLang | delete
  542. " (If the root form is in the dictionary, ispell -l will have no output so
  543. " nothing will be read in, the cursor will remain in the same place and the
  544. " :delete will delete the word from the list. If the root form is not in the
  545. " dictionary, then ispell -l will output it and it will be read on to a new
  546. " line; the delete command will then remove that misspelt root form, leaving
  547. " the original possessive form in the list!)
  548.  
  549. " only do anything if there are some misspellings:
  550. if strlen(getline('.')) > 0
  551.  
  552. " if (previously noted as) HTML, replace each non-alphanum char with a
  553. " regexp that matches either that char or a &...; entity:
  554. if HTML
  555. % substitute /\W/\\(&\\|\&\\(#\\d\\{2,4}\\|\w\\{2,8}\\);\\)/e
  556. endif
  557.  
  558. " turn each mistake into a `Vim' command to place it in the SpellError
  559. " syntax highlighting group:
  560. % substitute /^/syntax match SpellError !\\</
  561. % substitute /$/\\>!/
  562. endif
  563.  
  564. " save and close that file (so switch back to the one being checked):
  565. exit
  566.  
  567. " make syntax highlighting case-sensitive, then execute all the match
  568. " commands that have just been set up in that temporary file, delete it, and
  569. " highlight all those words in red:
  570. syntax case match
  571. execute 'source ' . ErrorsFile
  572. call delete(ErrorsFile)
  573. highlight SpellError term=reverse ctermfg=DarkRed guifg=Red
  574.  
  575. " with HTML, don't mark any errors in e-mail addresses or URLs, and ignore
  576. " anything marked in a fix-width font (as being computer code):
  577. if HTML
  578. syntax case ignore
  579. syntax match Normal !\<[[:alnum:]._-]\+@[[:alnum:]._-]\+\.\a\+\>!
  580. syntax match Normal
  581. \ !\<\(ht\|f\)tp://[-[:alnum:].]\+\a\(/[-_.[:alnum:]/#&=,]*\)\=\>!
  582. syntax region Normal start=!<Pre>! end=!</Pre>!
  583. syntax region Normal start=!<Code>! end=!</Code>!
  584. syntax region Normal start=!<Kbd>! end=!</Kbd>!
  585. endif
  586.  
  587. endfunction " HighlightSpellingErrors()
  588.  
  589.  
  590. function! AddWordToDictionary()
  591. " adds the word under the cursor to the personal dictonary; used for the \sa
  592. " operation defined above;
  593. " requires the global variable PersonalDict to be defined above, and to contain
  594. " the `Ispell' personal dictionary;
  595. "
  596. " by Smylers http://www.stripey.com/vim/
  597. "
  598. " 2000 Apr 30: for `Vim' 5.6
  599.  
  600. " get the word under the cursor, including the apostrophe as a word character
  601. " to allow for words like "won't", but then ignoring any apostrophes at the
  602. " start or end of the word:
  603. set iskeyword+='
  604. let Word = substitute(expand('<cword>'), "^'\\+", '', '')
  605. let Word = substitute(Word, "'\\+$", '', '')
  606. set iskeyword-='
  607.  
  608. " override any SpellError highlighting that might exist for this word,
  609. " `highlighting' it as normal text:
  610. execute 'syntax match Normal #\<' . Word . '\>#'
  611.  
  612. " remove any final "'s" so that possessive forms don't end up in the
  613. " dictionary, then add the word to the dictionary:
  614. let Word = substitute(Word, "'s$", '', '')
  615. execute '!echo "' . Word . '" >> ' . g:PersonalDict
  616.  
  617. endfunction " AddWordToDictionary()
  618.  
  619.  
  620. function! InsertCloseTag()
  621. " inserts the appropriate closing HTML tag; used for the \hc operation defined
  622. " above;
  623. " requires ignorecase to be set, or to type HTML tags in exactly the same case
  624. " that I do;
  625. " doesn't treat <P> as something that needs closing;
  626. " clobbers register z and mark z
  627. "
  628. " by Smylers http://www.stripey.com/vim/
  629. " 2000 May 4
  630.  
  631. if &filetype == 'html'
  632.  
  633. " list of tags which shouldn't be closed:
  634. let UnaryTags = ' Area Base Br DD DT HR Img Input LI Link Meta P Param '
  635.  
  636. " remember current position:
  637. normal mz
  638.  
  639. " loop backwards looking for tags:
  640. let Found = 0
  641. while Found == 0
  642. " find the previous <, then go forwards one character and grab the first
  643. " character plus the entire word:
  644. execute "normal ?\<LT>\<CR>l"
  645. normal "zyl
  646. let Tag = expand('<cword>')
  647.  
  648. " if this is a closing tag, skip back to its matching opening tag:
  649. if @z == '/'
  650. execute "normal ?\<LT>" . Tag . "\<CR>"
  651.  
  652. " if this is a unary tag, then position the cursor for the next
  653. " iteration:
  654. elseif match(UnaryTags, ' ' . Tag . ' ') > 0
  655. normal h
  656.  
  657. " otherwise this is the tag that needs closing:
  658. else
  659. let Found = 1
  660.  
  661. endif
  662. endwhile " not yet found match
  663.  
  664. " create the closing tag and insert it:
  665. let @z = '</' . Tag . '>'
  666. normal `z
  667. if col('.') == 1
  668. normal "zP
  669. else
  670. normal "zp
  671. endif
  672.  
  673. else " filetype is not HTML
  674. echohl ErrorMsg
  675. echo 'The InsertCloseTag() function is only intended to be used in HTML ' .
  676. \ 'files.'
  677. sleep
  678. echohl None
  679.  
  680. endif " check on filetype
  681.  
  682. endfunction " InsertCloseTag()
  683.  
  684.  
  685. function! RepeatTag(Forward)
  686. " repeats a (non-closing) HTML tag from elsewhere in the document; call
  687. " repeatedly until the correct tag is inserted (like with insert mode <Ctrl>+P
  688. " and <Ctrl>+N completion), with Forward determining whether to copy forwards
  689. " or backwards through the file; used for the \hp and \hn operations defined
  690. " above;
  691. " requires preservation of marks i and j;
  692. " clobbers register z
  693. "
  694. " by Smylers http://www.stripey.com/vim/
  695. "
  696. " 2000 May 4: for `Vim' 5.6
  697.  
  698. if &filetype == 'html'
  699.  
  700. " if the cursor is where this function left it, then continue from there:
  701. if line('.') == line("'i") && col('.') == col("'i")
  702. " delete the tag inserted last time:
  703. if col('.') == strlen(getline('.'))
  704. normal dF<x
  705. else
  706. normal dF<x
  707. if col('.') != 1
  708. normal h
  709. endif
  710. endif
  711. " note the cursor position, then jump to where the deleted tag was found:
  712. normal mi`j
  713.  
  714. " otherwise, just store the cursor position (in mark i):
  715. else
  716. normal mi
  717. endif
  718.  
  719. if a:Forward
  720. let SearchCmd = '/'
  721. else
  722. let SearchCmd = '?'
  723. endif
  724.  
  725. " find the next non-closing tag (in the appropriate direction), note where
  726. " it is (in mark j) in case this function gets called again, then yank it
  727. " and paste a copy at the original cursor position, and store the final
  728. " cursor position (in mark i) for use next time round:
  729. execute "normal " . SearchCmd . "<[^/>].\\{-}>\<CR>mj\"zyf>`i"
  730. if col('.') == 1
  731. normal "zP
  732. else
  733. normal "zp
  734. endif
  735. normal mi
  736.  
  737. else " filetype is not HTML
  738. echohl ErrorMsg
  739. echo 'The RepeatTag() function is only intended to be used in HTML files.'
  740. sleep
  741. echohl None
  742.  
  743. endif
  744.  
  745. endfunction " RepeatTag()
  746.  
  747. " Automatic code completion commands, plugins and scripts
  748.  
  749. " Auto-close parenthesis, single and double quotes, brackets and curly brackets.
  750. autocmd FileType python inoremap ( ()<Esc>i
  751. autocmd FileType python inoremap ' ''<Esc>i
  752. " For .vimrc style comments this should be disabled.
  753. autocmd FileType python inoremap " ""<Esc>i
  754. " For bash scripts, space properly.
  755. autocmd FileType python inoremap [ []<Esc>i
  756.  
  757. " For C style function body definition this should be expanded.
  758. " autocmd FileType python inoremap { {}<Esc>i
  759. " C style function definition curly braces.
  760. " autocmd FileType c,cpp,java inoremap { {<CR>}<Esc>i<Up><End><CR><Tab>
  761.  
  762. filetype plugin on
  763. let g:pydiction_location = '/home/mfukar/.vim/pydiction/complete-dict'
  764. let g:pydiction_menu_height = 20
  765.  
  766. "Remove the Windows ^M
  767. "noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
  768. "Remove indenting on empty lines
  769. "map <F2> :%s/\s*$//g<cr>:noh<cr>''
  770.  
  771. " end of mfukar's .vimrc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement