diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a0e76af --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.netrwhist diff --git a/.gitmodules b/.gitmodules index 3deda34..91829d9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -57,13 +57,73 @@ url = https://github.com/vim-scripts/taglist.vim.git [submodule "plugins/easymotion"] path = plugins/easymotion - url = https://github.com/Lokaltog/vim-easymotion + url = https://github.com/Lokaltog/vim-easymotion.git [submodule "plugins/sparkup"] path = plugins/sparkup url = https://github.com/bingaman/vim-sparkup.git -[submodule "plugins/mustache"] - path = plugins/mustache - url = git@github.com:valinorsgatekeeper/vim-kicks-ass.git [submodule "plugins/coffee-script"] path = plugins/coffee-script url = https://github.com/kchmck/vim-coffee-script.git +[submodule "plugins/php-namespace"] + path = plugins/php-namespace + url = https://github.com/arnaud-lb/vim-php-namespace.git +[submodule "plugins/php-cs-fixer"] + path = plugins/php-cs-fixer + url = https://github.com/stephpy/vim-php-cs-fixer.git +[submodule "plugins/php-complete"] + path = plugins/php-complete + url = https://github.com/shawncplus/phpcomplete.vim.git +[submodule "plugins/cpp-complete"] + path = plugins/cpp-complete + url = https://github.com/vim-scripts/OmniCppComplete.git +[submodule "plugins/js-jquery"] + path = plugins/js-jquery + url = https://github.com/itspriddle/vim-jquery.git +[submodule "plugins/js-jquery-doc"] + path = plugins/js-jquery-doc + url = https://github.com/lucapette/vim-jquery-doc.git +[submodule "plugins/easytags"] + path = plugins/easytags + url = https://github.com/xolox/vim-easytags.git +[submodule "plugins/misc"] + path = plugins/misc + url = https://github.com/xolox/vim-misc.git +[submodule "plugins/autocomplpop"] + path = plugins/autocomplpop + url = https://github.com/othree/vim-autocomplpop.git +[submodule "plugins/neocomplete"] + path = plugins/neocomplete + url = https://github.com/Shougo/neocomplete.vim.git +[submodule "plugins/html5"] + path = plugins/html5 + url = https://github.com/othree/html5.vim.git +[submodule "plugins/closetag"] + path = plugins/closetag + url = https://github.com/docunext/closetag.vim.git +[submodule "plugins/detectindent"] + path = plugins/detectindent + url = https://github.com/ciaranm/detectindent +[submodule "plugins/fzf.vim"] + path = plugins/fzf.vim + url = https://git::@github.com/junegunn/fzf.vim.git +[submodule "plugins/lightline.vim"] + path = plugins/lightline.vim + url = https://git::@github.com/itchyny/lightline.vim.git +[submodule "plugins/nerdtree"] + path = plugins/nerdtree + url = https://git::@github.com/scrooloose/nerdtree.git +[submodule "colors/onedark.vim"] + path = colors/onedark.vim + url = https://git::@github.com/joshdick/onedark.vim.git +[submodule "plugins/vim-polyglot"] + path = plugins/vim-polyglot + url = https://git::@github.com/sheerun/vim-polyglot.git +[submodule "plugins/vim-json"] + path = plugins/vim-json + url = https://git::@github.com/elzr/vim-json.git +[submodule "plugins/mustache"] + path = plugins/mustache + url = https://github.com/mustache/vim-mustache-handlebars.git +[submodule "plugins/vim-css-color"] + path = plugins/vim-css-color + url = https://git::@github.com/ap/vim-css-color.git diff --git a/README.md b/README.md index 0a57991..d2a998f 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ colorschemes and custom made presets, which can be enabled or disabled easily us vim-kicks-ass plugin. You will also find templates which you can use as your own vimrc, or you can use them for inspiration for creating your own. -My inspiration comes from the great [oh-my-zsh](https://github.com/robbyrussel/oh-my-zsh) project, where a lot of -people has forked, contributed and otherwise helped creating a great framework for configuring zshell. I +My inspiration comes from the great [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) project, where a lot of +people has forked, contributed and otherwise helped creating a great framework for configuring zshell. I wan't the same for VIM. I am not the greatest vimscript developer, nor am I the most advanced superuser of VIM, but with help from diff --git a/colors/jellybeans b/colors/jellybeans index 9e4b612..ef83bf4 160000 --- a/colors/jellybeans +++ b/colors/jellybeans @@ -1 +1 @@ -Subproject commit 9e4b612bc6729f8a6f39d2f37755511236a93ff9 +Subproject commit ef83bf4dc8b3eacffc97bf5c96ab2581b415c9fa diff --git a/colors/molokai/colors/molokai.vim b/colors/molokai/colors/molokai.vim new file mode 100644 index 0000000..2e4ba73 --- /dev/null +++ b/colors/molokai/colors/molokai.vim @@ -0,0 +1,270 @@ + +" Vim color file +" +" Author: Tomas Restrepo +" +" Note: Based on the monokai theme for textmate +" by Wimer Hazenberg and its darker variant +" by Hamish Stuart Macpherson +" + +hi clear + +set background=dark +if version > 580 + " no guarantees for version 5.8 and below, but this makes it stop + " complaining + hi clear + if exists("syntax_on") + syntax reset + endif +endif +let g:colors_name="molokai" + +if exists("g:molokai_original") + let s:molokai_original = g:molokai_original +else + let s:molokai_original = 0 +endif + + +hi Boolean guifg=#AE81FF +hi Character guifg=#E6DB74 +hi Number guifg=#AE81FF +hi String guifg=#E6DB74 +hi Conditional guifg=#F92672 gui=bold +hi Constant guifg=#AE81FF gui=bold +hi Cursor guifg=#000000 guibg=#F8F8F0 +hi iCursor guifg=#000000 guibg=#F8F8F0 +hi Debug guifg=#BCA3A3 gui=bold +hi Define guifg=#66D9EF +hi Delimiter guifg=#8F8F8F +hi DiffAdd guibg=#13354A +hi DiffChange guifg=#89807D guibg=#4C4745 +hi DiffDelete guifg=#960050 guibg=#1E0010 +hi DiffText guibg=#4C4745 gui=italic,bold + +hi Directory guifg=#A6E22E gui=bold +hi Error guifg=#960050 guibg=#1E0010 +hi ErrorMsg guifg=#F92672 guibg=#232526 gui=bold +hi Exception guifg=#A6E22E gui=bold +hi Float guifg=#AE81FF +hi FoldColumn guifg=#465457 guibg=#000000 +hi Folded guifg=#465457 guibg=#000000 +hi Function guifg=#A6E22E +hi Identifier guifg=#FD971F +hi Ignore guifg=#808080 guibg=bg +hi IncSearch guifg=#C4BE89 guibg=#000000 + +hi Keyword guifg=#F92672 gui=bold +hi Label guifg=#E6DB74 gui=none +hi Macro guifg=#C4BE89 gui=italic +hi SpecialKey guifg=#66D9EF gui=italic + +hi MatchParen guifg=#000000 guibg=#FD971F gui=bold +hi ModeMsg guifg=#E6DB74 +hi MoreMsg guifg=#E6DB74 +hi Operator guifg=#F92672 + +" complete menu +hi Pmenu guifg=#66D9EF guibg=#000000 +hi PmenuSel guibg=#808080 +hi PmenuSbar guibg=#080808 +hi PmenuThumb guifg=#66D9EF + +hi PreCondit guifg=#A6E22E gui=bold +hi PreProc guifg=#A6E22E +hi Question guifg=#66D9EF +hi Repeat guifg=#F92672 gui=bold +hi Search guifg=#FFFFFF guibg=#455354 +" marks +hi SignColumn guifg=#A6E22E guibg=#232526 +hi SpecialChar guifg=#F92672 gui=bold +hi SpecialComment guifg=#7E8E91 gui=bold +hi Special guifg=#66D9EF guibg=bg gui=italic +if has("spell") + hi SpellBad guisp=#FF0000 gui=undercurl + hi SpellCap guisp=#7070F0 gui=undercurl + hi SpellLocal guisp=#70F0F0 gui=undercurl + hi SpellRare guisp=#FFFFFF gui=undercurl +endif +hi Statement guifg=#F92672 gui=bold +hi StatusLine guifg=#455354 guibg=fg +hi StatusLineNC guifg=#808080 guibg=#080808 +hi StorageClass guifg=#FD971F gui=italic +hi Structure guifg=#66D9EF +hi Tag guifg=#F92672 gui=italic +hi Title guifg=#ef5939 +hi Todo guifg=#FFFFFF guibg=bg gui=bold + +hi Typedef guifg=#66D9EF +hi Type guifg=#66D9EF gui=none +hi Underlined guifg=#808080 gui=underline + +hi VertSplit guifg=#808080 guibg=#080808 gui=bold +hi VisualNOS guibg=#403D3D +hi Visual guibg=#403D3D +hi WarningMsg guifg=#FFFFFF guibg=#333333 gui=bold +hi WildMenu guifg=#66D9EF guibg=#000000 + +if s:molokai_original == 1 + hi Normal guifg=#F8F8F2 guibg=#272822 + hi Comment guifg=#75715E + hi CursorLine guibg=#3E3D32 + hi CursorLineNr guifg=#FD971F gui=none + hi CursorColumn guibg=#3E3D32 + hi ColorColumn guibg=#3B3A32 + hi LineNr guifg=#BCBCBC guibg=#3B3A32 + hi NonText guifg=#75715E + hi SpecialKey guifg=#75715E +else + hi Normal guifg=#F8F8F2 guibg=#1B1D1E + hi Comment guifg=#7E8E91 + hi CursorLine guibg=#293739 + hi CursorLineNr guifg=#FD971F gui=none + hi CursorColumn guibg=#293739 + hi ColorColumn guibg=#232526 + hi LineNr guifg=#465457 guibg=#232526 + hi NonText guifg=#465457 + hi SpecialKey guifg=#465457 +end + +" +" Support for 256-color terminal +" +if &t_Co > 255 + if s:molokai_original == 1 + hi Normal ctermbg=234 + hi CursorLine ctermbg=235 cterm=none + hi CursorLineNr ctermfg=208 cterm=none + else + hi Normal ctermfg=252 ctermbg=233 + hi CursorLine ctermbg=234 cterm=none + hi CursorLineNr ctermfg=208 cterm=none + endif + hi Boolean ctermfg=135 + hi Character ctermfg=144 + hi Number ctermfg=135 + hi String ctermfg=144 + hi Conditional ctermfg=161 cterm=bold + hi Constant ctermfg=135 cterm=bold + hi Cursor ctermfg=16 ctermbg=253 + hi Debug ctermfg=225 cterm=bold + hi Define ctermfg=81 + hi Delimiter ctermfg=241 + + hi DiffAdd ctermbg=24 + hi DiffChange ctermfg=181 ctermbg=239 + hi DiffDelete ctermfg=162 ctermbg=53 + hi DiffText ctermbg=102 cterm=bold + + hi Directory ctermfg=118 cterm=bold + hi Error ctermfg=219 ctermbg=89 + hi ErrorMsg ctermfg=199 ctermbg=16 cterm=bold + hi Exception ctermfg=118 cterm=bold + hi Float ctermfg=135 + hi FoldColumn ctermfg=67 ctermbg=16 + hi Folded ctermfg=67 ctermbg=16 + hi Function ctermfg=118 + hi Identifier ctermfg=208 cterm=none + hi Ignore ctermfg=244 ctermbg=232 + hi IncSearch ctermfg=193 ctermbg=16 + + hi keyword ctermfg=161 cterm=bold + hi Label ctermfg=229 cterm=none + hi Macro ctermfg=193 + hi SpecialKey ctermfg=81 + + hi MatchParen ctermfg=16 ctermbg=208 cterm=bold + hi ModeMsg ctermfg=229 + hi MoreMsg ctermfg=229 + hi Operator ctermfg=161 + + " complete menu + hi Pmenu ctermfg=81 ctermbg=16 + hi PmenuSel ctermfg=253 ctermbg=244 + hi PmenuSbar ctermbg=232 + hi PmenuThumb ctermfg=81 + + hi PreCondit ctermfg=118 cterm=bold + hi PreProc ctermfg=118 + hi Question ctermfg=81 + hi Repeat ctermfg=161 cterm=bold + hi Search ctermfg=253 ctermbg=66 + + " marks column + hi SignColumn ctermfg=118 ctermbg=235 + hi SpecialChar ctermfg=161 cterm=bold + hi SpecialComment ctermfg=245 cterm=bold + hi Special ctermfg=81 + if has("spell") + hi SpellBad ctermbg=52 + hi SpellCap ctermbg=17 + hi SpellLocal ctermbg=17 + hi SpellRare ctermfg=none ctermbg=none cterm=reverse + endif + hi Statement ctermfg=161 cterm=bold + hi StatusLine ctermfg=238 ctermbg=253 + hi StatusLineNC ctermfg=244 ctermbg=232 + hi StorageClass ctermfg=208 + hi Structure ctermfg=81 + hi Tag ctermfg=161 + hi Title ctermfg=166 + hi Todo ctermfg=231 ctermbg=232 cterm=bold + + hi Typedef ctermfg=81 + hi Type ctermfg=81 cterm=none + hi Underlined ctermfg=244 cterm=underline + + hi VertSplit ctermfg=244 ctermbg=232 cterm=bold + hi VisualNOS ctermbg=238 + hi Visual ctermbg=235 + hi WarningMsg ctermfg=231 ctermbg=238 cterm=bold + hi WildMenu ctermfg=81 ctermbg=16 + + hi Comment ctermfg=59 + hi CursorColumn ctermbg=234 + hi ColorColumn ctermbg=234 + hi LineNr ctermfg=250 ctermbg=234 + hi NonText ctermfg=59 + + hi SpecialKey ctermfg=59 + + if exists("g:rehash256") && g:rehash256 == 1 + hi Normal ctermfg=252 ctermbg=234 + hi CursorLine ctermbg=236 cterm=none + hi CursorLineNr ctermfg=208 cterm=none + + hi Boolean ctermfg=141 + hi Character ctermfg=222 + hi Number ctermfg=141 + hi String ctermfg=222 + hi Conditional ctermfg=197 cterm=bold + hi Constant ctermfg=141 cterm=bold + + hi DiffDelete ctermfg=125 ctermbg=233 + + hi Directory ctermfg=154 cterm=bold + hi Error ctermfg=125 ctermbg=233 + hi Exception ctermfg=154 cterm=bold + hi Float ctermfg=141 + hi Function ctermfg=154 + hi Identifier ctermfg=208 + + hi Keyword ctermfg=197 cterm=bold + hi Operator ctermfg=197 + hi PreCondit ctermfg=154 cterm=bold + hi PreProc ctermfg=154 + hi Repeat ctermfg=197 cterm=bold + + hi Statement ctermfg=197 cterm=bold + hi Tag ctermfg=197 + hi Title ctermfg=203 + hi Visual ctermbg=238 + + hi Comment ctermfg=244 + hi LineNr ctermfg=239 ctermbg=235 + hi NonText ctermfg=239 + hi SpecialKey ctermfg=239 + endif +end diff --git a/colors/onedark.vim b/colors/onedark.vim new file mode 160000 index 0000000..a9225db --- /dev/null +++ b/colors/onedark.vim @@ -0,0 +1 @@ +Subproject commit a9225db0fd9a2511dbb50d1a77f641411e959db1 diff --git a/plugins/autoclose b/plugins/autoclose index 4dfe50a..a9a3b73 160000 --- a/plugins/autoclose +++ b/plugins/autoclose @@ -1 +1 @@ -Subproject commit 4dfe50a95093da3488a0c0b0928abb591b1cb403 +Subproject commit a9a3b7384657bc1f60a963fd6c08c63fc48d61c3 diff --git a/plugins/autocomplpop b/plugins/autocomplpop new file mode 160000 index 0000000..5ceb2df --- /dev/null +++ b/plugins/autocomplpop @@ -0,0 +1 @@ +Subproject commit 5ceb2dfd368b36af029fabaed1bef3c5c4306d34 diff --git a/plugins/closetag b/plugins/closetag new file mode 160000 index 0000000..a52525b --- /dev/null +++ b/plugins/closetag @@ -0,0 +1 @@ +Subproject commit a52525b7220bb28309d1905108e9e8914fdb4112 diff --git a/plugins/cpp-complete b/plugins/cpp-complete new file mode 160000 index 0000000..2fac015 --- /dev/null +++ b/plugins/cpp-complete @@ -0,0 +1 @@ +Subproject commit 2fac015957895dffa6b298e3c028ac30560d015b diff --git a/plugins/detectindent b/plugins/detectindent new file mode 160000 index 0000000..c09ab6e --- /dev/null +++ b/plugins/detectindent @@ -0,0 +1 @@ +Subproject commit c09ab6effc29ef913c531816eb980460f8dc9ed2 diff --git a/plugins/easytags b/plugins/easytags new file mode 160000 index 0000000..72a8753 --- /dev/null +++ b/plugins/easytags @@ -0,0 +1 @@ +Subproject commit 72a8753b5d0a951e547c51b13633f680a95b5483 diff --git a/plugins/endwise b/plugins/endwise index 86e1d4a..f67d022 160000 --- a/plugins/endwise +++ b/plugins/endwise @@ -1 +1 @@ -Subproject commit 86e1d4ab9192245ae83831f073c0452f3b7baba8 +Subproject commit f67d022169bd04d3c000f47b1c03bfcbc4209470 diff --git a/plugins/fugitive b/plugins/fugitive index dba7bad..80ef196 160000 --- a/plugins/fugitive +++ b/plugins/fugitive @@ -1 +1 @@ -Subproject commit dba7bad83629ade30548c95c6cd88440603aad49 +Subproject commit 80ef19665a707aa8947dd9e5b8f82cbcec2f7b74 diff --git a/plugins/fzf.vim b/plugins/fzf.vim new file mode 160000 index 0000000..359a80e --- /dev/null +++ b/plugins/fzf.vim @@ -0,0 +1 @@ +Subproject commit 359a80e3a34aacbd5257713b6a88aa085337166f diff --git a/plugins/html5 b/plugins/html5 new file mode 160000 index 0000000..3db896b --- /dev/null +++ b/plugins/html5 @@ -0,0 +1 @@ +Subproject commit 3db896baa26839b866db3db5d8997cc830874a24 diff --git a/plugins/javascript b/plugins/javascript index 9990a76..b6c8c84 160000 --- a/plugins/javascript +++ b/plugins/javascript @@ -1 +1 @@ -Subproject commit 9990a767695c78a44611ce33fb2dbc25c83d8827 +Subproject commit b6c8c8419240bdd29b5eb51a47d488fd390deed5 diff --git a/plugins/jcommenter/README b/plugins/jcommenter/README new file mode 100644 index 0000000..7fbd60a --- /dev/null +++ b/plugins/jcommenter/README @@ -0,0 +1,17 @@ +This is a mirror of http://www.vim.org/scripts/script.php?script_id=20 + +Updated 29.12.2002 KB + +Description: +Generates JavaDoc (and some other) comments for java-sources. This is triggered by executing the JCommentWriter()-function while the cursor is over something meaningfull, or if a selection exists, the selected text is parsed and the comment template is generated based on that. + +The following comments are generated (in the appropriate situations): +1. File comments: user specifies the template, generated when the cursor is on the first line of the file. +2. Class comments: generated when on top of a class declaration +3. Method comments: generated when on top of a metod declaration. @return, @params, and @throws are generated, if applicable. If executed on a method declaration which already has JavaDoc-comments, updates the javadoc-comments by removing/adding tags as needed. +4. Field comments. Simply adds an empty JavaDoc-comment template above the field declaration +5. Copy @ -tags. When executed on @something, creates a tag with the same name directly above the line the cursor is currently on. +6. @throws for RuntimeExceptions. When executed on a line containing something like "throw new RuntimeException()", a @throws-tag is added to the previous JavaDoc-comment. +7. Block-end comments. When executed on a line containing a '}'-character and possibly some whitespace (but nothing else), generates a one-line-comment describing what block the '}' is terminating. For example, the comment for "aVeryLongMethod" is "// END: aVeryLongMethod". + +There are a bunch of other functions to support the comment generation (see the start of the script for full documentation). The style of the comment templates is configurable (see the file for configuration and description of the options) diff --git a/plugins/jcommenter/plugin/jcommenter.vim b/plugins/jcommenter/plugin/jcommenter.vim new file mode 100644 index 0000000..3110ecc --- /dev/null +++ b/plugins/jcommenter/plugin/jcommenter.vim @@ -0,0 +1,1250 @@ +" NOTE: Here begins the configuration script for the JCommenter. Later on this +" same file you can find the real script. +" It is a good idea to copy-paste the configuration part to another file, as +" you might want to preserve it for the next version (remember to add +" the new options!). +" See below for the real script description + +" --- cut here (configuration) --- + +" Configuration file for jcommenter +" +" Copy the necessary contents from this file to your .vimrc, or modify this +" file and add a source command to vimrc to read this file. +" +" The initial settings correspond with Sun's coding conventions. + + +" map the commenter: +map :call JCommentWriter() +imap :call JCommentWriter() + +" map searching for invalid comments. meta-n for next invalid comment, meta-p +" for previous. "Invalid" in this case means that the "main" comments are missing +" or the tag description is missing. Handy when searching for missing comments +" or when jumping to next tag (no need to use cursor keys (yuck!) or quit insert +" mode). +map :call SearchInvalidComment(0) +imap :call SearchInvalidComment(0)a +map :call SearchInvalidComment(1) +imap :call SearchInvalidComment(1)a + + +" modeline: +let b:jcommenter_modeline = "/* vim: set " . (&et ? "et" : "noet") . " sw=" . &sw . " ts=" . &ts . ": */" +. +" A way to automate the creation of the comments. Works only if the +" class/method declaration is on one row. Comments are generated when the +" beginning '{' is entered, if the proper function/class declaration is found. +" Should work independet of the location of the '{'. Recognizing whether the +" '{' starts a class/method or something else might fail, and comments might +" be generated for example for an 'if' clause. Has not happened yet, though. +" Uncomment to activate: +"imap { {:call search('\w', 'b'):call ConditionalWriter()0:call search('{')a + +" a nice trick: +" If you type '}-' and a space/enter/esc, jcommenter will be +" automatically called on the function/class declaration whose end the '}' is: +iabbrev }- }h%?\w:nohl:call JCommentWriter() + +" Move cursor to the place where inserting comments supposedly should start +let b:jcommenter_move_cursor = 1 + +" Defines whether to move the cursor to the line which has "/**", or the line +" after that (effective only if b:jcommenter_move_cursor is enabled) +let b:jcommenter_description_starts_from_first_line = 0 + +" Start insert mode after calling the commenter. Effective only if +" b:jcommenter_move_cursor is enabled. +let b:jcommenter_autostart_insert_mode = 1 + +" The number of empty rows (containing only the star) to be added for the +" description of the method +let b:jcommenter_method_description_space = 2 + +" The number of empty rows (containing only the star) to be added for the´ +" description of the field. Can be also -1, which means that "/** */" is added +" above the field declaration +let b:jcommenter_field_description_space = 1 + +" The number of empty rows (containing only the star) to be added for the +" description of the class +let b:jcommenter_class_description_space = 2 + +" If this option is enabled, and a method has no exceptions, parameters or +" return value, the space for the description of that method is allways one +" row. This is handy if you want to keep an empty line between the description +" and the tags, as is defined in Sun's java code conventions +let b:jcommenter_smart_method_description_spacing = 1 + +" the default content for the author-tag of class-comments. Leave empty to add +" just the empty tag, or outcomment to prevent author tag generation +let b:jcommenter_class_author = '' + +" the default content for the version-tag of class-comments. Leave empty to add +" just the empty tag, or outcomment to prevent version tag generation +let b:jcommenter_class_version = '' + +" The default author added to the file comments. leave empty to add just the +" field where the autor can be added, or outcomment to remove it. +let b:jcommenter_file_author = '' + +" The default copyright holder added to the file comments. leave empty to +" add just the field where the copyright info can be added, or outcomment +" to remove it. +let b:jcommenter_file_copyright = '' + +" Change this to true, if you want to use "@exception" instead of "@throws". +let b:jcommenter_use_exception_tag = 0 + +" set to true if you don't like the automatically added "created"-time +let b:jcommenter_file_noautotime = 0 + +" define whether jcommenter tries to parse and update the existing Doc-comments +" on the item it was executed on. If this feature is disabled, a completely new +" comment-template is written +let b:jcommenter_update_comments = 1 + +" If you want to put some text where the parameter text, return text etc. would +" normally go, uncomment and add the wanted text to these variables (this feature +" is considered "unsupported", which means it will not work perfectly with every +" other aspect of this script. For example, this will break the logic used to +" find "invalid" comments, see mappings above): +"let b:jcommenter_default_param = '' +"let b:jcommenter_default_return = '' +"let b:jcommenter_default_throw = '' + +" Another "unsupported" feature: define the number of lines added after each +" "tag-group" (except exceptions, which is often the last group). does not work +" well with comment updating currently: +"let b:jcommenter_tag_space = 1 + + +" define wheter jcommenter should remove old tags (eg. if the return value was +" changed from int to void). Will not work for exceptions, since it should not +" remove RuntimeExceptions, and recognizing whether an exception is RTE is very +" hard. +" This feature is not throughly tested, and might delete something it was not +" supposed to, so use with care. Only applicable if +" b:jcommenter_update_comments is enabled. +let b:jcommenter_remove_tags_on_update = 1 + +" Whether to prepend an empty line before the generated comment, if the +" line just above the comment would otherwise be non-empty. +let b:jcommenter_add_empty_line = 1 + +" Uncomment and modify if you're not happy with the default file +" comment-template: +"function! JCommenter_OwnFileComments() +" call append(0, '/* File name : ' . bufname("%")) +" call append(1, ' * authors : ') +" call append(2, ' * created : ' . strftime("%c")) +" call append(3, ' *') +" call append(4, ' */') +"endfunction + + +" --- cut here (configuration) --- + +" File: jcommenter.vim +" Summary: Functions for documenting java-code +" Author: Kalle Björklid +" Last Modified: 29.12.2002 +" Version: 1.3.1 +" Modifications: +" 1.3.1 : Fixed two bugs concerning the modifications of 1.3-version. +" 1.3 : Added check to see whether the script is already loaded +" Option to have an empty line automatically added before the +" generated comment if there was none previously. See config +" ("b:jcommenter_add_empty_line"). +" 1.2.1 : When executed on last line (must be empty), modeline gets generated. +" Option to have default @return, @param etc. values. see config. +" Option to have space between "Tag groups" +" 1.2 : Complete method comment updating. Now removes '@param'-tags +" if the parameter does not exist in the method header. +" Set "b:jcommenter_remove_tags_on_update" to true if you want to +" use this option. Exceptions will not get removed ever, since +" determining whether they are RuntimeExceptions or not is very +" hard. +" If executed on a string like "throw new RuntimeException()", a +" @throws tag (or @exception) will be added to the previous +" Javadoc comments. +" Corrected a problem where updating didn't work if a new parameter's +" name began the same way than an existing one's. +" Now behaves correctly even when "extra stuff" is included in the +" range. +" Added mapping for insert mode to the config-file. +" Added an abbreviation (see config file). Quite nice, I think. +" Added a new public function for searching for "invalid" comments. +" See config-file for description and mappings. +" Added end-function/class/etc commenting: if you call the commenter +" on a line that contains only a closing '}', the function/class +" name is written as a comment after that. Handy when you have +" a long method/class declaration. +" A way to automatically generate the comments when the '{'-character +" after the class/method declaration. See config-file for mapping +" (need to be uncommented to be active). +" 1.12: Fixed a bug where all methods were interpreted as constructors +" if 'ignorecase' was on. Thanks to David Menuhin for debugging this. +" 1.11: Fixed a bug where the end part of the whole buffer was sometimes +" deleted when updating w/ the b:jcommenter_remove_tags_on_update +" enabled. +" 1.1 : Can now choose between '@throws' and '@exception' tags. +" When executed on single-line comments ("/** blah blah */") expands +" them into multiline comments preserving the text +" Partial method documentation comment updating (see below for +" description) At this point, there's a behavoiur fault where +" single-line comments get expanded even if there's no tags to add. +" 1.0 : Did a complete rewrite of the script-code (this is the main reason +" for the version-number leap) +" A separate config-file, which should be modified to reflect the +" user's preferences +" More variables for better customization +" Due to the rewrite, should now be more robust (allthough new bugs +" may have been introduced during the process) +" Cursor movement and auto-start insert mode +" Better control over the look of the comment templates +" See installation instructions below (has changed) +" 0.4 : Recognizes now methods that have whitespaces before the '('. +" The file comments can now be completely redefined (see below for +" instructions) without editing the script. +" The comment-skeleton for fields is changed from '/** */ to correspond +" with the Sun's code conventions: +" /** +" * +" */ +" 0.3 : Added tag copying +" Recognizes interfaces (same as classes) +" 0.21: Improved the java-method recognition. +" 0.2 : initial public release. +" +" Tested on gvim 6.0 on Win32 +" +" Description: Functions for automatically generating JavaDoc compatible +" documentation for java source-files. +" The JCommentWriter() can produce four kinds of comments depending on the +" current line/range. +" - File comments. When the JCommentWriter()-function is called on the first +" line of the file, a template for file comments is created. It looks like +" this: +" +" /* Filename : +" * Author : +" * Summary : +" * Version : +" * Created : +" */ +" +" The file name and 'Created'-date are automatically filled. The author- +" field is filled with the contents of 'b:jcommenter_file_author'-variable. +" The automated date insertion can be prevented by defining the +" 'b:jcommenter_file_noautotime'-variable. +" You can redefine completely the file comments-writer-function. See the +" configuration script for more info +" +" - Class comments. When the JCommentWriter()-function is called on the +" header of a class, a template for class comments is created. It looks like +" this: +" +" /** +" * +" * @author +" * @version +" */ +" public class ClassName { ... +" +" The @author-field is automatically filled with the contents of the +" 'b:jcommenter_class_author'-variable. +" The @version-field is automatically filled with the contents of the +" 'b:jcommenter_class_def_version'-variable +" - Method comments. JCommentWriter()-function automatically generates +" the template for method comments if it is called on a header of a +" method. The JavaDoc-tags are automatically generated by detecting +" the parameter names, return value and exceptions that are declared +" in the header of the method. An example: +" +" /** +" * +" * @param numbers +" * @param str +" * @return +" * @throws IOException +" * @throws NumberFormatException +" */ +" public String [] method(Integer[] numbers, String str) throws +" IOException, NumberFormatException { +" +" Note: since the method header is on two lines, you need to specify +" the range (include everything before the '{', or ';' if the method is +" abstract). This can be done simply with line-wise visual selection. +" - Updating method comments (since 1.1): +" If executed on a method declaration that allready has Doc-comments, +" you can let jcommenter to try to parse the existing comments and +" add the tags that are new (for example, if you have declared another +" exception to be thrown) to the comments. At this time (version 1.1) +" the removing of old tags is limited to the @return-tag. +" See the config-script for variables concerning this feature. +" - Field comments. Appends this above the field declaration: +" /** +" * +" */ +" Can also be changed to '/** */', see the config-file. +" - Extending single-line comments into mulitline: +" When executed on a line like '/** blah blah blah */, the result is: +" /** +" * blah blah blah +" */ +" - When executed on an existing JavaDoc tag, copy that tag under that line. +" For example, when executed on the following line: +" * @throws IOException If cannot read file +" the result is: +" * @throws IOException If cannot read file +" * @throws +" Not that life changing, but quite nice when you want to document those +" RuntimeExceptions, or need to add another paramter. +" - RuntimeException tag adding. If you execute the commenter on a line +" like "throw new RuntimeException()", the previous doc-comments are +" searched, and a tag for the RuntimeException is added there. +" - Function/class/etc. end commenting. If you execute the commenter +" on a line containing only a closing '}' (and mabye some whitespace), +" the method/class name is added as a comment after the bracet: +" public aVeryLongMethod() { +" ... +" } // END: aVeryLongMethod +" - Cycle through incomplete comments using SearchInvalidComment-method. +" If you use the default mappings, use to go to next incomplete +" comment, and to go to previous one. Handy when finding +" incomplete comments, and completing a template just generated (don't +" have to quit insert mode or use arrow keys). +" - When executed on last line of the file (which must be empty) a +" modeline gets generated. See config-file for format. +" +" Installation: +" +" 0. (optional) copy-paste the configuration-part above to another file +" (save it somewhere) +" 1. Edit the config-section. It is commented, so I won't explain the +" options here). +" 2. Put something like +" aurocmd FileType java source $VIM/macros/jcommenter.vim +" autocmd FileType java source $VIM/macros/jcommenter_config.vim +" to your vimrc. Note that loading the config-part after the actual +" script guarantees that your options are used instad of the script +" defaults. +" +" Usage: +" If you didn't change the mapping specified in the config-file, you can +" can trigger the comment-generation by pressing Alt-c (or "Meta-c"). As +" described above, the cursor must be on the first line or on the same line +" as the method/class/attribute declaration in order to achieve something +" useful. If the declaration extends to several lines, the range must be +" specified. Range should include everything from the declaration that +" comes before the '{' or ';'. Everything after either of those characters +" is ignored, so linewise selection is a handy way to do this +" +" Notes: +" - If a method name starts with an uppercase letter, it is handled as a +" constructor (no @return-tag is generated) +" +" TODO: search for function etc not commented +" TODO: support for the umlaut-chars etc. that can be also used in java +" TODO: Inner classes/interfaces... +" TODO: sort exceptions alphabetically (see +" http://java.sun.com/j2se/javadoc/writingdoccomments/index.html) +" TODO: comment the script +" +" Comments: +" Send any comments or bugreports to bjorklid@st.jyu.fi +" Happy coding! ;-) +"===================================================================== + + +" THE SCRIPT + +" Load only once: +if exists("b:did_javacom") + finish +endif +let b:did_javacom = 1 + +" varible that tells what is put before the written string when using +" the AppendStr-function. +let s:indent = '' + +" The string that includes the text of the line on which the commenter +" was called, or the whole range. This is what is parsed. +let s:combinedString = '' + +let s:rangeStart = 1 " line on which the range started +let s:rangeEnd = 1 " line on which the range ended + +let s:defaultMethodDescriptionSpace = 1 +let s:defaultFieldDescriptionSpace = 1 +let s:defaultClassDescriptionSpace = 1 + +let s:linesAppended = 0 " this counter is increased when the AppendStr-method + " is called. + +let s:docCommentStart = -1 +let s:docCommentEnd = -1 + +let s:defaultParamText = (exists('b:jcommenter_default_param')) ? b:jcommenter_default_param : '' +let s:defaultReturnText = (exists('b:jcommenter_default_return')) ? b:jcommenter_default_return : '' +let s:defaultThrowText = (exists('b:jcommenter_default_throw')) ? b:jcommenter_default_throw : '' + +" =================================================== +" Public functions +" =================================================== + +function! JCommentWriter() range + let s:oldICValue = &ignorecase + let &ignorecase = 0 + + let s:rangeStart = a:firstline + let s:rangeEnd = a:lastline + let s:combinedString = s:GetCombinedString(s:rangeStart, s:rangeEnd) + + + let s:debugstring = '' + + if s:IsFileComments() + call s:WriteFileComments() + elseif s:IsModeLine() + call s:WriteModeLine() + elseif s:IsFunctionEnd() + call s:WriteFunctionEndComments() + elseif s:IsExceptionDeclaration() + call s:WriteFoundException() + elseif s:IsMethod() + let s:debugstring = s:debugstring . 'isMethod ' + call s:WriteMethodComments() + if s:method_comment_update_only == 0 + call s:AddEmpty() + endif + elseif s:IsClass() + call s:WriteClassComments() + call s:AddEmpty() + elseif s:IsSinglelineComment() + call s:ExpandSinglelineComments(s:rangeStart) + elseif s:IsCommentTag() + call s:WriteCopyOfTag() + elseif s:IsVariable() + call s:WriteFieldComments() + call s:AddEmpty() + else + call s:Message('Nothing to do') + endif + + " echo s:debugstring + + let &ignorecase = s:oldICValue + let b:jcommenter_lines_appended = s:linesAppended +endfunction + +fun! s:AddEmpty() + if exists("b:jcommenter_add_empty_line") && b:jcommenter_add_empty_line + if getline(a:firstline - 2) !~ '^\s*$' + let s:appendPos = a:firstline - 2 + call s:AppendStr("") + endif + endif +endfun + + +" =================================================== +" The update functions for method comments +" =================================================== + +function! s:UpdateAllTags() + let s:indent = s:GetIndentation(s:combinedString) + call s:UpdateParameters() + call s:UpdateReturnValue() + call s:UpdateExceptions() +endfunction + +function! s:UpdateExceptions() + let exceptionName = s:GetNextThrowName() + let seeTagPos = s:FindTag(s:docCommentStart, s:docCommentEnd, 'see', '') + if seeTagPos > -1 + let tagAppendPos = seeTagPos - 1 + else + let tagAppendPos = s:docCommentEnd - 1 + endif + while exceptionName != '' + let tagPos = s:FindTag(s:docCommentStart, s:docCommentEnd, 'throws', exceptionName) + if tagPos < 0 + let tagPos = s:FindTag(s:docCommentStart, s:docCommentEnd, 'exception', exceptionName) + endif + if tagPos > -1 + let tagAppendPos = tagPos + let exceptionName = s:GetNextThrowName() + continue + endif + let s:appendPos = tagAppendPos + call s:AppendStr(' * @throws ' . exceptionName . ' ' . s:defaultThrowText) + call s:MarkUpdateMade(tagAppendPos + 1) + let s:docCommentEnd = s:docCommentEnd + 1 + let tagAppendPos = tagAppendPos + 1 + let tagName = s:GetNextParameterName() + endwhile +endfunction + +function! s:UpdateReturnValue() + if s:method_returnValue == '' + if exists("b:jcommenter_remove_tags_on_update") && b:jcommenter_remove_tags_on_update + call s:RemoveTag(s:docCommentStart, s:docCommentEnd, 'return', '') + endif + return + endif + let returnTagPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'return') + if returnTagPos > -1 && s:method_returnValue != '' + return + endif + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'throws') - 1 + if tagAppendPos < 0 + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'exception') - 1 + endif + if tagAppendPos < 0 + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'see') - 1 + endif + if tagAppendPos < 0 + let tagAppendPos = s:docCommentEnd - 1 + endif + let s:appendPos = tagAppendPos + call s:AppendStr(' * @return ' . s:defaultReturnText) + call s:MarkUpdateMade(tagAppendPos + 1) + let s:docCommentEnd = s:docCommentEnd + 1 +endfunction + +function! s:RemoveNonExistingParameters() + call s:ResolveMethodParams(s:combinedString) + let paramlist = s:method_paramList + let pos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'param') + let Start = pos + + while pos > 0 + let line = getline(pos) + let tagParam = substitute(line, '^\s*\(\*\s*\)\=@[a-zA-Z]*\s\+\(\S*\).*', '\2', '') + + let paramExists = 0 + let existingParam = s:GetNextParameterName() + while existingParam != '' + + if existingParam == tagParam + let paramExists = 1 + break + endif + let existingParam = s:GetNextParameterName() + endwhile + if paramExists == 0 + call s:RemoveTag(Start, s:docCommentEnd, 'param', tagParam) + else + let Start = Start + 1 + endif + + let s:method_paramList = paramlist + let pos = s:FindFirstTag(Start, s:docCommentEnd, 'param') + endwhile +endfunction + +function! s:UpdateParameters() + let tagName = s:GetNextParameterName() + + "Try to find out where the tags that might be added should be written. + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'param') - 1 + if tagAppendPos < 0 + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'return') - 1 + endif + if tagAppendPos < 0 + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'throws') - 1 + endif + if tagAppendPos < 0 + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'exception') - 1 + endif + if tagAppendPos < 0 + let tagAppendPos = s:FindFirstTag(s:docCommentStart, s:docCommentEnd, 'see') - 1 + endif + if tagAppendPos < 0 + let tagAppendPos = s:docCommentEnd - 1 + endif + + while tagName != '' + let tagPos = s:FindTag(s:docCommentStart, s:docCommentEnd, 'param', tagName) + if tagPos > -1 + let tagAppendPos = tagPos + let tagName = s:GetNextParameterName() + continue + endif + let s:appendPos = tagAppendPos + call s:AppendStr(' * @param ' . tagName . ' ' . s:defaultParamText) + call s:MarkUpdateMade(tagAppendPos + 1) + let s:docCommentEnd = s:docCommentEnd + 1 + let tagAppendPos = tagAppendPos + 1 + let tagName = s:GetNextParameterName() + endwhile + + if exists("b:jcommenter_remove_tags_on_update") && b:jcommenter_remove_tags_on_update + call s:RemoveNonExistingParameters() + endif +endfunction + +function! s:FindTag(rangeStart, rangeEnd, tagName, tagParam) + let i = a:rangeStart + while i <= a:rangeEnd + if a:tagParam != '' + if getline(i) =~ '^\s*\(\*\s*\)\=@' . a:tagName . '\s\+' . a:tagParam . '\(\s\|$\)' + return i + endif + else + if getline(i) =~ '^\s*\(\*\s*\)\=@' . a:tagName . '\(\s\|$\)' + return i + endif + endif + let i = i + 1 + endwhile + return -1 +endfunction + +function! s:FindFirstTag(rangeStart, rangeEnd, tagName) + let i = a:rangeStart + while i <= a:rangeEnd + if getline(i) =~ '^\s*\(\*\s*\)\=@' . a:tagName . '\(\s\|$\)' + return i + endif + let i = i + 1 + endwhile + return -1 +endfunction + +function! s:FindAnyTag(rangeStart, rangeEnd) + let i = a:rangeStart + while i <= a:rangeEnd + if getline(i) =~ '^\s*\(\*\s*\)\=@' + return i + endif + let i = i + 1 + endwhile + return -1 +endfunction + +function! s:RemoveTag(rangeStart, rangeEnd, tagName, tagParam) + let tagStartPos = s:FindTag(a:rangeStart, a:rangeEnd, a:tagName, a:tagParam) + if tagStartPos == -1 + return 0 + endif + let tagEndPos = s:FindAnyTag(tagStartPos + 1, a:rangeEnd) + if tagEndPos == -1 + let tagEndPos = s:docCommentEnd - 1 + endif + let linesToDelete = tagEndPos - tagStartPos + exe "normal " . tagStartPos . "G" . linesToDelete . "dd" + let s:docCommentEnd = s:docCommentEnd - linesToDelete +endfunction + +function! s:MarkUpdateMade(linenum) + if s:firstUpdatedTagLine == -1 || a:linenum < s:firstUpdatedTagLine + let s:firstUpdatedTagLine = a:linenum + endif +endfunction + +" =================================================== +" From single line to multi line +" =================================================== + +function! s:ExpandSinglelineCommentsEx(line, space) + let str = getline(a:line) + let singleLinePattern = '^\s*/\*\*\s*\(.*\)\*/\s*$' + if str !~ singleLinePattern + return + endif + let s:indent = s:GetIndentation(str) + let str = substitute(str, singleLinePattern, '\1', '') + exe "normal " . a:line . "Gdd" + let s:appendPos = a:line - 1 + call s:AppendStr('/**') + call s:AppendStr(' * ' . str) + let i = 0 + while a:space > i + call s:AppendStr(' * ') + let i = i + 1 + endwhile + call s:AppendStr(' */') + let s:docCommentStart = a:line + let s:docCommentEnd = a:line + 2 + a:space +endfunction + +function! s:ExpandSinglelineComments(line) + call s:ExpandSinglelineCommentsEx(a:line, 0) +endfunction + +" =================================================== +" Functions for writing the comments +" =================================================== + +function! s:WriteMethodComments() + call s:ResolveMethodParams(s:combinedString) + let s:appendPos = s:rangeStart - 1 + let s:indent = s:method_indent + let s:linesAppended = 0 + + let existingDocCommentType = s:HasDocComments() + let s:method_comment_update_only = 0 + + if existingDocCommentType && exists("b:jcommenter_update_comments") && b:jcommenter_update_comments + let s:method_comment_update_only = 1 + if existingDocCommentType == 1 + call s:ExpandSinglelineCommentsEx(s:singleLineCommentPos, 1) + endif + let s:firstUpdatedTagLine = -1 + call s:UpdateAllTags() + if exists("b:jcommenter_move_cursor") && b:jcommenter_move_cursor && s:firstUpdatedTagLine != -1 + exe "normal " . s:firstUpdatedTagLine . "G$" + if exists("b:jcommenter_autostart_insert_mode") && b:jcommenter_autostart_insert_mode + startinsert! + endif + endif + return + endif + + if exists("b:jcommenter_method_description_space") + let descriptionSpace = b:jcommenter_method_description_space + else + let descriptionSpace = s:defaultMethodDescriptionSpace + endif + + call s:AppendStr('/** ') + + let param = s:GetNextParameterName() + let exception = s:GetNextThrowName() + + if param == '' && s:method_returnValue == '' && exception == '' && exists("b:jcommenter_smart_method_description_spacing") && b:jcommenter_smart_method_description_spacing + call s:AppendStars(1) + else + call s:AppendStars(descriptionSpace) + endif + + let hadParam = (param != '') + + while param != '' + call s:AppendStr(' * @param ' . param . ' ' . s:defaultParamText) + let param = s:GetNextParameterName() + endwhile + + if exists('b:jcommenter_tag_space') && b:jcommenter_tag_space && hadParam + call s:AppendStars(b:jcommenter_tag_space) + endif + + let hadReturn = (s:method_returnValue != '') + + if s:method_returnValue != '' + call s:AppendStr(' * @return ' . s:defaultReturnText) + let s:debugstring = s:debugstring . 'wroteReturnTag ' + endif + + if exists('b:jcommenter_tag_space') && b:jcommenter_tag_space && hadReturn + call s:AppendStars(b:jcommenter_tag_space) + endif + + if exists("b:jcommenter_use_exception_tag") && b:jcommenter_use_exception_tag + let exTag = '@exception ' + else + let exTag = '@throws ' + endif + +" let hadException = (exception != '') + + while exception != '' + call s:AppendStr(' * ' . exTag . exception . ' ' . s:defaultThrowText) + let exception = s:GetNextThrowName() + endwhile + + call s:AppendStr(' */') + + call s:MoveCursor() + +endfunction + +function! s:WriteFunctionEndComments() + normal 0 + if (getline(".")[0] != '}') + call search('}') " won't work if the '}' is the first char (thus the 'if') + endif + normal % + " Now we are on the '{' mark. Next we go backwards to the line on which the + " class/method declaration seems to be on: + call search('\%(^\|.*\s\)\%(\%(\(\h\w*\)\s*(\)\|\%(\%(class\|interface\)\s\+\(\u\w*\)\)\).*', 'b') + let header = getline(".") + let name = substitute(header, '\%(^\|.*\s\)\%(\%(\(\h\w*\)\s*(\)\|\%(\%(class\|interface\)\s\+\(\u\w*\)\)\).*', '\1\2', '') + call search('{') " go back to the end... + normal % + exe 'normal a // END: ' . name +endfunction + +function! s:WriteFoundException() + let exceptionName = substitute(s:combinedString, '.*\ 1 + let linenum = linenum - 1 + let str = getline(linenum) + endwhile + if str !~ '\*/\s*$' || str =~ '/\*\*.*\*/' + return 0 + endif + let s:docCommentEnd = linenum + let linenum = linenum - 1 + let str = getline(linenum) + while str !~ '\(/\*\|\*/\)' && linenum >= 1 + let linenum = linenum - 1 + let str = getline(linenum) + endwhile + if str =~ '^\s*/\*\*' + let s:docCommentStart = linenum + return 1 + else + let s:docCommentStart = -1 + let s:docCommentEnd = -1 + return 0 + endif +endfunction + + +function! s:SearchPrevDocComments() + let linenum = s:rangeStart - 1 + while 1 + let str = getline(linenum) + while str !~ '\*/' && linenum > 1 + let linenum = linenum - 1 + let str = getline(linenum) + endwhile + if linenum <= 1 + return 0 + endif + let s:docCommentEnd = linenum + let linenum = linenum - 1 + let str = getline(linenum) + while str !~ '\(/\*\|\*/\)' && linenum >= 1 + let linenum = linenum - 1 + let str = getline(linenum) + endwhile + if str =~ '^\s*/\*\*' + let s:docCommentStart = linenum + return 1 + else + if linenum == 1 + let s:docCommentStart = -1 + let s:docCommentEnd = -1 + return 0 + endif + endif + endwhile +endfunction + +function! s:HasSingleLineDocComments() + let linenum = s:rangeStart - 1 + let str = getline(linenum) + while str =~ '^\s*$' && linenum > 1 + let linenum = linenum - 1 + let str = getline(linenum) + endwhile + if str =~ '^\s*/\*\*.*\*/\s*$' + let s:singleLineCommentPos = linenum + let s:docCommentStart = linenum + let s:docCommentEnd = linenum + return 1 + endif + return 0 +endfunction + +function! s:HasDocComments() + if s:HasSingleLineDocComments() + return 1 + elseif s:HasMultilineDocComments() + return 2 + endif +endfunction + +" =================================================== +" Utility functions +" =================================================== + +function! s:GetIndentation(string) + return substitute(a:string, '^\(\s*\).*', '\1', '') +endfunction + +" returns one string combined from the strings on the given range. +function! s:GetCombinedString(rangeStart, rangeEnd) + let line = a:rangeStart + let combinedString = getline(line) + + while line < a:rangeEnd + let line = line + 1 + let combinedString = combinedString . ' ' . getline(line) + endwhile + + return substitute(combinedString, '^\([^;{]*[;{]\=\).*', '\1', '') +endfunction + +function! s:AppendStars(amount) + let i = a:amount + while i > 0 + call s:AppendStr(' * ') + let i = i - 1 + endwhile +endfunction + + +function! s:MoveCursorToEOL(line) + exe "normal " . a:line . "G$" +endfunction + +function! s:MoveCursor() + if !exists("b:jcommenter_move_cursor") + return + endif + if !b:jcommenter_move_cursor + return + endif + let startInsert = exists("b:jcommenter_autostart_insert_mode") && b:jcommenter_autostart_insert_mode + if exists("b:jcommenter_description_starts_from_first_line") && b:jcommenter_description_starts_from_first_line + call s:MoveCursorToEOL(s:rangeStart) + else + call s:MoveCursorToEOL(s:rangeStart + 1) + endif + if startInsert + startinsert + endif +endfunction + +let s:appendPos = 1 + +" A function for appending strings to the buffer. +" First set the 's:appendPos', then call this function repeatedly to append +" strings after that position. +function! s:AppendStr(string) + call append(s:appendPos, s:indent . a:string) + let s:appendPos = s:appendPos + 1 + let s:linesAppended = s:linesAppended + 1 +endfunction + +function! s:Trim(string) + return substitute(a:string, '^\s*\(.\{-}\)\s*$', '\1', '') +endfunction + +function! s:Message(string) + echo '[JCommenter] ' . a:string +endfunction + +"=============================================== +let s:noCommentTrunk = '^\s*\/\*\*\s*\n\%(\s*\*\s*\n\)*\%(\s*\*\s*@\|\s*\*\/\)' +let s:noParamTagComment = '^\s*\*\s*@\%(param\|throws\|exception\)\%(\s\+\h\w*\)\=\s*$' +let s:noTagComment = '^\s*\*\s*@\%(return\|see\|version\|since\)\s*$' +let s:invalComments = '\%(' . s:noCommentTrunk . '\)\|\%(' . s:noParamTagComment . '\)\|\%(' . s:noTagComment . '\)' + + +fun! SearchInvalidComment(backwards) + let param = a:backwards ? "wb" : "w" + if a:backwards + if !b:jcommenter_description_starts_from_first_line && getline(".") =~ '^\s*\*\s*$' + normal k + endif + normal k$ + endif + let result = search(s:invalComments, param) + if result > 0 + if !b:jcommenter_description_starts_from_first_line + let isTrunk = (getline(".") =~ '^\s*\/\*\*') + if isTrunk + normal j + endif + endif + normal $zz + else + call s:Message('No invalid comments found') + endif +endfun + +function! ConditionalWriter() + let line = getline(".") + let doDoc = (line =~ '\(^\|\s\)\h\w*\s\+\h\w*\s*(.*)') " Methods (allways have ret. value) + let doDoc2 = (line =~ '^\s*\u\w*\s*(.*)') " Constructors (allways begin w/ uppercase letter) + let doDoc3 = (line =~ '^\s*\%([a-z]\+\s\+\)*class\s\+\u\w*\%(\s\+\%(implements\|extends\)\s\+.*\)\{0,2}') + if doDoc || doDoc2 || doDoc3 + let oldmove = b:jcommenter_move_cursor + let b:jcommenter_move_cursor = 0 + call JCommentWriter() + let b:jcommenter_move_cursor = oldmove + endif +endfunction + +" vim: set et sw=2 ts=2: diff --git a/plugins/js-jquery b/plugins/js-jquery new file mode 160000 index 0000000..61890d8 --- /dev/null +++ b/plugins/js-jquery @@ -0,0 +1 @@ +Subproject commit 61890d8e5ba8a873526fb91c6484aa445cc20b56 diff --git a/plugins/js-jquery-doc b/plugins/js-jquery-doc new file mode 160000 index 0000000..3293931 --- /dev/null +++ b/plugins/js-jquery-doc @@ -0,0 +1 @@ +Subproject commit 32939319b0bbf9714b3ba46fbe600a6842e96737 diff --git a/plugins/json/README.markdown b/plugins/json/README.markdown deleted file mode 100644 index 2e3f08f..0000000 --- a/plugins/json/README.markdown +++ /dev/null @@ -1,5 +0,0 @@ -json.vim -============ - -Syntax highlighting for json files, created by Jeroen Ruigrok van der Werven -and taken from [vim.org](http://www.vim.org/scripts/script.php?script_id=1945) diff --git a/plugins/json/ftdetect/json.vim b/plugins/json/ftdetect/json.vim deleted file mode 100644 index a028791..0000000 --- a/plugins/json/ftdetect/json.vim +++ /dev/null @@ -1 +0,0 @@ -autocmd BufNewFile,BufRead *.json set filetype=json foldmethod=syntax diff --git a/plugins/json/syntax/json.vim b/plugins/json/syntax/json.vim deleted file mode 100644 index f3e27ba..0000000 --- a/plugins/json/syntax/json.vim +++ /dev/null @@ -1,77 +0,0 @@ -" Vim syntax file -" Language: JSON -" Maintainer: Jeroen Ruigrok van der Werven -" Last Change: 2009-06-16 -" Version: 0.4 -" {{{1 - -" Syntax setup {{{2 -" For version 5.x: Clear all syntax items -" For version 6.x: Quit when a syntax file was already loaded - -if !exists("main_syntax") - if version < 600 - syntax clear - elseif exists("b:current_syntax") - finish - endif - let main_syntax = 'json' -endif - -" Syntax: Strings {{{2 -syn region jsonString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsonEscape -" Syntax: JSON does not allow strings with single quotes, unlike JavaScript. -syn region jsonStringSQ start=+'+ skip=+\\\\\|\\"+ end=+'+ - -" Syntax: Escape sequences {{{3 -syn match jsonEscape "\\["\\/bfnrt]" contained -syn match jsonEscape "\\u\x\{4}" contained - -" Syntax: Strings should always be enclosed with quotes. -syn match jsonNoQuotes "\<\a\+\>" - -" Syntax: Numbers {{{2 -syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" - -" Syntax: An integer part of 0 followed by other digits is not allowed. -syn match jsonNumError "-\=\<0\d\.\d*\>" - -" Syntax: Boolean {{{2 -syn keyword jsonBoolean true false - -" Syntax: Null {{{2 -syn keyword jsonNull null - -" Syntax: Braces {{{2 -syn match jsonBraces "[{}\[\]]" - -" Define the default highlighting. {{{1 -" For version 5.7 and earlier: only when not done already -" For version 5.8 and later: only when an item doesn't have highlighting yet -if version >= 508 || !exists("did_json_syn_inits") - if version < 508 - let did_json_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - HiLink jsonString String - HiLink jsonEscape Special - HiLink jsonNumber Number - HiLink jsonBraces Operator - HiLink jsonNull Function - HiLink jsonBoolean Boolean - - HiLink jsonNumError Error - HiLink jsonStringSQ Error - HiLink jsonNoQuotes Error - delcommand HiLink -endif - -let b:current_syntax = "json" -if main_syntax == 'json' - unlet main_syntax -endif - -" Vim settings {{{2 -" vim: ts=8 fdm=marker diff --git a/plugins/lightline.vim b/plugins/lightline.vim new file mode 160000 index 0000000..c9ab296 --- /dev/null +++ b/plugins/lightline.vim @@ -0,0 +1 @@ +Subproject commit c9ab296e856bed4e694180efb6ffb692cf18ed8f diff --git a/plugins/markdown b/plugins/markdown index 34e28b3..a2e123a 160000 --- a/plugins/markdown +++ b/plugins/markdown @@ -1 +1 @@ -Subproject commit 34e28b3f6f6d702ff2963b8196eccae9344ed4bc +Subproject commit a2e123a288a72efe3f800c3a90736f9d2e48ebea diff --git a/plugins/misc b/plugins/misc new file mode 160000 index 0000000..3e6b8fb --- /dev/null +++ b/plugins/misc @@ -0,0 +1 @@ +Subproject commit 3e6b8fb6f03f13434543ce1f5d24f6a5d3f34f0b diff --git a/plugins/mustache b/plugins/mustache index 68b957d..697fa02 160000 --- a/plugins/mustache +++ b/plugins/mustache @@ -1 +1 @@ -Subproject commit 68b957dabbf6d229bac5c1deea5a2eb0bd37b471 +Subproject commit 697fa0277042a028d1731d36397c42d9f182a785 diff --git a/plugins/neocomplete b/plugins/neocomplete new file mode 160000 index 0000000..66cb31e --- /dev/null +++ b/plugins/neocomplete @@ -0,0 +1 @@ +Subproject commit 66cb31ed05861608329306eb92e081b19fac22da diff --git a/plugins/nerdcommenter b/plugins/nerdcommenter index b28e7be..a4b7c04 160000 --- a/plugins/nerdcommenter +++ b/plugins/nerdcommenter @@ -1 +1 @@ -Subproject commit b28e7be63235982501ab7dd30c03ea7feef7b095 +Subproject commit a4b7c046b3d3e170c6f62a6209abfa0760d6694a diff --git a/plugins/nerdtree b/plugins/nerdtree new file mode 160000 index 0000000..496b61e --- /dev/null +++ b/plugins/nerdtree @@ -0,0 +1 @@ +Subproject commit 496b61ead1acd80128164cce5c2ff8e89c42ded2 diff --git a/plugins/php-complete b/plugins/php-complete new file mode 160000 index 0000000..d074960 --- /dev/null +++ b/plugins/php-complete @@ -0,0 +1 @@ +Subproject commit d0749608acd360f4f93342bed75020b1f4b8ec81 diff --git a/plugins/php-cs-fixer b/plugins/php-cs-fixer new file mode 160000 index 0000000..2a8a757 --- /dev/null +++ b/plugins/php-cs-fixer @@ -0,0 +1 @@ +Subproject commit 2a8a75744b05da48504b1a30b11521e62597104a diff --git a/plugins/php-namespace b/plugins/php-namespace new file mode 160000 index 0000000..8741c0a --- /dev/null +++ b/plugins/php-namespace @@ -0,0 +1 @@ +Subproject commit 8741c0a71758fc4525efa0e7b09ae5ed81522126 diff --git a/plugins/surround b/plugins/surround index d9e6bfd..fab8621 160000 --- a/plugins/surround +++ b/plugins/surround @@ -1 +1 @@ -Subproject commit d9e6bfdd902fc661c8fd58ede248ccfc3b3039d7 +Subproject commit fab8621670f71637e9960003af28365129b1dfd0 diff --git a/plugins/syntastic b/plugins/syntastic index 88dbca8..0336c35 160000 --- a/plugins/syntastic +++ b/plugins/syntastic @@ -1 +1 @@ -Subproject commit 88dbca87c80de9b7852672907f6fc9fb935f531c +Subproject commit 0336c35c0b10b46d85cdd9c3df721f978429e82c diff --git a/plugins/tabular b/plugins/tabular index b7b4d87..339091a 160000 --- a/plugins/tabular +++ b/plugins/tabular @@ -1 +1 @@ -Subproject commit b7b4d8791a50013b56c2d68b6c5708c808203b54 +Subproject commit 339091ac4dd1f17e225fe7d57b48aff55f99b23a diff --git a/plugins/vim-css-color b/plugins/vim-css-color new file mode 160000 index 0000000..1f9fe5c --- /dev/null +++ b/plugins/vim-css-color @@ -0,0 +1 @@ +Subproject commit 1f9fe5c1f9e0a6bfc41b14d070f4d878d445ae96 diff --git a/plugins/vim-json b/plugins/vim-json new file mode 160000 index 0000000..3727f08 --- /dev/null +++ b/plugins/vim-json @@ -0,0 +1 @@ +Subproject commit 3727f089410e23ae113be6222e8a08dd2613ecf2 diff --git a/plugins/vim-polyglot b/plugins/vim-polyglot new file mode 160000 index 0000000..4f3df59 --- /dev/null +++ b/plugins/vim-polyglot @@ -0,0 +1 @@ +Subproject commit 4f3df59be709bf0d5c5c67dc804fde49abdc2700 diff --git a/presets/javascript.vim b/presets/javascript.vim new file mode 100644 index 0000000..5b96f76 --- /dev/null +++ b/presets/javascript.vim @@ -0,0 +1,7 @@ +" load dependencies +call vim_kicks_ass#with_plugins(["syntastic"]) + +" load plugins for javascript +call vim_kicks_ass#with_plugins([ + \ "javascript","elzr/vim-json","js-jquery","js-jquery-doc" + \ ]) diff --git a/presets/php.vim b/presets/php.vim index e64b9f3..0bf7741 100644 --- a/presets/php.vim +++ b/presets/php.vim @@ -1,2 +1,21 @@ " php-doc : helpers for creating phpdoc -call vim_kicks_ass#with_plugins(["php-doc", "php-fix-html-indent"]) +call vim_kicks_ass#with_plugins(["php-doc","php-fix-html-indent"]) + +" add PhpDoc command and binding +com! -nargs=0 -bang PhpDoc call PhpDoc() +nnoremap d :PhpDoc + +" php-complete : autocompletion support +" enable php-complete for newer code completion code base +call vim_kicks_ass#with_plugins(["php-complete"]) +let g:phpcomplete_parse_docblock_comments = 1 + +if !executable("php-cs-fixer") + echo "Remember to install php-cs-fixer." +endif + +" php-cs-fixer : format source code using PHP Coding Standards +call vim_kicks_ass#with_plugins(["php-cs-fixer"]) + +" php-namespace : insert needed namespaces at heading of file +call vim_kicks_ass#with_plugins(["php-namespace"]) diff --git a/templates/vimrc.jgmdev b/templates/vimrc.jgmdev new file mode 100644 index 0000000..be2a2b2 --- /dev/null +++ b/templates/vimrc.jgmdev @@ -0,0 +1,349 @@ +" (_) | | (_) | | +" __ ___ _ __ ___ ______| | ___ ___| | _____ ______ __ _ ___ ___ +" \ \ / / | '_ ` _ \______| |/ / |/ __| |/ / __|______/ _` / __/ __| +" \ V /| | | | | | | | <| | (__| <\__ \ | (_| \__ \__ \ +" \_/ |_|_| |_| |_| |_|\_\_|\___|_|\_\___/ \__,_|___/___/ +" +" .vimrc used by jgmdev (github.com/jgmdev) +" +" -- based on template/vimrc +" -- based on template/vimrc.kibs + +" make sure we are in full Vim mode +set nocompatible + +" enable filetype specific plugins +filetype on +filetype plugin on +filetype indent off " disable annoying auto indentation + +" for configuration +let vim_path=expand(':p:h')."/.vim" +let $VIMHOME=vim_path + +" ------------------------------------------------------- +" CHECK REQUIRED DEPENDENCIES +" ------------------------------------------------------- +if !executable("git") + echo "Remember to install git." +endif + +if !executable("ctags") && !executable("phpctags") + echo "Remember to install phpctags or ctags for autocomplete support." +endif + +if !executable("fzf") || !executable("rg") + echo "Remember to install fzf and ripgrep for file searching." +endif + +if !executable("php-cs-fixer") + echo "Remember to install php-cs-fixer." +endif + +" ------------------------------------------------------- +" LOAD PLUGINS +" ------------------------------------------------------- +call vim_kicks_ass#with_plugins([ + \ 'misc', 'easytags', 'taglist', + \ 'l9', 'syntastic', + \ 'fugitive', 'autoclose', 'markdown', + \ 'html5', 'nerdcommenter', 'tabular', + \ 'closetag', 'detectindent', 'junegunn/fzf.vim', + \ 'itchyny/lightline.vim', 'scrooloose/nerdtree', + \ 'sheerun/vim-polyglot', 'jcommenter', 'endwise', + \ 'ap/vim-css-color', 'prabirshrestha/async.vim', 'prabirshrestha/vim-lsp', + \ 'php-doc', 'php-fix-html-indent', 'php-cs-fixer', 'php-namespace', + \ 'mikoto2000/buffer_selector.vim', 'thaerkh/vim-workspace', + \ 'qpkorr/vim-bufkill' + \ ]) + +call vim_kicks_ass#with_plugins([ + \ 'prabirshrestha/asyncomplete.vim', + \ 'prabirshrestha/asyncomplete-lsp.vim', + \ ]) + +" ------------------------------------------------------- +" LOAD PRESETS +" ------------------------------------------------------- +call vim_kicks_ass#using_presets([ + \ 'javascript' + \ ]) + +" ------------------------------------------------------- +" Autocompletion backends for asynccomplete +" ------------------------------------------------------- + +" Keyword completion +call vim_kicks_ass#with_plugins([ + \ 'prabirshrestha/asyncomplete-buffer.vim', + \ ]) + +call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({ + \ 'name': 'buffer', + \ 'whitelist': ['*'], + \ 'blacklist': ['go'], + \ 'completor': function('asyncomplete#sources#buffer#completor'), + \ 'config': { + \ 'max_buffer_size': -1, + \ }, + \ })) + +" File name completion +call vim_kicks_ass#with_plugins([ + \ 'prabirshrestha/asyncomplete-file.vim' + \ ]) + +au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({ + \ 'name': 'file', + \ 'whitelist': ['*'], + \ 'priority': 10, + \ 'completor': function('asyncomplete#sources#file#completor') + \ })) + +" Omni completion +call vim_kicks_ass#with_plugins([ + \ 'yami-beta/asyncomplete-omni.vim' + \ ]) + +call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({ + \ 'name': 'omni', + \ 'whitelist': ['*'], + \ 'blacklist': ['c', 'cpp', 'html', 'php', 'css', 'less', 'sass'], + \ 'completor': function('asyncomplete#sources#omni#completor') + \ })) + +" ------------------------------------------------------- +" PLUGIN SETTINGS +" ------------------------------------------------------- + +" vim-workspace +let g:workspace_session_directory = vim_path.'/sessions/' + +" asynccomplete +let g:asyncomplete_auto_popup = 1 + +" vim-lsp +let g:lsp_signs_enabled = 0 +let g:lsp_diagnostics_echo_cursor = 1 +let g:lsp_insert_text_enabled = 0 +let g:lsp_preview_autoclose = 0 + +" Enable intelephense for vim-lsp or newer php-complete +" npm install -g intelephense +if executable("intelephense") + if !isdirectory(vim_path."/intelephense") + call mkdir(vim_path."/intelephense", "p") + endif + au User lsp_setup call lsp#register_server({ + \ 'name': 'intelephense', + \ 'cmd': {server_info->['intelephense', '--stdio']}, + \ 'initialization_options': {"storagePath": expand("~/.vim/intelephense")}, + \ 'whitelist': ['php'], + \ }) + "autocmd FileType php setlocal omnifunc=lsp#complete +" Enable php-language-server for vim-lsp +" git clone https://github.com/felixfbecker/php-language-server ~/.vim/php-language-server +" cd ~/.vim/php-language-server/ && composer install && composer run-script parse-stubs +elseif isdirectory(vim_path."/php-language-server") + au User lsp_setup call lsp#register_server({ + \ 'name': 'php-language-server', + \ 'cmd': {server_info->['php', expand("~/.vim/php-language-server/bin/php-language-server.php")]}, + \ 'whitelist': ['php'], + \ }) + "autocmd FileType php setlocal omnifunc=lsp#complete +else + " php-complete : autocompletion support + " enable php-complete for newer code completion code base + call vim_kicks_ass#with_plugins('php-complete') + let g:phpcomplete_parse_docblock_comments = 1 +endif + +" npm install -g vscode-css-languageserver-bin +if executable('css-languageserver') + au User lsp_setup call lsp#register_server({ + \ 'name': 'css-languageserver', + \ 'cmd': {server_info->[&shell, &shellcmdflag, 'css-languageserver --stdio']}, + \ 'whitelist': ['css', 'less', 'sass'], + \ }) + "autocmd FileType css setlocal omnifunc=lsp#complete + "autocmd FileType less setlocal omnifunc=lsp#complete + "autocmd FileType sass setlocal omnifunc=lsp#complete +endif + +" autocomplpop options +let g:acp_mappingDriven = 1 " don't autocomplete on backspace +let g:acp_behaviorKeywordLength = 2 " keyword autocomplete with 1 character +let g:acp_completeoptPreview = 1 " display function arguments preview + +" easytags option +let g:easytags_cmd = 'ctags' +let g:easytags_syntax_keyword = 'auto' " Use auto or always (faster) +let g:easytags_auto_update = 0 " automatically generate tags while coding +let g:easytags_auto_highlight = 0 " can affect performance +let g:easytags_async = 1 +if !isdirectory(vim_path."/typetags") + call mkdir(vim_path."/typetags", "p") +endif +set tags=./tags; " project tags file +let g:easytags_dynamic_files = 1 " use project tags file if available +let g:easytags_file = vim_path."/tags" +let g:easytags_by_filetype = vim_path."/typetags" " generate tag files by file type +" enable tag recursion if inside a repository +let git_repo = isdirectory(getcwd().'/'.".git") +let fossil_repo = file_readable(getcwd().'/'.".fslckout") +if git_repo || fossil_repo + let g:easytags_autorecurse = 1 + "echo 'Recursive tags scanning enabled.' +endif + +" syntastic options +let g:syntastic_enable_signs=1 +let g:syntastic_auto_loc_list=1 + +" detectindent options +let g:detectindent_preferred_expandtab = 1 +let g:detectindent_preferred_indent = 4 +let g:detectindent_preferred_when_mixed = 1 + +" lightline options +let g:lightline = { + \ 'active': { + \ 'left': [ + \ ['mode', 'paste'], + \ ['readonly', 'filename', 'modified'], + \ ['syntastic', 'gitbranch'] + \ ], + \ 'right': [ + \ ['lineinfo'], + \ ['percent'], + \ ['fileformat', 'fileencoding', 'filetype'] + \ ] + \ }, + \ 'component_function': { + \ 'gitbranch': "fugitive#statusline", + \ 'syntastic': "SyntasticStatuslineFlag" + \ } + \ } + +" fix: some weird issues with arrowkeys using autoclose in console +if !has("gui_running") + let g:AutoClosePreservDotReg = 0 +endif + +" ------------------------------------------------------- +" LOAD COLORSCHEMES +" ------------------------------------------------------- +call vim_kicks_ass#using_colorschemes([ + \ "jellybeans", "molokai", "joshdick/onedark.vim", + \ ]) + +" ------------------------------------------------------- +" EDITOR OPTIONS +" ------------------------------------------------------- + +" create the swap files directory +if !isdirectory(vim_path."/swap") + call mkdir(vim_path."/swap", "p") +endif + +syntax on +colorscheme onedark +set t_Co=256 " enable more colors for schemes that require them. +set ff=unix +set nowrap +set directory=$VIMHOME/swap// +"set backspace=indent,eol,start +set tabstop=4 +set softtabstop=4 +set shiftwidth=4 +set expandtab +set copyindent +set shiftround +set smartindent +set smarttab +set undolevels=100000 +set number " linenumbering +set laststatus=2 " always show statusline +set hlsearch +set cursorline +set relativenumber +set colorcolumn=81 " right margin position +set mouse=a " enable mouse +set completeopt=menuone,longest,preview,noselect,noinsert +set visualbell " disable annoying error sound +set t_vb= + +" ------------------------------------------------------- +" KEY BINDINGS +" ------------------------------------------------------- +let mapleader = '\' +let maplocalleader = ',' + +" Workspace session (create or delete a session for current directory) +nnoremap s :ToggleWorkspace +" Document traversing +nnoremap :call buffer_selector#OpenBufferSelector() +inoremap :call buffer_selector#OpenBufferSelector() +" show list of symbols +nnoremap l :TlistToggle +" goto definition +nnoremap :LspDefinition +inoremap :LspDefinition +nnoremap jh +nnoremap +nnoremap +" comment/uncomment +nnoremap c :call NERDComment(0, "toggle") +vnoremap c :call NERDComment(1, "toggle") +inoremap :call NERDComment(0, "toggle") +" generate php doc block +nnoremap d :call JCommentWriter() +nnoremap D :call PhpDoc() +nnoremap e :Explore +" tabs navigation previous/next +nnoremap [ :tabp +nnoremap ] :tabn +" open files +nnoremap o :edit +nnoremap O :tabnew +nnoremap v :vsplit +nnoremap V :split +" save/quit +nnoremap s :w +nnoremap sq :wq +nnoremap q :q +nnoremap Q :qa +nnoremap x :BD +nnoremap X :tabclose +" shift tab unindent +nnoremap >> +nnoremap << +inoremap +" bind omnicomplete to CTRL+Space (doesn't works in terminal but does on gvim) +inoremap pumvisible() \|\| &omnifunc == '' ? + \ "\C-n>" : + \ "\C-x>\C-o>=pumvisible() ?" . + \ "\"\\c-n>\\c-p>\\c-n>\" :" . + \ "\" \\bs>\\C-n>\"\" +inoremap +" Show function signature +nnoremap :LspHover +inoremap :LspHover +nnoremap :LspPeekDefinition +inoremap :LspPeekDefinition +" search files/content +nnoremap f :Files +nnoremap F :Rg +" toggle search highlight +nnoremap h :set hlsearch! +" display directory tree (use o to collapse/uncollapse) +nnoremap t :NERDTreeToggle +" php bindings +nnoremap f :call PhpCsFixerFixFile() + +" ------------------------------------------------------- +" AUTO COMMANDS +" ------------------------------------------------------- +autocmd BufWritePre * :%s/\s\+$//e " strip trailing spaces +autocmd BufWritePre * :retab " convert tabs to spaces +autocmd BufReadPost * :DetectIndent diff --git a/vim_kicks_ass.vim b/vim_kicks_ass.vim index 3a24acf..a2a4fd6 100644 --- a/vim_kicks_ass.vim +++ b/vim_kicks_ass.vim @@ -1,19 +1,37 @@ " Manage your VIM configuration with help from everybody " Many thanks to Tim Pope and his pathogen plugin, " from where i copied some great functions -" -" Maintainer: Sune Kibsgaard Pedersen +" +" Maintainers: Sune Kibsgaard Pedersen +" Jefferson Gonzalez " Homepage: https://github.com/kibs/vim-kicks-ass " License: VIM License +" +" Thanks: https://github.com/junegunn/vim-plug +" which source code was used to impement +" git repository parsing and cloning. " make sure we only load once, also set this to 1 in .vimrc to disable plugin if exists("g:loaded_vim_kicks_ass") finish endif + let g:loaded_vim_kicks_ass = 1 -" vim_kicks_ass root folder +" make sure the git application is on path +if !executable('git') + echohl ErrorMsg + echo '[vim-kicks-ass] needs git to function.' + echohl None + finish +endif + +" vim_kicks_ass root folder and other settings let s:root = fnamemodify(resolve(expand(':p')), ":p:h") +let s:plugins_path = s:root."/plugins" +let s:colors_path = s:root."/colors" +let s:is_win = has('win32') +let s:base_spec = {'branch': 'master', 'frozen': 0} " ------------------------------------------------------- " public functions @@ -21,30 +39,81 @@ let s:root = fnamemodify(resolve(expand(':p')), ":p:h") " add plugins function vim_kicks_ass#with_plugins(plugins) - call s:add(s:listify(a:plugins), s:root.s:separator()."plugins", "plugin") + let plugins = s:download(s:listify(a:plugins), "plugins") + call s:add(plugins, s:path(s:plugins_path), "plugin") endfunction " remove plugins which should not be loaded function vim_kicks_ass#without_plugins(plugins) - call s:remove(s:listify(a:plugins), s:root.s:separator()."plugins") + call s:remove(s:listify(a:plugins), s:root.s:separator()."plugins") +endfunction + +" set the colorscheme which should be loaded and used +function vim_kicks_ass#using_colorschemes(schemes) + let schemes = s:download(s:listify(a:schemes), "colors") + call s:add(schemes, s:path(s:colors_path), "colorscheme") endfunction " load presets function vim_kicks_ass#using_presets(presets) - let sep = s:separator() - for preset in s:listify(a:presets) - let path = s:root.sep."presets".sep.preset.".vim" - if glob(path) == "" - call s:msg("preset ".preset." not found") - else - execute ":source ".path - endif - endfor + let sep = s:separator() + for preset in s:listify(a:presets) + let path = s:root.sep."presets".sep.preset.".vim" + if glob(path) == "" + call s:msg("preset ".preset." not found") + else + execute ":source ".path + endif + endfor endfunction -" set the colorscheme which should be loaded and used -function vim_kicks_ass#using_colorschemes(schemes) - call s:add(s:listify(a:schemes), s:root.s:separator()."colors", "colorscheme") +" update all submodules +function vim_kicks_ass#update_all() + call s:msg("checking for module updates") + echo system( + \ "cd ".s:root. + \ " && ". + \ "git submodule foreach git pull origin master". + \ " && ". + \ "git submodule foreach git checkout master" + \ ) +endfunction + +" add repo and enable it. +function vim_kicks_ass#with_repo(repo, type, ...) + let name = '' + let type = s:trim(a:type) + if a:0 == 1 + let name = vim_kicks_ass#add_repo(repo, type, a:1) + else + let name = vim_kicks_ass#add_repo(repo, type) + endif + call s:add(s:listify(name, s:path(s:root.'/'.type), a:type)) +endfunction + +" clones a repository if doesn't exists. +function vim_kicks_ass#add_repo(repo, type, ...) + if a:0 > 1 + return s:err('Invalid number of arguments (2..3)') + endif + let repo = s:trim(a:repo) + let rtype = s:trim(a:type) + let opts = a:0 == 1 ? s:parse_options(a:1) : s:base_spec + let name = get(opts, 'as', fnamemodify(repo, ':t:s?\.git$??')) + let spec = extend(s:infer_properties(name, repo, rtype), opts) + let rpath = rtype.'/'.name + if empty(glob(spec.dir)) + call s:msg("adding ".name) + call system("cd ".s:root." && "."git submodule add ".spec.uri." ".rpath) + call system("cd ".s:root." && "."git submodule update --init ".rpath) + if spec.branch != "master" + call system("cd ".spec.dir." && "."git checkout ".spec.branch) + endif + if has_key(spec, "do") + call system("cd ".spec.dir." && ".spec.do) + endif + endif + return name endfunction " ------------------------------------------------------- @@ -53,46 +122,63 @@ endfunction " make sure we always get a list from some data function s:listify(values) - if type(a:values) == type("") - return [a:values] - else - return a:values - endif + if type(a:values) == type("") + return [a:values] + else + return a:values + endif endfunction " tell user something function s:msg(message) - echo "[vim-kicks-ass] ".a:message + echo "[vim-kicks-ass] ".a:message +endfunction + +" downloads only plugins with a / separator. +function s:download(repos, type) + let repos = [] + for repo in a:repos + if repo =~ '/' + call add(repos, vim_kicks_ass#add_repo(repo, s:trim(a:type))) + else + call add(repos, repo) + endif + endfor + return repos endfunction " add dirs to runtimepath function s:add(dirs, root, type) - let paths = s:split(&rtp) - let sep = s:separator() - for dir in a:dirs - let path = a:root.sep.dir - if glob(path.sep."*") == "" - call s:msg("initializing ".a:type." ".dir) - call system("cd ".s:root." && git submodule update --init ".path) - endif - if index(paths, path) == -1 - let paths = insert(paths, path) - endif - endfor - let &rtp = s:join(paths) + let paths = s:split(&rtp) + let sep = s:separator() + for dir in a:dirs + let path = a:root.sep.dir + if glob(path.sep."*") == "" + call s:msg("initializing ".a:type." ".dir) + call system("cd ".s:root." && git submodule update --init ".path) + endif + if index(paths, path) == -1 + let paths = insert(paths, path) + endif + let after_path = path."/"."after" + if isdirectory(after_path) + let paths = insert(paths, after_path) + endif + endfor + let &rtp = s:join(paths) endfunction " remove dirs from runtimepath function s:remove(dirs, root) - let paths = s:split(&rtp) - let sep = s:separator() - for dir in a:dirs - let i = index(paths, a:root.sep.dir) - if i != -1 - call remove(paths, i) - endif - endfor - let &rtp = s:join(paths) + let paths = s:split(&rtp) + let sep = s:separator() + for dir in a:dirs + let i = index(paths, a:root.sep.dir) + if i != -1 + call remove(paths, i) + endif + endfor + let &rtp = s:join(paths) endfunction " split a path into a list @@ -129,7 +215,106 @@ function s:join(...) return substitute(path,'^,','','') endfunction " }}}1 +function s:parse_options(arg) + let opts = copy(s:base_spec) + let type = type(a:arg) + if type == type('') + let opts.tag = a:arg + elseif type == type({}) + call extend(opts, a:arg) + if has_key(opts, 'dir') + let opts.dir = s:dirpath(expand(opts.dir)) + endif + else + throw 'Invalid argument type (expected: string of dictionary)' + endif + return opts +endfunction + +function s:infer_properties(name, repo, type) + let repo = a:repo + if s:is_local_plug(repo) + return {'dir': s:dirpath(expand(repo))} + else + if repo =~ ':' + let uri = repo + else + if repo !~ '/' + throw printf('Invalid argument: %s (implicit `vim-scripts` expansion is deprecated)', repo) + endif + let fmt = 'https://git::@github.com/%s.git' + let uri = printf(fmt, repo) + endif + let type_dir = s:path(s:root.'/'.s:trim(a:type)) + if !isdirectory(type_dir) + call mkdir(type_dir, "p") + endif + return {'dir': s:dirpath(type_dir.'/'.a:name), 'uri': uri} + endif +endfunction + +if s:is_win + function! s:rtp(spec) + return s:path(a:spec.dir . get(a:spec, 'rtp', '')) + endfunction + + function! s:path(path) + return s:trim(substitute(a:path, '/', '\', 'g')) + endfunction + + function! s:dirpath(path) + return s:path(a:path) . '\' + endfunction + + function! s:is_local_plug(repo) + return a:repo =~? '^[a-z]:\|^[%~]' + endfunction + + " Copied from fzf + function! s:wrap_cmds(cmds) + return map(['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] + + \ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) + + \ ['chcp %origchcp% > nul'], 'v:val."\r"') + endfunction + + function! s:batchfile(cmd) + let batchfile = tempname().'.bat' + call writefile(s:wrap_cmds(a:cmd), batchfile) + let cmd = plug#shellescape(batchfile, {'shell': &shell, 'script': 1}) + if &shell =~# 'powershell\.exe$' + let cmd = '& ' . cmd + endif + return [batchfile, cmd] + endfunction +else + function! s:rtp(spec) + return s:dirpath(a:spec.dir . get(a:spec, 'rtp', '')) + endfunction + + function! s:path(path) + return s:trim(a:path) + endfunction + + function! s:dirpath(path) + return substitute(a:path, '[/\\]*$', '/', '') + endfunction + + function! s:is_local_plug(repo) + return a:repo[0] =~ '[/$~]' + endfunction +endif + " \ on Windows unless shellslash is set, / everywhere else. function s:separator() return !exists("+shellslash") || &shellslash ? '/' : '\' endfunction " }}}1 + +function s:trim(str) + return substitute(a:str, '[\/]\+$', '', '') +endfunction + +function s:err(msg) + echohl ErrorMsg + echom '[vim-kicks-ass] '.a:msg + echohl None +endfunction