├── .gitignore ├── README.mkd ├── ftdetect └── fsharp.vim ├── ftplugin └── fsharp.vim ├── indent └── fsharp.vim └── syntax └── fsharp.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | #*.pdf 3 | *.DS_Store 4 | *.aux 5 | *.blg 6 | *.lof 7 | *.log 8 | *.pyc 9 | *.sqlite3 10 | *.sw[nop] 11 | *.synctex.gz 12 | Thumbs.db 13 | *.toc 14 | ./*/*.aux 15 | ./*/*.log 16 | ./*/*.sw[nop] 17 | ./*/.DS_Store 18 | .DS_Store 19 | core 20 | -------------------------------------------------------------------------------- /README.mkd: -------------------------------------------------------------------------------- 1 | 2 | Vim Runtime Files for F# (FSharp) 3 | ======================================= 4 | 5 | This runtime files are inspired by the original version of a fsharp syntax file 6 | named [fs.vim](http://www.vim.org/scripts/script.php?script_id=2162) from [Choy 7 | Rim](mailto:choy.rim@gmail.com) and a slightly [modified 8 | version](https://github.com/DrTom/fsharp-vim) from [Thomas 9 | Schank](mailto:ThomasSchank@gmail.com). The syntax file is now completely 10 | rewritten. 11 | 12 | This vim runtime files are especially helpful when editing F# files under 13 | Linux/Mac. Under Windows I would recommend to use VisualStudio with the great 14 | [VsVim Plugin](https://github.com/jaredpar/VsVim) by Jared Parsons. 15 | 16 | 17 | Installing 18 | ---------- 19 | 20 | ### Using pathogen 21 | 22 | 1. Install [pathogen](https://github.com/tpope/vim-pathogen) 23 | 24 | 2. Move into your main vimfiles git repository 25 | 26 | 3. Run `git submodule add git://github.com/kongo2002/fsharp-vim.git bundle/fsharp` 27 | 28 | ### Traditional install 29 | 30 | Drop the contents into your `~/.vim` directory as usual 31 | 32 | 33 | Usage 34 | ------ 35 | 36 | Opening either `*.fs`, `*.fsi` or `*.fsx` files should trigger syntax 37 | highlighting and other depending runtime files as well. 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /ftdetect/fsharp.vim: -------------------------------------------------------------------------------- 1 | " F#, fsharp 2 | autocmd BufNewFile,BufRead *.fs,*.fsi,*.fsx set filetype=fsharp 3 | -------------------------------------------------------------------------------- /ftplugin/fsharp.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin 2 | " Language: F# 3 | " Last Change: Sun 31 Aug 2014 06:58:41 PM CEST 4 | " Maintainer: Gregor Uhlenheuer 5 | 6 | if exists('b:did_ftplugin') 7 | finish 8 | endif 9 | let b:did_ftplugin = 1 10 | 11 | let s:cpo_save = &cpo 12 | set cpo&vim 13 | 14 | " Jump to bindings in the first column, taken from python. 15 | nnoremap ]] :call Fsharp_jump('/^\(let\\|type\\|do\\|module\)') 16 | nnoremap [[ :call Fsharp_jump('?^\(let\\|type\\|do\\|module\)') 17 | nnoremap ]m :call Fsharp_jump('/^\s*\(let\\|type\\|do\\|module\)') 18 | nnoremap [m :call Fsharp_jump('?^\s*\(let\\|type\\|do\\|module\)') 19 | 20 | if exists('*Fsharp_jump') | finish | endif 21 | 22 | fun! Fsharp_jump(motion) range 23 | let cnt = v:count1 24 | " save last search pattern 25 | let save = @/ 26 | mark ' 27 | while cnt > 0 28 | silent! exe a:motion 29 | let cnt = cnt - 1 30 | endwhile 31 | call histdel('/', -1) 32 | " restore last search pattern 33 | let @/ = save 34 | endfun 35 | 36 | " enable syntax based folding 37 | setl fdm=syntax 38 | 39 | " comment settings 40 | setl formatoptions=croql 41 | setl commentstring=(*%s*) 42 | setl comments=s0:*\ -,m0:*\ \ ,ex0:*),s1:(*,mb:*,ex:*),:\/\/\/,:\/\/ 43 | 44 | " tab/indentation settings 45 | setl expandtab 46 | setl nolisp 47 | setl nosmartindent 48 | 49 | " make ftplugin undo-able 50 | let b:undo_ftplugin = 'setl fo< cms< com< fdm< et< si< lisp<' 51 | 52 | let &cpo = s:cpo_save 53 | 54 | " vim: sw=4 et sts=4 55 | -------------------------------------------------------------------------------- /indent/fsharp.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: FSharp 3 | " Maintainers: Jean-Francois Yuen 4 | " Mike Leary 5 | " Markus Mottl 6 | " Rudi Grinberg 7 | " Gregor Uhlenheuer 8 | " Last Change: 2013 Jun 29 9 | " 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working 10 | " 2005 May 09 - Added an option to not indent OCaml-indents specially (MM) 11 | " 2013 June - commented textwidth (Marc Weber) 12 | " 2014 August - Ported to F# 13 | " 2014 August - F# specific cleanup 14 | " 15 | " Marc Weber's comment: This file may contain a lot of (very custom) stuff 16 | " which eventually should be moved somewhere else .. 17 | 18 | " Only load this indent file when no other was loaded. 19 | 20 | if exists("b:did_indent") 21 | finish 22 | endif 23 | let b:did_indent = 1 24 | 25 | setlocal indentexpr=GetFsharpIndent() 26 | setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0) 27 | 28 | " Only define the function once. 29 | if exists("*GetFsharpIndent") 30 | finish 31 | endif 32 | 33 | " Skipping pattern, for comments 34 | function! s:GetLineWithoutFullComment(lnum) 35 | let lnum = prevnonblank(a:lnum - 1) 36 | let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '') 37 | while lline =~ '^\s*$' && lnum > 0 38 | let lnum = prevnonblank(lnum - 1) 39 | let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '') 40 | endwhile 41 | return lnum 42 | endfunction 43 | 44 | " Indent for ';;' to match multiple 'let' 45 | function! s:GetInd(lnum, pat, lim) 46 | let llet = search(a:pat, 'bW') 47 | let old = indent(a:lnum) 48 | while llet > 0 49 | let old = indent(llet) 50 | let nb = s:GetLineWithoutFullComment(llet) 51 | if getline(nb) =~ a:lim 52 | return old 53 | endif 54 | let llet = search(a:pat, 'bW') 55 | endwhile 56 | return old 57 | endfunction 58 | 59 | " Indent pairs 60 | function! s:FindPair(pstart, pmid, pend) 61 | call search(a:pend, 'bW') 62 | return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')) 63 | endfunction 64 | 65 | " Indent 'let' 66 | function! s:FindLet(pstart, pmid, pend) 67 | call search(a:pend, 'bW') 68 | return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") =~ "^\\s*let\\>.*=.*\\\s*$' 85 | return ind + &sw + &sw 86 | endif 87 | 88 | let line = getline(v:lnum) 89 | 90 | " Indent if current line begins with 'end': 91 | if line =~ '^\s*end\>' 92 | return s:FindPair(s:module, '','\') 93 | 94 | " Indent if current line begins with 'done' for 'do': 95 | elseif line =~ '^\s*done\>' 96 | return s:FindPair('\', '','\') 97 | 98 | " Indent if current line begins with '}' or '>}': 99 | elseif line =~ '^\s*\(\|>\)}' 100 | return s:FindPair('{', '','}') 101 | 102 | " Indent if current line begins with ']', '|]' or '>]': 103 | elseif line =~ '^\s*\(\||\|>\)\]' 104 | return s:FindPair('\[', '','\]') 105 | 106 | " Indent if current line begins with ')': 107 | elseif line =~ '^\s*)' 108 | return s:FindPair('(', '',')') 109 | 110 | " Indent if current line begins with 'let': 111 | elseif line =~ '^\s*let\>' 112 | if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet 113 | return s:FindLet(s:type, '','\' 118 | if lline !~ s:lim . '\|\\)\|\<\(function\|private\|with\)\s*$' 125 | call search('|', 'bW') 126 | return indent(searchpair('^\s*\(match\|type\)\>\|\<\(function\|private\|with\)\s*$', '', '^\s*|', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") !~ "^\\s*|.*->"')) 127 | endif 128 | 129 | " Indent if current line begins with ';;': 130 | elseif line =~ '^\s*;;' 131 | if lline !~ ';;\s*$' 132 | return s:GetInd(v:lnum, s:letpat, s:letlim) 133 | endif 134 | 135 | " Indent if current line begins with 'in': 136 | elseif line =~ '^\s*in\>' 137 | if lline !~ '^\s*\(let\|and\)\>' 138 | return s:FindPair('\', '', '\') 139 | endif 140 | 141 | " Indent if current line begins with 'else': 142 | elseif line =~ '^\s*else\>' 143 | if lline !~ '^\s*\(if\|then\)\>' 144 | return s:FindPair('\', '', '\') 145 | endif 146 | 147 | " Indent if current line begins with 'then': 148 | elseif line =~ '^\s*then\>' 149 | if lline !~ '^\s*\(if\|else\)\>' 150 | return s:FindPair('\', '', '\') 151 | endif 152 | 153 | " Indent if current line begins with 'and': 154 | elseif line =~ '^\s*and\>' 155 | if lline !~ '^\s*\(and\|let\|type\)\>\|\' 161 | if lline !~ '^\s*\(match\|try\)\>' 162 | return s:FindPair('\<\%(match\|try\)\>', '','\') 163 | endif 164 | 165 | " Indent if current line begins with 'exception', 'external', 'include' or 166 | " 'open': 167 | elseif line =~ '^\s*\(exception\|external\|include\|open\)\>' 168 | if lline !~ s:lim . '\|' . s:letlim 169 | call search(line) 170 | return indent(search('^\s*\(\(exception\|external\|include\|open\|type\)\>\|val\>.*:\)', 'bW')) 171 | endif 172 | 173 | " Indent if current line begins with 'val': 174 | elseif line =~ '^\s*val\>' 175 | if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim 176 | return indent(search('^\s*\(\(exception\|include\|initializer\|method\|open\|type\|val\)\>\|external\>.*:\)', 'bW')) 177 | endif 178 | 179 | " Indent if current line begins with 'constraint', 'inherit', 'initializer' 180 | " or 'method': 181 | elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>' 182 | if lline !~ s:obj 183 | return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw 184 | endif 185 | 186 | endif 187 | 188 | " Add a 'shiftwidth' after lines ending with: 189 | if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|private\|sig\|struct\|then\|try\)\|\') 199 | 200 | " Back to normal indent after lines ending with 'in': 201 | elseif lline =~ '\' 202 | let ind = s:FindPair('\', '', '\') 203 | 204 | " Back to normal indent after lines ending with 'done': 205 | elseif lline =~ '\', '','\') 207 | 208 | " Back to normal indent after lines ending with '}' or '>}': 209 | elseif lline =~ '\(\|>\)}\s*$' 210 | let ind = s:FindPair('{', '','}') 211 | 212 | " Back to normal indent after lines ending with ']', '|]' or '>]': 213 | elseif lline =~ '\(\||\|>\)\]\s*$' 214 | let ind = s:FindPair('\[', '','\]') 215 | 216 | " Back to normal indent after comments: 217 | elseif lline =~ '\*)\s*$' 218 | call search('\*)', 'bW') 219 | let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')) 220 | 221 | " Back to normal indent after lines ending with ')': 222 | elseif lline =~ ')\s*$' 223 | let ind = s:FindPair('(', '',')') 224 | 225 | " If this is a multiline comment then align '*': 226 | elseif lline =~ '^\s*(\*' && line =~ '^\s*\*' 227 | let ind = ind + 1 228 | 229 | else 230 | " Don't change indentation of this line 231 | " for new lines (indent==0) use indentation of previous line 232 | 233 | " This is for preventing removing indentation of these args: 234 | " let f x = 235 | " let y = x + 1 in 236 | " Printf.printf 237 | " "o" << here 238 | " "oeuth" << don't touch indentation 239 | 240 | let i = indent(v:lnum) 241 | return i == 0 ? ind : i 242 | 243 | endif 244 | 245 | return ind 246 | 247 | endfunction 248 | 249 | " vim: sw=4 et sts=4 250 | -------------------------------------------------------------------------------- /syntax/fsharp.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: F# 3 | " Last Change: Thu 04 Sep 2014 08:35:49 PM CEST 4 | " Maintainer: Gregor Uhlenheuer 5 | " 6 | " Note: This syntax file is a complete rewrite of the original version 7 | " of fs.vim from Choy Rim and a slight 8 | " modified version from Thomas Schank 9 | 10 | if version < 600 11 | syntax clear 12 | elseif exists('b:current_syntax') 13 | finish 14 | endif 15 | 16 | " F# is case sensitive. 17 | syn case match 18 | 19 | " reset 'iskeyword' setting 20 | setl isk&vim 21 | 22 | " Scripting/preprocessor directives 23 | syn match fsharpSScript "^\s*#\S\+" transparent contains=fsharpScript,fsharpRegion,fsharpPreCondit 24 | 25 | syn match fsharpScript contained "#" 26 | syn keyword fsharpScript contained quitlabels warnings directory cd load use 27 | syn keyword fsharpScript contained install_printer remove_printer requirethread 28 | syn keyword fsharpScript contained trace untrace untrace_all print_depth 29 | syn keyword fsharpScript contained print_length define undef if elif else endif 30 | syn keyword fsharpScript contained line error warning light nowarn 31 | 32 | 33 | " comments 34 | syn match fsharpComment "//.*$" contains=fsharpTodo,@Spell 35 | syn region fsharpDocComment start="///" end="$" contains=fsharpTodo,fsharpXml,@Spell keepend oneline 36 | syn region fsharpXml matchgroup=fsharpXmlDoc start="<[^>]\+>" end="]\+>" contained 37 | 38 | 39 | " symbol names 40 | syn match fsharpSymbol "\%(let\|use\|mutable\|rec\|and\)\@<=!\=\s\+\zs\w\+\ze\s*[^=:]*[=:]" 41 | syn match fsharpSymbol "\%(member\)\@<=\s\+\w\+\.\zs\w\+" 42 | 43 | 44 | " types 45 | syn match fsharpTypeName "\%(\" 140 | syn match fsharpRefAssign ":=" 141 | syn match fsharpTopStop ";;" 142 | syn match fsharpOperator "\^" 143 | syn match fsharpOperator "::" 144 | 145 | syn match fsharpLabel "\<_\>" 146 | 147 | syn match fsharpOperator "&&" 148 | syn match fsharpOperator "<" 149 | syn match fsharpOperator ">" 150 | syn match fsharpOperator "|>" 151 | syn match fsharpOperator ":>" 152 | syn match fsharpOperator ":?>" 153 | syn match fsharpOperator "&&&" 154 | syn match fsharpOperator "|||" 155 | syn match fsharpOperator "\.\." 156 | 157 | syn match fsharpKeyChar "|[^\]]"me=e-1 158 | syn match fsharpKeyChar ";" 159 | syn match fsharpKeyChar "\~" 160 | syn match fsharpKeyChar "?" 161 | syn match fsharpKeyChar "\*" 162 | syn match fsharpKeyChar "+" 163 | syn match fsharpKeyChar "=" 164 | syn match fsharpKeyChar "|" 165 | 166 | syn match fsharpOperator "<-" 167 | 168 | syn match fsharpNumber "\<\d\+" 169 | syn match fsharpNumber "\<-\=\d\(_\|\d\)*[l|L|n]\?\>" 170 | syn match fsharpNumber "\<-\=0[x|X]\(\x\|_\)\+[l|L|n]\?\>" 171 | syn match fsharpNumber "\<-\=0[o|O]\(\o\|_\)\+[l|L|n]\?\>" 172 | syn match fsharpNumber "\<-\=0[b|B]\([01]\|_\)\+[l|L|n]\?\>" 173 | syn match fsharpFloat "\<-\=\d\(_\|\d\)*\.\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" 174 | syn match fsharpFloat "\<-\=\d\(_\|\d\)*\.\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" 175 | syn match fsharpFloat "\<\d\+\.\d*" 176 | 177 | " modules 178 | syn match fsharpModule "\%(\= 508 || !exists("did_fs_syntax_inits") 189 | if version < 508 190 | let did_fs_syntax_inits = 1 191 | command -nargs=+ HiLink hi link 192 | else 193 | command -nargs=+ HiLink hi def link 194 | endif 195 | 196 | HiLink fsharpBraceErr Error 197 | HiLink fsharpBrackErr Error 198 | HiLink fsharpParenErr Error 199 | HiLink fsharpArrErr Error 200 | HiLink fsharpCommentErr Error 201 | 202 | HiLink fsharpComment Comment 203 | HiLink fsharpDocComment Comment 204 | HiLink fsharpXml Comment 205 | 206 | HiLink fsharpOpen Include 207 | HiLink fsharpModPath Include 208 | HiLink fsharpScript Include 209 | HiLink fsharpPreCondit Include 210 | 211 | HiLink fsharpKeyword Keyword 212 | HiLink fsharpCoreMethod Keyword 213 | 214 | HiLink fsharpOCaml Statement 215 | HiLink fsharpLinq Statement 216 | 217 | HiLink fsharpSymbol Function 218 | 219 | HiLink fsharpFunDef Operator 220 | HiLink fsharpRefAssign Operator 221 | HiLink fsharpTopStop Operator 222 | HiLink fsharpKeyChar Operator 223 | HiLink fsharpOperator Operator 224 | 225 | HiLink fsharpBoolean Boolean 226 | HiLink fsharpConstant Constant 227 | HiLink fsharpCharacter Character 228 | HiLink fsharpNumber Number 229 | HiLink fsharpFloat Float 230 | 231 | HiLink fsharpString String 232 | HiLink fsharpRawString String 233 | 234 | HiLink fsharpFormat Special 235 | 236 | HiLink fsharpModifier StorageClass 237 | 238 | HiLink fsharpException Exception 239 | 240 | HiLink fsharpLabel Identifier 241 | HiLink fsharpOption Identifier 242 | HiLink fsharpTypeName Identifier 243 | HiLink fsharpModule Identifier 244 | 245 | HiLink fsharpType Type 246 | 247 | HiLink fsharpCoreClass Typedef 248 | HiLink fsharpAttrib Typedef 249 | HiLink fsharpXmlDoc Typedef 250 | 251 | HiLink fsharpTodo Todo 252 | 253 | HiLink fsharpEncl Delimiter 254 | HiLink fsharpAttribute Delimiter 255 | 256 | delcommand HiLink 257 | endif 258 | 259 | let b:current_syntax = 'fsharp' 260 | 261 | " vim: sw=4 et sts=4 262 | --------------------------------------------------------------------------------