├── .editorconfig ├── .gitignore ├── .tern-project ├── .vimrc ├── LICENSE ├── README.md ├── autoload └── plug.vim ├── colors └── PaperColor.vim ├── config ├── abbrev.vim ├── autocmd.vim ├── mapping.vim └── setting.vim ├── fonts ├── 10-powerline-symbols.conf ├── PowerlineSymbols.otf └── install ├── plugins ├── config.vim └── def.vim └── resources ├── WebVim.png └── WebVim.svg /.editorconfig: -------------------------------------------------------------------------------- 1 | ; .editorconfig 2 | 3 | root = true 4 | 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 4 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | 13 | [**.json] 14 | indent_style = space 15 | indent_size = 2 16 | 17 | [**.html] 18 | brace_style = expand 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | local.vim 2 | plugins/plugged/* 3 | nerdtree_plugin 4 | spell 5 | -------------------------------------------------------------------------------- /.tern-project: -------------------------------------------------------------------------------- 1 | { 2 | "libs" : ["ecma6", "browser", "requirejs"], 3 | "plugins": { 4 | "node" : {}, 5 | "es_modules" : {}, 6 | "requirejs" : {} 7 | }, 8 | "ecmaVersion": 6 9 | } 10 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " 2 | " WebVim Configuration entry point 3 | " 4 | " author: Bertrand Chevrier 5 | " source: https://github.com/krampstudio/dotvim 6 | " year : 2015 7 | " 8 | 9 | 10 | 11 | " You won't find any configuration here directly, 12 | " please look at files under the config folder for global config 13 | " and under plugins for plugins configuration 14 | 15 | 16 | filetype plugin on 17 | 18 | let g:vimDir = $HOME.'/.vim' 19 | 20 | let g:hardcoreMode = 1 21 | 22 | let s:pluginDir = g:vimDir.'/plugins/plugged' 23 | let s:pluginDef = g:vimDir.'/plugins/def.vim' 24 | let s:pluginConf = g:vimDir.'/plugins/config.vim' 25 | 26 | let s:configSetting = g:vimDir.'/config/setting.vim' 27 | let s:configMapping = g:vimDir.'/config/mapping.vim' 28 | let s:configAbbrev = g:vimDir.'/config/abbrev.vim' 29 | let s:configAutocmd = g:vimDir.'/config/autocmd.vim' 30 | 31 | let s:userConfig = g:vimDir.'/local.vim' 32 | 33 | if !isdirectory(s:pluginDir) 34 | 35 | " Welcome message when plugins are not yet installed 36 | 37 | echom " " 38 | echom "Welcome to WebVim" 39 | echom " > the vim IDE for web dev <" 40 | echom " " 41 | echom "Checking dependencies :" 42 | if (!executable('node') && !executable('nodejs')) || !executable('npm') 43 | echom " [ERR] node.js and npm are required, please install them before continuing." 44 | echom " " 45 | else 46 | 47 | echom " - nodejs : ok" 48 | echom " - npm : ok" 49 | echom " - eslint : " . (executable('eslint') ? "ok" : "no (optional)") 50 | echom " - jsonlint : " . (executable('jsonlint') ? "ok" : "no (optional)") 51 | echom " - csslint : " . (executable('csslint') ? "ok" : "no (optional)") 52 | echom " done." 53 | 54 | echom " " 55 | echom "We are going to install the plugins : " 56 | echom " 1. take a coffee" 57 | echom " 2. reload vim" 58 | echom " 3. Envoy WebVim" 59 | echom " " 60 | echom "Please note if you want to have the arrows keys and , disable the 'hardcoreMode' in the vimrc" 61 | echom " " 62 | 63 | exec ":source ".s:pluginDef 64 | 65 | "Install plugins on first run 66 | autocmd VimEnter * PlugInstall 67 | endif 68 | 69 | else 70 | 71 | " Loads the global config, mapping and settings 72 | exec ":source ".s:configSetting 73 | exec ":source ".s:configMapping 74 | exec ":source ".s:configAbbrev 75 | exec ":source ".s:configAutocmd 76 | 77 | " Loads plugins def and config 78 | exec ":source ".s:pluginDef 79 | exec ":source ".s:pluginConf 80 | 81 | 82 | " user configuration 83 | if filereadable(s:userConfig) 84 | exec ":source ".s:userConfig 85 | endif 86 | 87 | endif 88 | 89 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | http://www.gnu.org/licenses/gpl-3.0.txt 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for 12 | software and other kinds of works. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | the GNU General Public License is intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. We, the Free Software Foundation, use the 19 | GNU General Public License for most of our software; it applies also to 20 | any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | them if you wish), that you receive source code or can get it if you 27 | want it, that you can change the software or use pieces of it in new 28 | free programs, and that you know you can do these things. 29 | 30 | To protect your rights, we need to prevent others from denying you 31 | these rights or asking you to surrender the rights. Therefore, you have 32 | certain responsibilities if you distribute copies of the software, or if 33 | you modify it: responsibilities to respect the freedom of others. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must pass on to the recipients the same 37 | freedoms that you received. You must make sure that they, too, receive 38 | or can get the source code. And you must show them these terms so they 39 | know their rights. 40 | 41 | Developers that use the GNU GPL protect your rights with two steps: 42 | (1) assert copyright on the software, and (2) offer you this License 43 | giving you legal permission to copy, distribute and/or modify it. 44 | 45 | For the developers' and authors' protection, the GPL clearly explains 46 | that there is no warranty for this free software. For both users' and 47 | authors' sake, the GPL requires that modified versions be marked as 48 | changed, so that their problems will not be attributed erroneously to 49 | authors of previous versions. 50 | 51 | Some devices are designed to deny users access to install or run 52 | modified versions of the software inside them, although the manufacturer 53 | can do so. This is fundamentally incompatible with the aim of 54 | protecting users' freedom to change the software. The systematic 55 | pattern of such abuse occurs in the area of products for individuals to 56 | use, which is precisely where it is most unacceptable. Therefore, we 57 | have designed this version of the GPL to prohibit the practice for those 58 | products. If such problems arise substantially in other domains, we 59 | stand ready to extend this provision to those domains in future versions 60 | of the GPL, as needed to protect the freedom of users. 61 | 62 | Finally, every program is threatened constantly by software patents. 63 | States should not allow patents to restrict development and use of 64 | software on general-purpose computers, but in those that do, we wish to 65 | avoid the special danger that patents applied to a free program could 66 | make it effectively proprietary. To prevent this, the GPL assures that 67 | patents cannot be used to render the program non-free. 68 | 69 | The precise terms and conditions for copying, distribution and 70 | modification follow. 71 | 72 | TERMS AND CONDITIONS 73 | 74 | 0. Definitions. 75 | 76 | "This License" refers to version 3 of the GNU General Public License. 77 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of 79 | works, such as semiconductor masks. 80 | 81 | "The Program" refers to any copyrightable work licensed under this 82 | License. Each licensee is addressed as "you". "Licensees" and 83 | "recipients" may be individuals or organizations. 84 | 85 | To "modify" a work means to copy from or adapt all or part of the work 86 | in a fashion requiring copyright permission, other than the making of an 87 | exact copy. The resulting work is called a "modified version" of the 88 | earlier work or a work "based on" the earlier work. 89 | 90 | A "covered work" means either the unmodified Program or a work based 91 | on the Program. 92 | 93 | To "propagate" a work means to do anything with it that, without 94 | permission, would make you directly or secondarily liable for 95 | infringement under applicable copyright law, except executing it on a 96 | computer or modifying a private copy. Propagation includes copying, 97 | distribution (with or without modification), making available to the 98 | public, and in some countries other activities as well. 99 | 100 | To "convey" a work means any kind of propagation that enables other 101 | parties to make or receive copies. Mere interaction with a user through 102 | a computer network, with no transfer of a copy, is not conveying. 103 | 104 | An interactive user interface displays "Appropriate Legal Notices" 105 | to the extent that it includes a convenient and prominently visible 106 | feature that (1) displays an appropriate copyright notice, and (2) 107 | tells the user that there is no warranty for the work (except to the 108 | extent that warranties are provided), that licensees may convey the 109 | work under this License, and how to view a copy of this License. If 110 | the interface presents a list of user commands or options, such as a 111 | menu, a prominent item in the list meets this criterion. 112 | 113 | 1. Source Code. 114 | 115 | The "source code" for a work means the preferred form of the work 116 | for making modifications to it. "Object code" means any non-source 117 | form of a work. 118 | 119 | A "Standard Interface" means an interface that either is an official 120 | standard defined by a recognized standards body, or, in the case of 121 | interfaces specified for a particular programming language, one that 122 | is widely used among developers working in that language. 123 | 124 | The "System Libraries" of an executable work include anything, other 125 | than the work as a whole, that (a) is included in the normal form of 126 | packaging a Major Component, but which is not part of that Major 127 | Component, and (b) serves only to enable use of the work with that 128 | Major Component, or to implement a Standard Interface for which an 129 | implementation is available to the public in source code form. A 130 | "Major Component", in this context, means a major essential component 131 | (kernel, window system, and so on) of the specific operating system 132 | (if any) on which the executable work runs, or a compiler used to 133 | produce the work, or an object code interpreter used to run it. 134 | 135 | The "Corresponding Source" for a work in object code form means all 136 | the source code needed to generate, install, and (for an executable 137 | work) run the object code and to modify the work, including scripts to 138 | control those activities. However, it does not include the work's 139 | System Libraries, or general-purpose tools or generally available free 140 | programs which are used unmodified in performing those activities but 141 | which are not part of the work. For example, Corresponding Source 142 | includes interface definition files associated with source files for 143 | the work, and the source code for shared libraries and dynamically 144 | linked subprograms that the work is specifically designed to require, 145 | such as by intimate data communication or control flow between those 146 | subprograms and other parts of the work. 147 | 148 | The Corresponding Source need not include anything that users 149 | can regenerate automatically from other parts of the Corresponding 150 | Source. 151 | 152 | The Corresponding Source for a work in source code form is that 153 | same work. 154 | 155 | 2. Basic Permissions. 156 | 157 | All rights granted under this License are granted for the term of 158 | copyright on the Program, and are irrevocable provided the stated 159 | conditions are met. This License explicitly affirms your unlimited 160 | permission to run the unmodified Program. The output from running a 161 | covered work is covered by this License only if the output, given its 162 | content, constitutes a covered work. This License acknowledges your 163 | rights of fair use or other equivalent, as provided by copyright law. 164 | 165 | You may make, run and propagate covered works that you do not 166 | convey, without conditions so long as your license otherwise remains 167 | in force. You may convey covered works to others for the sole purpose 168 | of having them make modifications exclusively for you, or provide you 169 | with facilities for running those works, provided that you comply with 170 | the terms of this License in conveying all material for which you do 171 | not control copyright. Those thus making or running the covered works 172 | for you must do so exclusively on your behalf, under your direction 173 | and control, on terms that prohibit them from making any copies of 174 | your copyrighted material outside their relationship with you. 175 | 176 | Conveying under any other circumstances is permitted solely under 177 | the conditions stated below. Sublicensing is not allowed; section 10 178 | makes it unnecessary. 179 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 181 | 182 | No covered work shall be deemed part of an effective technological 183 | measure under any applicable law fulfilling obligations under article 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 185 | similar laws prohibiting or restricting circumvention of such 186 | measures. 187 | 188 | When you convey a covered work, you waive any legal power to forbid 189 | circumvention of technological measures to the extent such circumvention 190 | is effected by exercising rights under this License with respect to 191 | the covered work, and you disclaim any intention to limit operation or 192 | modification of the work as a means of enforcing, against the work's 193 | users, your or third parties' legal rights to forbid circumvention of 194 | technological measures. 195 | 196 | 4. Conveying Verbatim Copies. 197 | 198 | You may convey verbatim copies of the Program's source code as you 199 | receive it, in any medium, provided that you conspicuously and 200 | appropriately publish on each copy an appropriate copyright notice; 201 | keep intact all notices stating that this License and any 202 | non-permissive terms added in accord with section 7 apply to the code; 203 | keep intact all notices of the absence of any warranty; and give all 204 | recipients a copy of this License along with the Program. 205 | 206 | You may charge any price or no price for each copy that you convey, 207 | and you may offer support or warranty protection for a fee. 208 | 209 | 5. Conveying Modified Source Versions. 210 | 211 | You may convey a work based on the Program, or the modifications to 212 | produce it from the Program, in the form of source code under the 213 | terms of section 4, provided that you also meet all of these conditions: 214 | 215 | a) The work must carry prominent notices stating that you modified 216 | it, and giving a relevant date. 217 | 218 | b) The work must carry prominent notices stating that it is 219 | released under this License and any conditions added under section 220 | 7. This requirement modifies the requirement in section 4 to 221 | "keep intact all notices". 222 | 223 | c) You must license the entire work, as a whole, under this 224 | License to anyone who comes into possession of a copy. This 225 | License will therefore apply, along with any applicable section 7 226 | additional terms, to the whole of the work, and all its parts, 227 | regardless of how they are packaged. This License gives no 228 | permission to license the work in any other way, but it does not 229 | invalidate such permission if you have separately received it. 230 | 231 | d) If the work has interactive user interfaces, each must display 232 | Appropriate Legal Notices; however, if the Program has interactive 233 | interfaces that do not display Appropriate Legal Notices, your 234 | work need not make them do so. 235 | 236 | A compilation of a covered work with other separate and independent 237 | works, which are not by their nature extensions of the covered work, 238 | and which are not combined with it such as to form a larger program, 239 | in or on a volume of a storage or distribution medium, is called an 240 | "aggregate" if the compilation and its resulting copyright are not 241 | used to limit the access or legal rights of the compilation's users 242 | beyond what the individual works permit. Inclusion of a covered work 243 | in an aggregate does not cause this License to apply to the other 244 | parts of the aggregate. 245 | 246 | 6. Conveying Non-Source Forms. 247 | 248 | You may convey a covered work in object code form under the terms 249 | of sections 4 and 5, provided that you also convey the 250 | machine-readable Corresponding Source under the terms of this License, 251 | in one of these ways: 252 | 253 | a) Convey the object code in, or embodied in, a physical product 254 | (including a physical distribution medium), accompanied by the 255 | Corresponding Source fixed on a durable physical medium 256 | customarily used for software interchange. 257 | 258 | b) Convey the object code in, or embodied in, a physical product 259 | (including a physical distribution medium), accompanied by a 260 | written offer, valid for at least three years and valid for as 261 | long as you offer spare parts or customer support for that product 262 | model, to give anyone who possesses the object code either (1) a 263 | copy of the Corresponding Source for all the software in the 264 | product that is covered by this License, on a durable physical 265 | medium customarily used for software interchange, for a price no 266 | more than your reasonable cost of physically performing this 267 | conveying of source, or (2) access to copy the 268 | Corresponding Source from a network server at no charge. 269 | 270 | c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | 276 | d) Convey the object code by offering access from a designated 277 | place (gratis or for a charge), and offer equivalent access to the 278 | Corresponding Source in the same way through the same place at no 279 | further charge. You need not require recipients to copy the 280 | Corresponding Source along with the object code. If the place to 281 | copy the object code is a network server, the Corresponding Source 282 | may be on a different server (operated by you or a third party) 283 | that supports equivalent copying facilities, provided you maintain 284 | clear directions next to the object code saying where to find the 285 | Corresponding Source. Regardless of what server hosts the 286 | Corresponding Source, you remain obligated to ensure that it is 287 | available for as long as needed to satisfy these requirements. 288 | 289 | e) Convey the object code using peer-to-peer transmission, provided 290 | you inform other peers where the object code and Corresponding 291 | Source of the work are being offered to the general public at no 292 | charge under subsection 6d. 293 | 294 | A separable portion of the object code, whose source code is excluded 295 | from the Corresponding Source as a System Library, need not be 296 | included in conveying the object code work. 297 | 298 | A "User Product" is either (1) a "consumer product", which means any 299 | tangible personal property which is normally used for personal, family, 300 | or household purposes, or (2) anything designed or sold for incorporation 301 | into a dwelling. In determining whether a product is a consumer product, 302 | doubtful cases shall be resolved in favor of coverage. For a particular 303 | product received by a particular user, "normally used" refers to a 304 | typical or common use of that class of product, regardless of the status 305 | of the particular user or of the way in which the particular user 306 | actually uses, or expects or is expected to use, the product. A product 307 | is a consumer product regardless of whether the product has substantial 308 | commercial, industrial or non-consumer uses, unless such uses represent 309 | the only significant mode of use of the product. 310 | 311 | "Installation Information" for a User Product means any methods, 312 | procedures, authorization keys, or other information required to install 313 | and execute modified versions of a covered work in that User Product from 314 | a modified version of its Corresponding Source. The information must 315 | suffice to ensure that the continued functioning of the modified object 316 | code is in no case prevented or interfered with solely because 317 | modification has been made. 318 | 319 | If you convey an object code work under this section in, or with, or 320 | specifically for use in, a User Product, and the conveying occurs as 321 | part of a transaction in which the right of possession and use of the 322 | User Product is transferred to the recipient in perpetuity or for a 323 | fixed term (regardless of how the transaction is characterized), the 324 | Corresponding Source conveyed under this section must be accompanied 325 | by the Installation Information. But this requirement does not apply 326 | if neither you nor any third party retains the ability to install 327 | modified object code on the User Product (for example, the work has 328 | been installed in ROM). 329 | 330 | The requirement to provide Installation Information does not include a 331 | requirement to continue to provide support service, warranty, or updates 332 | for a work that has been modified or installed by the recipient, or for 333 | the User Product in which it has been modified or installed. Access to a 334 | network may be denied when the modification itself materially and 335 | adversely affects the operation of the network or violates the rules and 336 | protocols for communication across the network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders of 364 | that material) supplement the terms of this License with terms: 365 | 366 | a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | 369 | b) Requiring preservation of specified reasonable legal notices or 370 | author attributions in that material or in the Appropriate Legal 371 | Notices displayed by works containing it; or 372 | 373 | c) Prohibiting misrepresentation of the origin of that material, or 374 | requiring that modified versions of such material be marked in 375 | reasonable ways as different from the original version; or 376 | 377 | d) Limiting the use for publicity purposes of names of licensors or 378 | authors of the material; or 379 | 380 | e) Declining to grant rights under trademark law for use of some 381 | trade names, trademarks, or service marks; or 382 | 383 | f) Requiring indemnification of licensors and authors of that 384 | material by anyone who conveys the material (or modified versions of 385 | it) with contractual assumptions of liability to the recipient, for 386 | any liability that these contractual assumptions directly impose on 387 | those licensors and authors. 388 | 389 | All other non-permissive additional terms are considered "further 390 | restrictions" within the meaning of section 10. If the Program as you 391 | received it, or any part of it, contains a notice stating that it is 392 | governed by this License along with a term that is a further 393 | restriction, you may remove that term. If a license document contains 394 | a further restriction but permits relicensing or conveying under this 395 | License, you may add to a covered work material governed by the terms 396 | of that license document, provided that the further restriction does 397 | not survive such relicensing or conveying. 398 | 399 | If you add terms to a covered work in accord with this section, you 400 | must place, in the relevant source files, a statement of the 401 | additional terms that apply to those files, or a notice indicating 402 | where to find the applicable terms. 403 | 404 | Additional terms, permissive or non-permissive, may be stated in the 405 | form of a separately written license, or stated as exceptions; 406 | the above requirements apply either way. 407 | 408 | 8. Termination. 409 | 410 | You may not propagate or modify a covered work except as expressly 411 | provided under this License. Any attempt otherwise to propagate or 412 | modify it is void, and will automatically terminate your rights under 413 | this License (including any patent licenses granted under the third 414 | paragraph of section 11). 415 | 416 | However, if you cease all violation of this License, then your 417 | license from a particular copyright holder is reinstated (a) 418 | provisionally, unless and until the copyright holder explicitly and 419 | finally terminates your license, and (b) permanently, if the copyright 420 | holder fails to notify you of the violation by some reasonable means 421 | prior to 60 days after the cessation. 422 | 423 | Moreover, your license from a particular copyright holder is 424 | reinstated permanently if the copyright holder notifies you of the 425 | violation by some reasonable means, this is the first time you have 426 | received notice of violation of this License (for any work) from that 427 | copyright holder, and you cure the violation prior to 30 days after 428 | your receipt of the notice. 429 | 430 | Termination of your rights under this section does not terminate the 431 | licenses of parties who have received copies or rights from you under 432 | this License. If your rights have been terminated and not permanently 433 | reinstated, you do not qualify to receive new licenses for the same 434 | material under section 10. 435 | 436 | 9. Acceptance Not Required for Having Copies. 437 | 438 | You are not required to accept this License in order to receive or 439 | run a copy of the Program. Ancillary propagation of a covered work 440 | occurring solely as a consequence of using peer-to-peer transmission 441 | to receive a copy likewise does not require acceptance. However, 442 | nothing other than this License grants you permission to propagate or 443 | modify any covered work. These actions infringe copyright if you do 444 | not accept this License. Therefore, by modifying or propagating a 445 | covered work, you indicate your acceptance of this License to do so. 446 | 447 | 10. Automatic Licensing of Downstream Recipients. 448 | 449 | Each time you convey a covered work, the recipient automatically 450 | receives a license from the original licensors, to run, modify and 451 | propagate that work, subject to this License. You are not responsible 452 | for enforcing compliance by third parties with this License. 453 | 454 | An "entity transaction" is a transaction transferring control of an 455 | organization, or substantially all assets of one, or subdividing an 456 | organization, or merging organizations. If propagation of a covered 457 | work results from an entity transaction, each party to that 458 | transaction who receives a copy of the work also receives whatever 459 | licenses to the work the party's predecessor in interest had or could 460 | give under the previous paragraph, plus a right to possession of the 461 | Corresponding Source of the work from the predecessor in interest, if 462 | the predecessor has it or can get it with reasonable efforts. 463 | 464 | You may not impose any further restrictions on the exercise of the 465 | rights granted or affirmed under this License. For example, you may 466 | not impose a license fee, royalty, or other charge for exercise of 467 | rights granted under this License, and you may not initiate litigation 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that 469 | any patent claim is infringed by making, using, selling, offering for 470 | sale, or importing the Program or any portion of it. 471 | 472 | 11. Patents. 473 | 474 | A "contributor" is a copyright holder who authorizes use under this 475 | License of the Program or a work on which the Program is based. The 476 | work thus licensed is called the contributor's "contributor version". 477 | 478 | A contributor's "essential patent claims" are all patent claims 479 | owned or controlled by the contributor, whether already acquired or 480 | hereafter acquired, that would be infringed by some manner, permitted 481 | by this License, of making, using, or selling its contributor version, 482 | but do not include claims that would be infringed only as a 483 | consequence of further modification of the contributor version. For 484 | purposes of this definition, "control" includes the right to grant 485 | patent sublicenses in a manner consistent with the requirements of 486 | this License. 487 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free 489 | patent license under the contributor's essential patent claims, to 490 | make, use, sell, offer for sale, import and otherwise run, modify and 491 | propagate the contents of its contributor version. 492 | 493 | In the following three paragraphs, a "patent license" is any express 494 | agreement or commitment, however denominated, not to enforce a patent 495 | (such as an express permission to practice a patent or covenant not to 496 | sue for patent infringement). To "grant" such a patent license to a 497 | party means to make such an agreement or commitment not to enforce a 498 | patent against the party. 499 | 500 | If you convey a covered work, knowingly relying on a patent license, 501 | and the Corresponding Source of the work is not available for anyone 502 | to copy, free of charge and under the terms of this License, through a 503 | publicly available network server or other readily accessible means, 504 | then you must either (1) cause the Corresponding Source to be so 505 | available, or (2) arrange to deprive yourself of the benefit of the 506 | patent license for this particular work, or (3) arrange, in a manner 507 | consistent with the requirements of this License, to extend the patent 508 | license to downstream recipients. "Knowingly relying" means you have 509 | actual knowledge that, but for the patent license, your conveying the 510 | covered work in a country, or your recipient's use of the covered work 511 | in a country, would infringe one or more identifiable patents in that 512 | country that you have reason to believe are valid. 513 | 514 | If, pursuant to or in connection with a single transaction or 515 | arrangement, you convey, or propagate by procuring conveyance of, a 516 | covered work, and grant a patent license to some of the parties 517 | receiving the covered work authorizing them to use, propagate, modify 518 | or convey a specific copy of the covered work, then the patent license 519 | you grant is automatically extended to all recipients of the covered 520 | work and works based on it. 521 | 522 | A patent license is "discriminatory" if it does not include within 523 | the scope of its coverage, prohibits the exercise of, or is 524 | conditioned on the non-exercise of one or more of the rights that are 525 | specifically granted under this License. You may not convey a covered 526 | work if you are a party to an arrangement with a third party that is 527 | in the business of distributing software, under which you make payment 528 | to the third party based on the extent of your activity of conveying 529 | the work, and under which the third party grants, to any of the 530 | parties who would receive the covered work from you, a discriminatory 531 | patent license (a) in connection with copies of the covered work 532 | conveyed by you (or copies made from those copies), or (b) primarily 533 | for and in connection with specific products or compilations that 534 | contain the covered work, unless you entered into that arrangement, 535 | or that patent license was granted, prior to 28 March 2007. 536 | 537 | Nothing in this License shall be construed as excluding or limiting 538 | any implied license or other defenses to infringement that may 539 | otherwise be available to you under applicable patent law. 540 | 541 | 12. No Surrender of Others' Freedom. 542 | 543 | If conditions are imposed on you (whether by court order, agreement or 544 | otherwise) that contradict the conditions of this License, they do not 545 | excuse you from the conditions of this License. If you cannot convey a 546 | covered work so as to satisfy simultaneously your obligations under this 547 | License and any other pertinent obligations, then as a consequence you may 548 | not convey it at all. For example, if you agree to terms that obligate you 549 | to collect a royalty for further conveying from those to whom you convey 550 | the Program, the only way you could satisfy both those terms and this 551 | License would be to refrain entirely from conveying the Program. 552 | 553 | 13. Use with the GNU Affero General Public License. 554 | 555 | Notwithstanding any other provision of this License, you have 556 | permission to link or combine any covered work with a work licensed 557 | under version 3 of the GNU Affero General Public License into a single 558 | combined work, and to convey the resulting work. The terms of this 559 | License will continue to apply to the part which is the covered work, 560 | but the special requirements of the GNU Affero General Public License, 561 | section 13, concerning interaction through a network will apply to the 562 | combination as such. 563 | 564 | 14. Revised Versions of this License. 565 | 566 | The Free Software Foundation may publish revised and/or new versions of 567 | the GNU General Public License from time to time. Such new versions will 568 | be similar in spirit to the present version, but may differ in detail to 569 | address new problems or concerns. 570 | 571 | Each version is given a distinguishing version number. If the 572 | Program specifies that a certain numbered version of the GNU General 573 | Public License "or any later version" applies to it, you have the 574 | option of following the terms and conditions either of that numbered 575 | version or of any later version published by the Free Software 576 | Foundation. If the Program does not specify a version number of the 577 | GNU General Public License, you may choose any version ever published 578 | by the Free Software Foundation. 579 | 580 | If the Program specifies that a proxy can decide which future 581 | versions of the GNU General Public License can be used, that proxy's 582 | public statement of acceptance of a version permanently authorizes you 583 | to choose that version for the Program. 584 | 585 | Later license versions may give you additional or different 586 | permissions. However, no additional obligations are imposed on any 587 | author or copyright holder as a result of your choosing to follow a 588 | later version. 589 | 590 | 15. Disclaimer of Warranty. 591 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 600 | 601 | 16. Limitation of Liability. 602 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 611 | SUCH DAMAGES. 612 | 613 | 17. Interpretation of Sections 15 and 16. 614 | 615 | If the disclaimer of warranty and limitation of liability provided 616 | above cannot be given local legal effect according to their terms, 617 | reviewing courts shall apply local law that most closely approximates 618 | an absolute waiver of all civil liability in connection with the 619 | Program, unless a warranty or assumption of liability accompanies a 620 | copy of the Program in return for a fee. 621 | 622 | END OF TERMS AND CONDITIONS 623 | 624 | How to Apply These Terms to Your New Programs 625 | 626 | If you develop a new program, and you want it to be of the greatest 627 | possible use to the public, the best way to achieve this is to make it 628 | free software which everyone can redistribute and change under these terms. 629 | 630 | To do so, attach the following notices to the program. It is safest 631 | to attach them to the start of each source file to most effectively 632 | state the exclusion of warranty; and each file should have at least 633 | the "copyright" line and a pointer to where the full notice is found. 634 | 635 | 636 | Copyright (C) 637 | 638 | This program is free software: you can redistribute it and/or modify 639 | it under the terms of the GNU General Public License as published by 640 | the Free Software Foundation, either version 3 of the License, or 641 | (at your option) any later version. 642 | 643 | This program is distributed in the hope that it will be useful, 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 646 | GNU General Public License for more details. 647 | 648 | You should have received a copy of the GNU General Public License 649 | along with this program. If not, see . 650 | 651 | Also add information on how to contact you by electronic and paper mail. 652 | 653 | If the program does terminal interaction, make it output a short 654 | notice like this when it starts in an interactive mode: 655 | 656 | Copyright (C) 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 658 | This is free software, and you are welcome to redistribute it 659 | under certain conditions; type `show c' for details. 660 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate 662 | parts of the General Public License. Of course, your program's commands 663 | might be different; for a GUI interface, you would use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU GPL, see 668 | . 669 | 670 | The GNU General Public License does not permit incorporating your program 671 | into proprietary programs. If your program is a subroutine library, you 672 | may consider it more useful to permit linking proprietary applications with 673 | the library. If this is what you want to do, use the GNU Lesser General 674 | Public License instead of this License. But first, please read 675 | . 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![WebVim](resources/WebVim.png?v=2 "WebVim") 2 | =============================== 3 | 4 | WebVim is a Vim based distribution targeting JavaScript and Web development. 5 | 6 | It targets : 7 | - JavaScript development (ES5, ES6, node.js) 8 | - HTML5 9 | - CSS3 and SCSS 10 | 11 | And contains the features you expect from a modern code editor : 12 | 13 | - syntax highlighting 14 | - syntax and error checking 15 | - autocompletion 16 | - multi cursor 17 | - git support 18 | - code format 19 | - support coding conventions (editorconfig) 20 | - hardcore mode (for real Vim users) 21 | - Emmet support 22 | - jsdoc generation (coming soon) 23 | - debugging (coming soon) 24 | - grunt/gulp support (coming soon) 25 | - all the awesomeness from Vim 26 | 27 | > The WebVim idea is to provide you a vim distribution: something that comes prepackaged, preconfigured, built on a kernel to serve a goal. WebVim is to vim what Debian is to Linux, a vim distribution for the web. 28 | 29 | ## Install 30 | 31 | __Only tested on Linux__ 32 | 33 | ### Dependencies (the long story) 34 | 35 | On Ubuntu (from 15.04) 36 | 37 | 1. A modern version of Vim 38 | 39 | ```sh 40 | apt-get install vim vim-runtime vim-gui-common 41 | ``` 42 | 43 | or compile a recent version with `xterm_clipboard` and `ruby` or `python` support. 44 | 45 | 2. Some tools to compile YouCompleteMe 46 | 47 | ```sh 48 | apt-get install build-essential cmake python-dev exuberant-ctags 49 | ``` 50 | 51 | 3. Node.js and npm 52 | 53 | ```sh 54 | curl -sL https://deb.nodesource.com/setup_0.12 | bash - 55 | apt-get install -y nodejs 56 | ``` 57 | 58 | 4. Some npm packages 59 | 60 | ```sh 61 | npm install -g eslint csslint jshint jsonlint handlebars 62 | ``` 63 | 64 | ### Dependencies (the short story) 65 | 66 | > Please report me what you did to make it work on your OS 67 | 68 | #### Fedora 23/24 69 | 70 | ```sh 71 | sudo dnf install cmake python-devel npm vim 72 | npm install -g npm eslint csslint jshint jsonlint handlebars 73 | ``` 74 | 75 | ### Install it: 76 | 77 | ```sh 78 | git clone https://github.com/krampstudio/webvim.git ~/.vim 79 | ln -s ~/.vim/.vimrc ~/.vimrc 80 | ln -s ~/.vim/.tern-project ~/.tern-project 81 | vim 82 | ``` 83 | 84 | The plugins install can take some times, especially since there's a compilation made by YouCompleteMe. If you've the feeling the install has frozen, you can finish the install after by entering the command `:PlugInstall`. 85 | 86 | ## Hardcore mode 87 | 88 | The hardcore mode remap some keys to force you use Vim in a productive way: 89 | - no arrow keys for moving instead use the common Vim movement commands. 90 | - in insert mode, use `jk` to switch back to normal mode instead of `` 91 | 92 | Restricting commands is the best way to make your fingers learn. After one or two days, you should be more productive and have learned lots of Vim commands. 93 | 94 | You can disable the hardcore mode by setting the value of `g:hardcoreMode` to `0` in `.vimrc`. You can also change the mappings. 95 | 96 | ## Usage 97 | 98 | ### Vim 99 | 100 | WebVim is only a Vim distribution with plugins and configuration, so all common Vim commands and basic mapping are available. You must know how to use Vim before using this IDE. If you're not comfortable with Vim enough I suggest you to take the interactive Vim tutorial (run `vimtutor` in a terminal), and keep a [common usage cheat sheet](http://fprintf.net/vimCheatSheet.html) close to you until your fingers get all the mappings in memory. 101 | 102 | ### WebVim 103 | 104 | | | Command | Mode | Context | 105 | |--------------------------------------------------|-----------------------|:----:|------------------| 106 | | __Plugins__ | 107 | | Install Plugins | `:PlugInstall` | n | | 108 | | Update Plugins | `:PlugUpdate` | n | | 109 | | | 110 | | __Config__ | 111 | | Edit .vimrc | `ev` | n | | 112 | | Reload .vimrc | `sv` | n | | 113 | | | 114 | | __File Tree (NERDTree)__ | 115 | | Toggle Tree | `` | n | | 116 | | Open a node in a new tab | `t` | | Tree Node | 117 | | Change Root | `C` | | Tree Node | 118 | | Tree menu | `m` | | Tree Node | 119 | | Add a file | `a` | | Tree Menu | 120 | | Delete a file | `d` | | Tree Menu | 121 | | Move a file | `m` | | Tree Menu | 122 | | Copy a file | `c` | | Tree Menu | 123 | | Search in files (grep) | `g` | | Tree Menu | 124 | | Next match in grep | `:cn` | | Grep > Quickfix | 125 | | Move to left tab | `` | n | | 126 | | Move to right tab | `` | n | | 127 | | Change window (ie. tree to tab) | `` | | | 128 | | Help | `?` | | Tree | 129 | | Documentation | `:help NERDTree` | | | 130 | | | 131 | | __Comment__ | 132 | | Toggle comments | `` | nv | | 133 | | Comments | `cc` | nv | | 134 | | Sexy Comments | `cs` | nv | | 135 | | UnComments | `cu` | nv | | 136 | | Yank and Comments | `cy` | nv | | 137 | | Documentation | `:help NERDCommenter` | | | 138 | | | 139 | | __Align__ | 140 | | Start interactive alignment | `EasyAlign` | v | selection | 141 | | Align next paragraph on = | `a=` | n | | 142 | | Align next paragraph on : | `a:` | n | | 143 | | Align next paragraph on delimiter _x_ | `ax` | n | | 144 | | Right align selection on = | `a=` | v | | 145 | | Right align selection on : | `a:` | v | | 146 | | Right align selection on _x_ | `ax` | v | | 147 | | Documentation | `:help :EasyAlign` | | | 148 | | | 149 | | __Format__ | 150 | | Format the file | `` | n | js,json,html,css | 151 | | Format the selection | `` | n | js,json,html,css | 152 | | | 153 | | __Multiple Cursor__ | 154 | | Start multiple cursor | `` | v | Visual Block | 155 | | Multiple cursor insert | `i` | | multiple cursor | 156 | | Multiple cursor remove | `x` | | multiple cursor | 157 | | Leave multiple cursor | `` | | multiple cursor | 158 | | | 159 | | __Paste__ | 160 | | cycle backward through your history of yanks | `p` | nv | after paste `p` | 161 | | cycle forward through your history of yanks | `P` | nv | after paste `p` | 162 | | | 163 | | __AutoCompletion__ | 164 | | Select next proposal in menu | `` | i | complete menu | 165 | | Select previous proposal in menu | `` | i | complete menu | 166 | | | 167 | | __Syntax checking__ | 168 | | Checkers infos | `:SyntasticInfo` | n | | 169 | | Check | `:SyntasticCheck` | n | | 170 | | Toggle check | `:SyntasticToggleMode`| n | | 171 | | Error window | `:Errors` | n | | 172 | | Jump next error | `:lnext` | n | | 173 | | Jump previous error | `:lprev` | n | | 174 | | | 175 | | __JavaScript__ | 176 | | Get type | `gt` | n | under cursor | 177 | | Get documentation | `gd` | n | under cursor | 178 | | Go to | `go` | n | under cursor | 179 | | Jump to definition | `gf` | n | under cursor | 180 | | Go to references | `gr` | n | under cursor | 181 | | Rename | `r` | n | under cursor | 182 | | Jump to the source of a `require` | `gf` | n | node.js, cursor | 183 | | Edit the main file of a CJS module | `:Nedit module` | n | node.js | 184 | | Edit a file of a CJS module | `:Nedit module/foo.js`| n | node.js | 185 | | Edit projects main (from package.json) | `:Nedit` | n | node.js | 186 | | | 187 | | __Git__ | 188 | | git diff | `:Gdiff` | n | | 189 | | git status | `:Gstatus` | n | | 190 | | git commit | `:Gcommit` | n | | 191 | | git blame | `:Gblame` | n | | 192 | | git mv | `:Gmove` | n | | 193 | | git rm | `:Gremove` | n | | 194 | | Open the current file in Github | `:Gbrowse` | n | | 195 | | | 196 | | __Spell Check__ | 197 | | Enable checking | `set spell` | n | | 198 | | move to the next misspelled word | `]s` | n | | 199 | | move to the previous misspelled word | `[s` | n | | 200 | | add a word to the dictionary | `zg` | n | | 201 | | undo the addition of a word to the dictionary | `zug` | n | | 202 | | view spelling suggestions for a misspelled word | `z=` | n | | 203 | | | 204 | | __Search__ | 205 | | clear highlights | `` | n | | 206 | | | 207 | | __Editing__ | 208 | | Move line up | `-` | nv | | 209 | | Move line down | `_` | nv | | 210 | | Wrap in single quote | `'` | nv | | 211 | | Wrap in double quote | `"` | nv | | 212 | | | 213 | | __Emmet__ | 214 | | Expand abbreviation | `,` | i | html,css,scss | 215 | | | 216 | | _Next sections to come soon_ | 217 | | | 218 | 219 | _Modes_ : 220 | - `n` normal 221 | - `i` insert 222 | - `v` visual 223 | 224 | _Commands_ : 225 | - `:command` a Vim command 226 | - `:set something` can also be replaced by `:setlocal something` to apply it to the current buffer only 227 | - `a` or `a` a keyboard command 228 | - `` means `CTRL and `/` (this is the Vim notation) 229 | - `` means `Shift` and `left arrow` 230 | - `b` means `CTRL` and `a`, then `b` 231 | - `` is mapped to `,` 232 | - `` is mapped to `\` 233 | 234 | 235 | 236 | 237 | ## Plugins 238 | 239 | WebVim is only a distribution that contains plugins. The plugin authors have made the hard work. 240 | 241 | _Plugin authors rocks!_ 242 | 243 | ### Plugin 244 | - [vim-plug](https://github.com/junegunn/vim-plug) Minimalist Vim Plugin Manager 245 | 246 | ### User interface 247 | 248 | - [Mango](https://github.com/goatslacker/mango.vim) A nice color scheme 249 | - [VimAirline](https://github.com/bling/vim-airline) Lean and mean statusbars 250 | 251 | ### Manage your project 252 | 253 | - [NERDTree](https://github.com/scrooloose/nerdtree) Manage your project files 254 | - [VimFugitive](https://github.com/tpope/vim-fugitive) Git integration 255 | - [VimGitGutter](https://github.com/airblade/vim-gitgutter) Git diff in the gutter 256 | - [EditorconfigVim](https://github.com/editorconfig/editorconfig-vim) Shared coding conventions 257 | 258 | ### Code writing 259 | 260 | - [NERDCommenter](https://github.com/scrooloose/nerdcommenter) Comments made easy 261 | - [VimTrailingWhitespace](https://github.com/bronson/vim-trailing-whitespace) Highlight trailing spaces 262 | - [Syntastic](https://github.com/scrooloose/syntastic) Syntax check and validation 263 | - [VimEasyAlign](https://github.com/junegunn/vim-easy-align) Realign pieces of code 264 | - [VimMultipleCursors](https://github.com/terryma/vim-multiple-cursors) Write on multiple lines easily 265 | - [VimJsBeautify](https://github.com/maksimr/vim-jsbeautify) Reformat JavaScript, HTML and JSON files 266 | - [VimYankStack](https://github.com/maxbrunsfeld/vim-yankstack) Iterate over yanked stack on paste 267 | - [VimSurround](https://github.com/tpope/vim-surround) Quoting and parenthesizing 268 | - [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) Autocompletion engine 269 | - [VimNode](https://github.com/moll/vim-node) Navigate through node.js code/modules 270 | - [VimLint](https://github.com/syngan/vim-vimlint) Linter used by syntastic for VimL 271 | - [VimLParser](https://github.com/ynkdir/vim-vimlparser) VimL parser (required by VimLint) 272 | - [Emmet-vim](https://github.com/mattn/emmet-vim) Expanding abbreviations similar to [emmet](http://emmet.io/) 273 | 274 | ### Code reading 275 | 276 | - [VimJson](https://github.com/elzr/vim-json) JSON highlighting and quote concealing 277 | - [YaJS](https://github.com/othree/yajs.vim) JavaScript syntax (ES5 and ES6) 278 | - [JavaScriptLibrariesSyntax](https://github.com/othree/javascript-libraries-syntax.vim) Syntax highlighting for well-known JS libraries 279 | - [VimCSS3](https://github.com/hail2u/vim-css3-syntax) CSS3 syntax 280 | - [ScssSyntax](https://github.com/cakebaker/scss-syntax.vim) SCSS syntax 281 | - [HTML5](https://github.com/othree/html5.vim) HTML5 syntax 282 | 283 | ## History 284 | - __1.3.0__ Fixed dependencies, tern via YCM, Emmet, new theme, nerdtree grep, use local linters 285 | - __1.2.0__ Fix #28, support new esint config files, update installe 286 | - __1.1.0__ Add user config, autocmd file, fix easyalign mapping, update Nerdtree config, better mouse support in insert mode 287 | - __1.0.0__ Becomes `webvim` with an install process, a better configuration system, better plugins neighborhood 288 | - __0.1.0__ A basic `dotvim` repository with my own Vim configuration 289 | 290 | ## Contributing 291 | 292 | Every contribution is more than welcomed. You can: 293 | - [report issues](https://github.com/krampstudio/webvim/issues) 294 | - Fix, improve the configuration, add new features. The best is to fork and submit a pull request 295 | - Test and adapt to other OS 296 | - Fix my English mistakes 297 | - Update the documentation 298 | - Create a better logo 299 | - [Offer me a coffee](https://liberapay.com/krampstudio/donate) 300 | 301 | 302 | 303 | [![Donate using Liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/krampstudio/donate) 304 | 305 | ## License 306 | 307 | The content of this repository is licensed under the [GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt) 308 | 309 | -------------------------------------------------------------------------------- /autoload/plug.vim: -------------------------------------------------------------------------------- 1 | " vim-plug: Vim plugin manager 2 | " ============================ 3 | " 4 | " Download plug.vim and put it in ~/.vim/autoload 5 | " 6 | " curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ 7 | " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 8 | " 9 | " Edit your .vimrc 10 | " 11 | " call plug#begin('~/.vim/plugged') 12 | " 13 | " " Make sure you use single quotes 14 | " 15 | " " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align 16 | " Plug 'junegunn/vim-easy-align' 17 | " 18 | " " Any valid git URL is allowed 19 | " Plug 'https://github.com/junegunn/vim-github-dashboard.git' 20 | " 21 | " " Group dependencies, vim-snippets depends on ultisnips 22 | " Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' 23 | " 24 | " " On-demand loading 25 | " Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } 26 | " Plug 'tpope/vim-fireplace', { 'for': 'clojure' } 27 | " 28 | " " Using a non-master branch 29 | " Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } 30 | " 31 | " " Using a tagged release; wildcard allowed (requires git 1.9.2 or above) 32 | " Plug 'fatih/vim-go', { 'tag': '*' } 33 | " 34 | " " Plugin options 35 | " Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' } 36 | " 37 | " " Plugin outside ~/.vim/plugged with post-update hook 38 | " Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } 39 | " 40 | " " Unmanaged plugin (manually installed and updated) 41 | " Plug '~/my-prototype-plugin' 42 | " 43 | " " Add plugins to &runtimepath 44 | " call plug#end() 45 | " 46 | " Then reload .vimrc and :PlugInstall to install plugins. 47 | " 48 | " Plug options: 49 | " 50 | "| Option | Description | 51 | "| ----------------------- | ------------------------------------------------ | 52 | "| `branch`/`tag`/`commit` | Branch/tag/commit of the repository to use | 53 | "| `rtp` | Subdirectory that contains Vim plugin | 54 | "| `dir` | Custom directory for the plugin | 55 | "| `as` | Use different name for the plugin | 56 | "| `do` | Post-update hook (string or funcref) | 57 | "| `on` | On-demand loading: Commands or ``-mappings | 58 | "| `for` | On-demand loading: File types | 59 | "| `frozen` | Do not update unless explicitly specified | 60 | " 61 | " More information: https://github.com/junegunn/vim-plug 62 | " 63 | " 64 | " Copyright (c) 2016 Junegunn Choi 65 | " 66 | " MIT License 67 | " 68 | " Permission is hereby granted, free of charge, to any person obtaining 69 | " a copy of this software and associated documentation files (the 70 | " "Software"), to deal in the Software without restriction, including 71 | " without limitation the rights to use, copy, modify, merge, publish, 72 | " distribute, sublicense, and/or sell copies of the Software, and to 73 | " permit persons to whom the Software is furnished to do so, subject to 74 | " the following conditions: 75 | " 76 | " The above copyright notice and this permission notice shall be 77 | " included in all copies or substantial portions of the Software. 78 | " 79 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 80 | " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 81 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 82 | " NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 83 | " LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 84 | " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 85 | " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 86 | 87 | if exists('g:loaded_plug') 88 | finish 89 | endif 90 | let g:loaded_plug = 1 91 | 92 | let s:cpo_save = &cpo 93 | set cpo&vim 94 | 95 | let s:plug_src = 'https://github.com/junegunn/vim-plug.git' 96 | let s:plug_tab = get(s:, 'plug_tab', -1) 97 | let s:plug_buf = get(s:, 'plug_buf', -1) 98 | let s:mac_gui = has('gui_macvim') && has('gui_running') 99 | let s:is_win = has('win32') || has('win64') 100 | let s:nvim = has('nvim') && exists('*jobwait') && !s:is_win 101 | let s:me = resolve(expand(':p')) 102 | let s:base_spec = { 'branch': 'master', 'frozen': 0 } 103 | let s:TYPE = { 104 | \ 'string': type(''), 105 | \ 'list': type([]), 106 | \ 'dict': type({}), 107 | \ 'funcref': type(function('call')) 108 | \ } 109 | let s:loaded = get(s:, 'loaded', {}) 110 | let s:triggers = get(s:, 'triggers', {}) 111 | 112 | function! plug#begin(...) 113 | if a:0 > 0 114 | let s:plug_home_org = a:1 115 | let home = s:path(fnamemodify(expand(a:1), ':p')) 116 | elseif exists('g:plug_home') 117 | let home = s:path(g:plug_home) 118 | elseif !empty(&rtp) 119 | let home = s:path(split(&rtp, ',')[0]) . '/plugged' 120 | else 121 | return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.') 122 | endif 123 | 124 | let g:plug_home = home 125 | let g:plugs = {} 126 | let g:plugs_order = [] 127 | let s:triggers = {} 128 | 129 | call s:define_commands() 130 | return 1 131 | endfunction 132 | 133 | function! s:define_commands() 134 | command! -nargs=+ -bar Plug call plug#() 135 | if !executable('git') 136 | return s:err('`git` executable not found. Most commands will not be available. To suppress this message, prepend `silent!` to `call plug#begin(...)`.') 137 | endif 138 | command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(0, []) 139 | command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(0, []) 140 | command! -nargs=0 -bar -bang PlugClean call s:clean(0) 141 | command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(s:me) | endif 142 | command! -nargs=0 -bar PlugStatus call s:status() 143 | command! -nargs=0 -bar PlugDiff call s:diff() 144 | command! -nargs=? -bar -bang -complete=file PlugSnapshot call s:snapshot(0, ) 145 | endfunction 146 | 147 | function! s:to_a(v) 148 | return type(a:v) == s:TYPE.list ? a:v : [a:v] 149 | endfunction 150 | 151 | function! s:to_s(v) 152 | return type(a:v) == s:TYPE.string ? a:v : join(a:v, "\n") . "\n" 153 | endfunction 154 | 155 | function! s:glob(from, pattern) 156 | return s:lines(globpath(a:from, a:pattern)) 157 | endfunction 158 | 159 | function! s:source(from, ...) 160 | let found = 0 161 | for pattern in a:000 162 | for vim in s:glob(a:from, pattern) 163 | execute 'source' s:esc(vim) 164 | let found = 1 165 | endfor 166 | endfor 167 | return found 168 | endfunction 169 | 170 | function! s:assoc(dict, key, val) 171 | let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) 172 | endfunction 173 | 174 | function! s:ask(message, ...) 175 | call inputsave() 176 | echohl WarningMsg 177 | let answer = input(a:message.(a:0 ? ' (y/N/a) ' : ' (y/N) ')) 178 | echohl None 179 | call inputrestore() 180 | echo "\r" 181 | return (a:0 && answer =~? '^a') ? 2 : (answer =~? '^y') ? 1 : 0 182 | endfunction 183 | 184 | function! s:ask_no_interrupt(...) 185 | try 186 | return call('s:ask', a:000) 187 | catch 188 | return 0 189 | endtry 190 | endfunction 191 | 192 | function! plug#end() 193 | if !exists('g:plugs') 194 | return s:err('Call plug#begin() first') 195 | endif 196 | 197 | if exists('#PlugLOD') 198 | augroup PlugLOD 199 | autocmd! 200 | augroup END 201 | augroup! PlugLOD 202 | endif 203 | let lod = { 'ft': {}, 'map': {}, 'cmd': {} } 204 | 205 | filetype off 206 | for name in g:plugs_order 207 | if !has_key(g:plugs, name) 208 | continue 209 | endif 210 | let plug = g:plugs[name] 211 | if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for') 212 | let s:loaded[name] = 1 213 | continue 214 | endif 215 | 216 | if has_key(plug, 'on') 217 | let s:triggers[name] = { 'map': [], 'cmd': [] } 218 | for cmd in s:to_a(plug.on) 219 | if cmd =~? '^.\+' 220 | if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i')) 221 | call s:assoc(lod.map, cmd, name) 222 | endif 223 | call add(s:triggers[name].map, cmd) 224 | elseif cmd =~# '^[A-Z]' 225 | if exists(':'.cmd) != 2 226 | call s:assoc(lod.cmd, cmd, name) 227 | endif 228 | call add(s:triggers[name].cmd, cmd) 229 | else 230 | call s:err('Invalid `on` option: '.cmd. 231 | \ '. Should start with an uppercase letter or ``.') 232 | endif 233 | endfor 234 | endif 235 | 236 | if has_key(plug, 'for') 237 | let types = s:to_a(plug.for) 238 | if !empty(types) 239 | augroup filetypedetect 240 | call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') 241 | augroup END 242 | endif 243 | for type in types 244 | call s:assoc(lod.ft, type, name) 245 | endfor 246 | endif 247 | endfor 248 | 249 | for [cmd, names] in items(lod.cmd) 250 | execute printf( 251 | \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "", , , , %s)', 252 | \ cmd, string(cmd), string(names)) 253 | endfor 254 | 255 | for [map, names] in items(lod.map) 256 | for [mode, map_prefix, key_prefix] in 257 | \ [['i', '', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] 258 | execute printf( 259 | \ '%snoremap %s %s:call lod_map(%s, %s, "%s")', 260 | \ mode, map, map_prefix, string(map), string(names), key_prefix) 261 | endfor 262 | endfor 263 | 264 | for [ft, names] in items(lod.ft) 265 | augroup PlugLOD 266 | execute printf('autocmd FileType %s call lod_ft(%s, %s)', 267 | \ ft, string(ft), string(names)) 268 | augroup END 269 | endfor 270 | 271 | call s:reorg_rtp() 272 | filetype plugin indent on 273 | if has('vim_starting') 274 | if has('syntax') && !exists('g:syntax_on') 275 | syntax enable 276 | end 277 | else 278 | call s:reload_plugins() 279 | endif 280 | endfunction 281 | 282 | function! s:loaded_names() 283 | return filter(copy(g:plugs_order), 'get(s:loaded, v:val, 0)') 284 | endfunction 285 | 286 | function! s:load_plugin(spec) 287 | call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim') 288 | endfunction 289 | 290 | function! s:reload_plugins() 291 | for name in s:loaded_names() 292 | call s:load_plugin(g:plugs[name]) 293 | endfor 294 | endfunction 295 | 296 | function! s:trim(str) 297 | return substitute(a:str, '[\/]\+$', '', '') 298 | endfunction 299 | 300 | function! s:version_requirement(val, min) 301 | for idx in range(0, len(a:min) - 1) 302 | let v = get(a:val, idx, 0) 303 | if v < a:min[idx] | return 0 304 | elseif v > a:min[idx] | return 1 305 | endif 306 | endfor 307 | return 1 308 | endfunction 309 | 310 | function! s:git_version_requirement(...) 311 | if !exists('s:git_version') 312 | let s:git_version = map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)') 313 | endif 314 | return s:version_requirement(s:git_version, a:000) 315 | endfunction 316 | 317 | function! s:progress_opt(base) 318 | return a:base && !s:is_win && 319 | \ s:git_version_requirement(1, 7, 1) ? '--progress' : '' 320 | endfunction 321 | 322 | if s:is_win 323 | function! s:rtp(spec) 324 | return s:path(a:spec.dir . get(a:spec, 'rtp', '')) 325 | endfunction 326 | 327 | function! s:path(path) 328 | return s:trim(substitute(a:path, '/', '\', 'g')) 329 | endfunction 330 | 331 | function! s:dirpath(path) 332 | return s:path(a:path) . '\' 333 | endfunction 334 | 335 | function! s:is_local_plug(repo) 336 | return a:repo =~? '^[a-z]:\|^[%~]' 337 | endfunction 338 | else 339 | function! s:rtp(spec) 340 | return s:dirpath(a:spec.dir . get(a:spec, 'rtp', '')) 341 | endfunction 342 | 343 | function! s:path(path) 344 | return s:trim(a:path) 345 | endfunction 346 | 347 | function! s:dirpath(path) 348 | return substitute(a:path, '[/\\]*$', '/', '') 349 | endfunction 350 | 351 | function! s:is_local_plug(repo) 352 | return a:repo[0] =~ '[/$~]' 353 | endfunction 354 | endif 355 | 356 | function! s:err(msg) 357 | echohl ErrorMsg 358 | echom '[vim-plug] '.a:msg 359 | echohl None 360 | endfunction 361 | 362 | function! s:warn(cmd, msg) 363 | echohl WarningMsg 364 | execute a:cmd 'a:msg' 365 | echohl None 366 | endfunction 367 | 368 | function! s:esc(path) 369 | return escape(a:path, ' ') 370 | endfunction 371 | 372 | function! s:escrtp(path) 373 | return escape(a:path, ' ,') 374 | endfunction 375 | 376 | function! s:remove_rtp() 377 | for name in s:loaded_names() 378 | let rtp = s:rtp(g:plugs[name]) 379 | execute 'set rtp-='.s:escrtp(rtp) 380 | let after = globpath(rtp, 'after') 381 | if isdirectory(after) 382 | execute 'set rtp-='.s:escrtp(after) 383 | endif 384 | endfor 385 | endfunction 386 | 387 | function! s:reorg_rtp() 388 | if !empty(s:first_rtp) 389 | execute 'set rtp-='.s:first_rtp 390 | execute 'set rtp-='.s:last_rtp 391 | endif 392 | 393 | " &rtp is modified from outside 394 | if exists('s:prtp') && s:prtp !=# &rtp 395 | call s:remove_rtp() 396 | unlet! s:middle 397 | endif 398 | 399 | let s:middle = get(s:, 'middle', &rtp) 400 | let rtps = map(s:loaded_names(), 's:rtp(g:plugs[v:val])') 401 | let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), 'isdirectory(v:val)') 402 | let rtp = join(map(rtps, 'escape(v:val, ",")'), ',') 403 | \ . ','.s:middle.',' 404 | \ . join(map(afters, 'escape(v:val, ",")'), ',') 405 | let &rtp = substitute(substitute(rtp, ',,*', ',', 'g'), '^,\|,$', '', 'g') 406 | let s:prtp = &rtp 407 | 408 | if !empty(s:first_rtp) 409 | execute 'set rtp^='.s:first_rtp 410 | execute 'set rtp+='.s:last_rtp 411 | endif 412 | endfunction 413 | 414 | function! s:doautocmd(...) 415 | if exists('#'.join(a:000, '#')) 416 | execute 'doautocmd' ((v:version > 703 || has('patch442')) ? '' : '') join(a:000) 417 | endif 418 | endfunction 419 | 420 | function! s:dobufread(names) 421 | for name in a:names 422 | let path = s:rtp(g:plugs[name]).'/**' 423 | for dir in ['ftdetect', 'ftplugin'] 424 | if len(finddir(dir, path)) 425 | return s:doautocmd('BufRead') 426 | endif 427 | endfor 428 | endfor 429 | endfunction 430 | 431 | function! plug#load(...) 432 | if a:0 == 0 433 | return s:err('Argument missing: plugin name(s) required') 434 | endif 435 | if !exists('g:plugs') 436 | return s:err('plug#begin was not called') 437 | endif 438 | let unknowns = filter(copy(a:000), '!has_key(g:plugs, v:val)') 439 | if !empty(unknowns) 440 | let s = len(unknowns) > 1 ? 's' : '' 441 | return s:err(printf('Unknown plugin%s: %s', s, join(unknowns, ', '))) 442 | end 443 | for name in a:000 444 | call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 445 | endfor 446 | call s:dobufread(a:000) 447 | return 1 448 | endfunction 449 | 450 | function! s:remove_triggers(name) 451 | if !has_key(s:triggers, a:name) 452 | return 453 | endif 454 | for cmd in s:triggers[a:name].cmd 455 | execute 'silent! delc' cmd 456 | endfor 457 | for map in s:triggers[a:name].map 458 | execute 'silent! unmap' map 459 | execute 'silent! iunmap' map 460 | endfor 461 | call remove(s:triggers, a:name) 462 | endfunction 463 | 464 | function! s:lod(names, types, ...) 465 | for name in a:names 466 | call s:remove_triggers(name) 467 | let s:loaded[name] = 1 468 | endfor 469 | call s:reorg_rtp() 470 | 471 | for name in a:names 472 | let rtp = s:rtp(g:plugs[name]) 473 | for dir in a:types 474 | call s:source(rtp, dir.'/**/*.vim') 475 | endfor 476 | if a:0 477 | if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2)) 478 | execute 'runtime' a:1 479 | endif 480 | call s:source(rtp, a:2) 481 | endif 482 | call s:doautocmd('User', name) 483 | endfor 484 | endfunction 485 | 486 | function! s:lod_ft(pat, names) 487 | let syn = 'syntax/'.a:pat.'.vim' 488 | call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn) 489 | execute 'autocmd! PlugLOD FileType' a:pat 490 | call s:doautocmd('filetypeplugin', 'FileType') 491 | call s:doautocmd('filetypeindent', 'FileType') 492 | endfunction 493 | 494 | function! s:lod_cmd(cmd, bang, l1, l2, args, names) 495 | call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 496 | call s:dobufread(a:names) 497 | execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args) 498 | endfunction 499 | 500 | function! s:lod_map(map, names, prefix) 501 | call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 502 | call s:dobufread(a:names) 503 | let extra = '' 504 | while 1 505 | let c = getchar(0) 506 | if c == 0 507 | break 508 | endif 509 | let extra .= nr2char(c) 510 | endwhile 511 | if v:count 512 | call feedkeys(v:count, 'n') 513 | endif 514 | call feedkeys('"'.v:register, 'n') 515 | if mode(1) == 'no' 516 | call feedkeys(v:operator) 517 | endif 518 | call feedkeys(a:prefix . substitute(a:map, '^', "\", '') . extra) 519 | endfunction 520 | 521 | function! plug#(repo, ...) 522 | if a:0 > 1 523 | return s:err('Invalid number of arguments (1..2)') 524 | endif 525 | 526 | try 527 | let repo = s:trim(a:repo) 528 | let opts = a:0 == 1 ? s:parse_options(a:1) : s:base_spec 529 | let name = get(opts, 'as', fnamemodify(repo, ':t:s?\.git$??')) 530 | let spec = extend(s:infer_properties(name, repo), opts) 531 | if !has_key(g:plugs, name) 532 | call add(g:plugs_order, name) 533 | endif 534 | let g:plugs[name] = spec 535 | let s:loaded[name] = get(s:loaded, name, 0) 536 | catch 537 | return s:err(v:exception) 538 | endtry 539 | endfunction 540 | 541 | function! s:parse_options(arg) 542 | let opts = copy(s:base_spec) 543 | let type = type(a:arg) 544 | if type == s:TYPE.string 545 | let opts.tag = a:arg 546 | elseif type == s:TYPE.dict 547 | call extend(opts, a:arg) 548 | if has_key(opts, 'dir') 549 | let opts.dir = s:dirpath(expand(opts.dir)) 550 | endif 551 | else 552 | throw 'Invalid argument type (expected: string or dictionary)' 553 | endif 554 | return opts 555 | endfunction 556 | 557 | function! s:infer_properties(name, repo) 558 | let repo = a:repo 559 | if s:is_local_plug(repo) 560 | return { 'dir': s:dirpath(expand(repo)) } 561 | else 562 | if repo =~ ':' 563 | let uri = repo 564 | else 565 | if repo !~ '/' 566 | let repo = 'vim-scripts/'. repo 567 | endif 568 | let fmt = get(g:, 'plug_url_format', 'https://git::@github.com/%s.git') 569 | let uri = printf(fmt, repo) 570 | endif 571 | let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') ) 572 | return { 'dir': dir, 'uri': uri } 573 | endif 574 | endfunction 575 | 576 | function! s:install(force, names) 577 | call s:update_impl(0, a:force, a:names) 578 | endfunction 579 | 580 | function! s:update(force, names) 581 | call s:update_impl(1, a:force, a:names) 582 | endfunction 583 | 584 | function! plug#helptags() 585 | if !exists('g:plugs') 586 | return s:err('plug#begin was not called') 587 | endif 588 | for spec in values(g:plugs) 589 | let docd = join([spec.dir, 'doc'], '/') 590 | if isdirectory(docd) 591 | silent! execute 'helptags' s:esc(docd) 592 | endif 593 | endfor 594 | return 1 595 | endfunction 596 | 597 | function! s:syntax() 598 | syntax clear 599 | syntax region plug1 start=/\%1l/ end=/\%2l/ contains=plugNumber 600 | syntax region plug2 start=/\%2l/ end=/\%3l/ contains=plugBracket,plugX 601 | syn match plugNumber /[0-9]\+[0-9.]*/ contained 602 | syn match plugBracket /[[\]]/ contained 603 | syn match plugX /x/ contained 604 | syn match plugDash /^-/ 605 | syn match plugPlus /^+/ 606 | syn match plugStar /^*/ 607 | syn match plugMessage /\(^- \)\@<=.*/ 608 | syn match plugName /\(^- \)\@<=[^ ]*:/ 609 | syn match plugSha /\%(: \)\@<=[0-9a-f]\{4,}$/ 610 | syn match plugTag /(tag: [^)]\+)/ 611 | syn match plugInstall /\(^+ \)\@<=[^:]*/ 612 | syn match plugUpdate /\(^* \)\@<=[^:]*/ 613 | syn match plugCommit /^ \X*[0-9a-f]\{7} .*/ contains=plugRelDate,plugEdge,plugTag 614 | syn match plugEdge /^ \X\+$/ 615 | syn match plugEdge /^ \X*/ contained nextgroup=plugSha 616 | syn match plugSha /[0-9a-f]\{7}/ contained 617 | syn match plugRelDate /([^)]*)$/ contained 618 | syn match plugNotLoaded /(not loaded)$/ 619 | syn match plugError /^x.*/ 620 | syn region plugDeleted start=/^\~ .*/ end=/^\ze\S/ 621 | syn match plugH2 /^.*:\n-\+$/ 622 | syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean 623 | hi def link plug1 Title 624 | hi def link plug2 Repeat 625 | hi def link plugH2 Type 626 | hi def link plugX Exception 627 | hi def link plugBracket Structure 628 | hi def link plugNumber Number 629 | 630 | hi def link plugDash Special 631 | hi def link plugPlus Constant 632 | hi def link plugStar Boolean 633 | 634 | hi def link plugMessage Function 635 | hi def link plugName Label 636 | hi def link plugInstall Function 637 | hi def link plugUpdate Type 638 | 639 | hi def link plugError Error 640 | hi def link plugDeleted Ignore 641 | hi def link plugRelDate Comment 642 | hi def link plugEdge PreProc 643 | hi def link plugSha Identifier 644 | hi def link plugTag Constant 645 | 646 | hi def link plugNotLoaded Comment 647 | endfunction 648 | 649 | function! s:lpad(str, len) 650 | return a:str . repeat(' ', a:len - len(a:str)) 651 | endfunction 652 | 653 | function! s:lines(msg) 654 | return split(a:msg, "[\r\n]") 655 | endfunction 656 | 657 | function! s:lastline(msg) 658 | return get(s:lines(a:msg), -1, '') 659 | endfunction 660 | 661 | function! s:new_window() 662 | execute get(g:, 'plug_window', 'vertical topleft new') 663 | endfunction 664 | 665 | function! s:plug_window_exists() 666 | let buflist = tabpagebuflist(s:plug_tab) 667 | return !empty(buflist) && index(buflist, s:plug_buf) >= 0 668 | endfunction 669 | 670 | function! s:switch_in() 671 | if !s:plug_window_exists() 672 | return 0 673 | endif 674 | 675 | if winbufnr(0) != s:plug_buf 676 | let s:pos = [tabpagenr(), winnr(), winsaveview()] 677 | execute 'normal!' s:plug_tab.'gt' 678 | let winnr = bufwinnr(s:plug_buf) 679 | execute winnr.'wincmd w' 680 | call add(s:pos, winsaveview()) 681 | else 682 | let s:pos = [winsaveview()] 683 | endif 684 | 685 | setlocal modifiable 686 | return 1 687 | endfunction 688 | 689 | function! s:switch_out(...) 690 | call winrestview(s:pos[-1]) 691 | setlocal nomodifiable 692 | if a:0 > 0 693 | execute a:1 694 | endif 695 | 696 | if len(s:pos) > 1 697 | execute 'normal!' s:pos[0].'gt' 698 | execute s:pos[1] 'wincmd w' 699 | call winrestview(s:pos[2]) 700 | endif 701 | endfunction 702 | 703 | function! s:finish_bindings() 704 | nnoremap R :call retry() 705 | nnoremap D :PlugDiff 706 | nnoremap S :PlugStatus 707 | nnoremap U :call status_update() 708 | xnoremap U :call status_update() 709 | nnoremap ]] :silent! call section('') 710 | nnoremap [[ :silent! call section('b') 711 | endfunction 712 | 713 | function! s:prepare(...) 714 | if empty(getcwd()) 715 | throw 'Invalid current working directory. Cannot proceed.' 716 | endif 717 | 718 | for evar in ['$GIT_DIR', '$GIT_WORK_TREE'] 719 | if exists(evar) 720 | throw evar.' detected. Cannot proceed.' 721 | endif 722 | endfor 723 | 724 | call s:job_abort() 725 | if s:switch_in() 726 | normal q 727 | endif 728 | 729 | call s:new_window() 730 | nnoremap q :if b:plug_preview==1pcendifbd 731 | if a:0 == 0 732 | call s:finish_bindings() 733 | endif 734 | let b:plug_preview = -1 735 | let s:plug_tab = tabpagenr() 736 | let s:plug_buf = winbufnr(0) 737 | call s:assign_name() 738 | 739 | for k in ['', 'L', 'o', 'X', 'd', 'dd'] 740 | execute 'silent! unmap ' k 741 | endfor 742 | setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable 743 | setf vim-plug 744 | if exists('g:syntax_on') 745 | call s:syntax() 746 | endif 747 | endfunction 748 | 749 | function! s:assign_name() 750 | " Assign buffer name 751 | let prefix = '[Plugins]' 752 | let name = prefix 753 | let idx = 2 754 | while bufexists(name) 755 | let name = printf('%s (%s)', prefix, idx) 756 | let idx = idx + 1 757 | endwhile 758 | silent! execute 'f' fnameescape(name) 759 | endfunction 760 | 761 | function! s:chsh(swap) 762 | let prev = [&shell, &shellredir] 763 | if !s:is_win && a:swap 764 | set shell=sh shellredir=>%s\ 2>&1 765 | endif 766 | return prev 767 | endfunction 768 | 769 | function! s:bang(cmd, ...) 770 | try 771 | let [sh, shrd] = s:chsh(a:0) 772 | " FIXME: Escaping is incomplete. We could use shellescape with eval, 773 | " but it won't work on Windows. 774 | let cmd = a:0 ? s:with_cd(a:cmd, a:1) : a:cmd 775 | let g:_plug_bang = '!'.escape(cmd, '#!%') 776 | execute "normal! :execute g:_plug_bang\\" 777 | finally 778 | unlet g:_plug_bang 779 | let [&shell, &shellredir] = [sh, shrd] 780 | endtry 781 | return v:shell_error ? 'Exit status: ' . v:shell_error : '' 782 | endfunction 783 | 784 | function! s:regress_bar() 785 | let bar = substitute(getline(2)[1:-2], '.*\zs=', 'x', '') 786 | call s:progress_bar(2, bar, len(bar)) 787 | endfunction 788 | 789 | function! s:is_updated(dir) 790 | return !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', a:dir)) 791 | endfunction 792 | 793 | function! s:do(pull, force, todo) 794 | for [name, spec] in items(a:todo) 795 | if !isdirectory(spec.dir) 796 | continue 797 | endif 798 | let installed = has_key(s:update.new, name) 799 | let updated = installed ? 0 : 800 | \ (a:pull && index(s:update.errors, name) < 0 && s:is_updated(spec.dir)) 801 | if a:force || installed || updated 802 | execute 'cd' s:esc(spec.dir) 803 | call append(3, '- Post-update hook for '. name .' ... ') 804 | let error = '' 805 | let type = type(spec.do) 806 | if type == s:TYPE.string 807 | if spec.do[0] == ':' 808 | call s:load_plugin(spec) 809 | execute spec.do[1:] 810 | else 811 | let error = s:bang(spec.do) 812 | endif 813 | elseif type == s:TYPE.funcref 814 | try 815 | let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged') 816 | call spec.do({ 'name': name, 'status': status, 'force': a:force }) 817 | catch 818 | let error = v:exception 819 | endtry 820 | else 821 | let error = 'Invalid hook type' 822 | endif 823 | call s:switch_in() 824 | call setline(4, empty(error) ? (getline(4) . 'OK') 825 | \ : ('x' . getline(4)[1:] . error)) 826 | if !empty(error) 827 | call add(s:update.errors, name) 828 | call s:regress_bar() 829 | endif 830 | cd - 831 | endif 832 | endfor 833 | endfunction 834 | 835 | function! s:hash_match(a, b) 836 | return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0 837 | endfunction 838 | 839 | function! s:checkout(spec) 840 | let sha = a:spec.commit 841 | let output = s:system('git rev-parse HEAD', a:spec.dir) 842 | if !v:shell_error && !s:hash_match(sha, s:lines(output)[0]) 843 | let output = s:system( 844 | \ 'git fetch --depth 999999 && git checkout '.s:esc(sha), a:spec.dir) 845 | endif 846 | return output 847 | endfunction 848 | 849 | function! s:finish(pull) 850 | let new_frozen = len(filter(keys(s:update.new), 'g:plugs[v:val].frozen')) 851 | if new_frozen 852 | let s = new_frozen > 1 ? 's' : '' 853 | call append(3, printf('- Installed %d frozen plugin%s', new_frozen, s)) 854 | endif 855 | call append(3, '- Finishing ... ') | 4 856 | redraw 857 | call plug#helptags() 858 | call plug#end() 859 | call setline(4, getline(4) . 'Done!') 860 | redraw 861 | let msgs = [] 862 | if !empty(s:update.errors) 863 | call add(msgs, "Press 'R' to retry.") 864 | endif 865 | if a:pull && len(s:update.new) < len(filter(getline(5, '$'), 866 | \ "v:val =~ '^- ' && stridx(v:val, 'Already up-to-date') < 0")) 867 | call add(msgs, "Press 'D' to see the updated changes.") 868 | endif 869 | echo join(msgs, ' ') 870 | call s:finish_bindings() 871 | endfunction 872 | 873 | function! s:retry() 874 | if empty(s:update.errors) 875 | return 876 | endif 877 | echo 878 | call s:update_impl(s:update.pull, s:update.force, 879 | \ extend(copy(s:update.errors), [s:update.threads])) 880 | endfunction 881 | 882 | function! s:is_managed(name) 883 | return has_key(g:plugs[a:name], 'uri') 884 | endfunction 885 | 886 | function! s:names(...) 887 | return sort(filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')) 888 | endfunction 889 | 890 | function! s:check_ruby() 891 | silent! ruby require 'thread'; VIM::command("let g:plug_ruby = '#{RUBY_VERSION}'") 892 | if !exists('g:plug_ruby') 893 | redraw! 894 | return s:warn('echom', 'Warning: Ruby interface is broken') 895 | endif 896 | let ruby_version = split(g:plug_ruby, '\.') 897 | unlet g:plug_ruby 898 | return s:version_requirement(ruby_version, [1, 8, 7]) 899 | endfunction 900 | 901 | function! s:update_impl(pull, force, args) abort 902 | let args = copy(a:args) 903 | let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ? 904 | \ remove(args, -1) : get(g:, 'plug_threads', 16) 905 | 906 | let managed = filter(copy(g:plugs), 's:is_managed(v:key)') 907 | let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') : 908 | \ filter(managed, 'index(args, v:key) >= 0') 909 | 910 | if empty(todo) 911 | return s:warn('echo', 'No plugin to '. (a:pull ? 'update' : 'install')) 912 | endif 913 | 914 | if !s:is_win && s:git_version_requirement(2, 3) 915 | let s:git_terminal_prompt = exists('$GIT_TERMINAL_PROMPT') ? $GIT_TERMINAL_PROMPT : '' 916 | let $GIT_TERMINAL_PROMPT = 0 917 | for plug in values(todo) 918 | let plug.uri = substitute(plug.uri, 919 | \ '^https://git::@github\.com', 'https://github.com', '') 920 | endfor 921 | endif 922 | 923 | if !isdirectory(g:plug_home) 924 | try 925 | call mkdir(g:plug_home, 'p') 926 | catch 927 | return s:err(printf('Invalid plug directory: %s. '. 928 | \ 'Try to call plug#begin with a valid directory', g:plug_home)) 929 | endtry 930 | endif 931 | 932 | if has('nvim') && !exists('*jobwait') && threads > 1 933 | call s:warn('echom', '[vim-plug] Update Neovim for parallel installer') 934 | endif 935 | 936 | let python = (has('python') || has('python3')) && (!s:nvim || has('vim_starting')) 937 | let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && s:check_ruby() 938 | 939 | let s:update = { 940 | \ 'start': reltime(), 941 | \ 'all': todo, 942 | \ 'todo': copy(todo), 943 | \ 'errors': [], 944 | \ 'pull': a:pull, 945 | \ 'force': a:force, 946 | \ 'new': {}, 947 | \ 'threads': (python || ruby || s:nvim) ? min([len(todo), threads]) : 1, 948 | \ 'bar': '', 949 | \ 'fin': 0 950 | \ } 951 | 952 | call s:prepare(1) 953 | call append(0, ['', '']) 954 | normal! 2G 955 | silent! redraw 956 | 957 | let s:clone_opt = get(g:, 'plug_shallow', 1) ? 958 | \ '--depth 1' . (s:git_version_requirement(1, 7, 10) ? ' --no-single-branch' : '') : '' 959 | 960 | " Python version requirement (>= 2.7) 961 | if python && !has('python3') && !ruby && !s:nvim && s:update.threads > 1 962 | redir => pyv 963 | silent python import platform; print platform.python_version() 964 | redir END 965 | let python = s:version_requirement( 966 | \ map(split(split(pyv)[0], '\.'), 'str2nr(v:val)'), [2, 6]) 967 | endif 968 | 969 | if (python || ruby) && s:update.threads > 1 970 | try 971 | let imd = &imd 972 | if s:mac_gui 973 | set noimd 974 | endif 975 | if ruby 976 | call s:update_ruby() 977 | else 978 | call s:update_python() 979 | endif 980 | catch 981 | let lines = getline(4, '$') 982 | let printed = {} 983 | silent! 4,$d _ 984 | for line in lines 985 | let name = s:extract_name(line, '.', '') 986 | if empty(name) || !has_key(printed, name) 987 | call append('$', line) 988 | if !empty(name) 989 | let printed[name] = 1 990 | if line[0] == 'x' && index(s:update.errors, name) < 0 991 | call add(s:update.errors, name) 992 | end 993 | endif 994 | endif 995 | endfor 996 | finally 997 | let &imd = imd 998 | call s:update_finish() 999 | endtry 1000 | else 1001 | call s:update_vim() 1002 | endif 1003 | endfunction 1004 | 1005 | function! s:log4(name, msg) 1006 | call setline(4, printf('- %s (%s)', a:msg, a:name)) 1007 | redraw 1008 | endfunction 1009 | 1010 | function! s:update_finish() 1011 | if exists('s:git_terminal_prompt') 1012 | let $GIT_TERMINAL_PROMPT = s:git_terminal_prompt 1013 | endif 1014 | if s:switch_in() 1015 | call append(3, '- Updating ...') | 4 1016 | for [name, spec] in items(filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && (s:update.force || s:update.pull || has_key(s:update.new, v:key))')) 1017 | let pos = s:logpos(name) 1018 | if !pos 1019 | continue 1020 | endif 1021 | if has_key(spec, 'commit') 1022 | call s:log4(name, 'Checking out '.spec.commit) 1023 | let out = s:checkout(spec) 1024 | elseif has_key(spec, 'tag') 1025 | let tag = spec.tag 1026 | if tag =~ '\*' 1027 | let tags = s:lines(s:system('git tag --list '.string(tag).' --sort -version:refname 2>&1', spec.dir)) 1028 | if !v:shell_error && !empty(tags) 1029 | let tag = tags[0] 1030 | call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag)) 1031 | call append(3, '') 1032 | endif 1033 | endif 1034 | call s:log4(name, 'Checking out '.tag) 1035 | let out = s:system('git checkout -q '.s:esc(tag).' 2>&1', spec.dir) 1036 | else 1037 | let branch = s:esc(get(spec, 'branch', 'master')) 1038 | call s:log4(name, 'Merging origin/'.branch) 1039 | let out = s:system('git checkout -q '.branch.' 2>&1' 1040 | \. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir) 1041 | endif 1042 | if !v:shell_error && filereadable(spec.dir.'/.gitmodules') && 1043 | \ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir)) 1044 | call s:log4(name, 'Updating submodules. This may take a while.') 1045 | let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir) 1046 | endif 1047 | let msg = printf('%s %s: %s', v:shell_error ? 'x': '-', name, s:lastline(out)) 1048 | if v:shell_error 1049 | call add(s:update.errors, name) 1050 | call s:regress_bar() 1051 | silent execute pos 'd _' 1052 | call append(4, msg) | 4 1053 | elseif !empty(out) 1054 | call setline(pos, msg) 1055 | endif 1056 | redraw 1057 | endfor 1058 | silent 4 d _ 1059 | call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && has_key(v:val, "do")')) 1060 | call s:finish(s:update.pull) 1061 | call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.') 1062 | call s:switch_out('normal! gg') 1063 | endif 1064 | endfunction 1065 | 1066 | function! s:job_abort() 1067 | if !s:nvim || !exists('s:jobs') 1068 | return 1069 | endif 1070 | 1071 | for [name, j] in items(s:jobs) 1072 | silent! call jobstop(j.jobid) 1073 | if j.new 1074 | call s:system('rm -rf ' . s:shellesc(g:plugs[name].dir)) 1075 | endif 1076 | endfor 1077 | let s:jobs = {} 1078 | endfunction 1079 | 1080 | " When a:event == 'stdout', data = list of strings 1081 | " When a:event == 'exit', data = returncode 1082 | function! s:job_handler(job_id, data, event) abort 1083 | if !s:plug_window_exists() " plug window closed 1084 | return s:job_abort() 1085 | endif 1086 | 1087 | if a:event == 'stdout' 1088 | let complete = empty(a:data[-1]) 1089 | let lines = map(filter(a:data, 'len(v:val) > 0'), 'split(v:val, "[\r\n]")[-1]') 1090 | call extend(self.lines, lines) 1091 | let self.result = join(self.lines, "\n") 1092 | if !complete 1093 | call remove(self.lines, -1) 1094 | endif 1095 | " To reduce the number of buffer updates 1096 | let self.tick = get(self, 'tick', -1) + 1 1097 | if self.tick % len(s:jobs) == 0 1098 | call s:log(self.new ? '+' : '*', self.name, self.result) 1099 | endif 1100 | elseif a:event == 'exit' 1101 | let self.running = 0 1102 | if a:data != 0 1103 | let self.error = 1 1104 | endif 1105 | call s:reap(self.name) 1106 | call s:tick() 1107 | endif 1108 | endfunction 1109 | 1110 | function! s:spawn(name, cmd, opts) 1111 | let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [], 'result': '', 1112 | \ 'new': get(a:opts, 'new', 0), 1113 | \ 'on_stdout': function('s:job_handler'), 1114 | \ 'on_exit' : function('s:job_handler'), 1115 | \ } 1116 | let s:jobs[a:name] = job 1117 | 1118 | if s:nvim 1119 | let argv = [ 'sh', '-c', 1120 | \ (has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd) ] 1121 | let jid = jobstart(argv, job) 1122 | if jid > 0 1123 | let job.jobid = jid 1124 | else 1125 | let job.running = 0 1126 | let job.error = 1 1127 | let job.result = jid < 0 ? 'sh is not executable' : 1128 | \ 'Invalid arguments (or job table is full)' 1129 | endif 1130 | else 1131 | let params = has_key(a:opts, 'dir') ? [a:cmd, a:opts.dir] : [a:cmd] 1132 | let job.result = call('s:system', params) 1133 | let job.error = v:shell_error != 0 1134 | let job.running = 0 1135 | endif 1136 | endfunction 1137 | 1138 | function! s:reap(name) 1139 | let job = s:jobs[a:name] 1140 | if job.error 1141 | call add(s:update.errors, a:name) 1142 | elseif get(job, 'new', 0) 1143 | let s:update.new[a:name] = 1 1144 | endif 1145 | let s:update.bar .= job.error ? 'x' : '=' 1146 | 1147 | call s:log(job.error ? 'x' : '-', a:name, empty(job.result) ? 'OK' : job.result) 1148 | call s:bar() 1149 | 1150 | call remove(s:jobs, a:name) 1151 | endfunction 1152 | 1153 | function! s:bar() 1154 | if s:switch_in() 1155 | let total = len(s:update.all) 1156 | call setline(1, (s:update.pull ? 'Updating' : 'Installing'). 1157 | \ ' plugins ('.len(s:update.bar).'/'.total.')') 1158 | call s:progress_bar(2, s:update.bar, total) 1159 | call s:switch_out() 1160 | endif 1161 | endfunction 1162 | 1163 | function! s:logpos(name) 1164 | for i in range(4, line('$')) 1165 | if getline(i) =~# '^[-+x*] '.a:name.':' 1166 | return i 1167 | endif 1168 | endfor 1169 | endfunction 1170 | 1171 | function! s:log(bullet, name, lines) 1172 | if s:switch_in() 1173 | let pos = s:logpos(a:name) 1174 | if pos > 0 1175 | silent execute pos 'd _' 1176 | if pos > winheight('.') 1177 | let pos = 4 1178 | endif 1179 | else 1180 | let pos = 4 1181 | endif 1182 | call append(pos - 1, s:format_message(a:bullet, a:name, a:lines)) 1183 | call s:switch_out() 1184 | endif 1185 | endfunction 1186 | 1187 | function! s:update_vim() 1188 | let s:jobs = {} 1189 | 1190 | call s:bar() 1191 | call s:tick() 1192 | endfunction 1193 | 1194 | function! s:tick() 1195 | let pull = s:update.pull 1196 | let prog = s:progress_opt(s:nvim) 1197 | while 1 " Without TCO, Vim stack is bound to explode 1198 | if empty(s:update.todo) 1199 | if empty(s:jobs) && !s:update.fin 1200 | let s:update.fin = 1 1201 | call s:update_finish() 1202 | endif 1203 | return 1204 | endif 1205 | 1206 | let name = keys(s:update.todo)[0] 1207 | let spec = remove(s:update.todo, name) 1208 | let new = !isdirectory(spec.dir) 1209 | 1210 | call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...') 1211 | redraw 1212 | 1213 | let has_tag = has_key(spec, 'tag') 1214 | if !new 1215 | let [error, _] = s:git_validate(spec, 0) 1216 | if empty(error) 1217 | if pull 1218 | let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : '' 1219 | call s:spawn(name, printf('git fetch %s %s 2>&1', fetch_opt, prog), { 'dir': spec.dir }) 1220 | else 1221 | let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 } 1222 | endif 1223 | else 1224 | let s:jobs[name] = { 'running': 0, 'result': error, 'error': 1 } 1225 | endif 1226 | else 1227 | call s:spawn(name, 1228 | \ printf('git clone %s %s %s %s 2>&1', 1229 | \ has_tag ? '' : s:clone_opt, 1230 | \ prog, 1231 | \ s:shellesc(spec.uri), 1232 | \ s:shellesc(s:trim(spec.dir))), { 'new': 1 }) 1233 | endif 1234 | 1235 | if !s:jobs[name].running 1236 | call s:reap(name) 1237 | endif 1238 | if len(s:jobs) >= s:update.threads 1239 | break 1240 | endif 1241 | endwhile 1242 | endfunction 1243 | 1244 | function! s:update_python() 1245 | let py_exe = has('python') ? 'python' : 'python3' 1246 | execute py_exe "<< EOF" 1247 | import datetime 1248 | import functools 1249 | import os 1250 | try: 1251 | import queue 1252 | except ImportError: 1253 | import Queue as queue 1254 | import random 1255 | import re 1256 | import shutil 1257 | import signal 1258 | import subprocess 1259 | import tempfile 1260 | import threading as thr 1261 | import time 1262 | import traceback 1263 | import vim 1264 | 1265 | G_NVIM = vim.eval("has('nvim')") == '1' 1266 | G_PULL = vim.eval('s:update.pull') == '1' 1267 | G_RETRIES = int(vim.eval('get(g:, "plug_retries", 2)')) + 1 1268 | G_TIMEOUT = int(vim.eval('get(g:, "plug_timeout", 60)')) 1269 | G_CLONE_OPT = vim.eval('s:clone_opt') 1270 | G_PROGRESS = vim.eval('s:progress_opt(1)') 1271 | G_LOG_PROB = 1.0 / int(vim.eval('s:update.threads')) 1272 | G_STOP = thr.Event() 1273 | G_IS_WIN = vim.eval('s:is_win') == '1' 1274 | 1275 | class PlugError(Exception): 1276 | def __init__(self, msg): 1277 | self.msg = msg 1278 | class CmdTimedOut(PlugError): 1279 | pass 1280 | class CmdFailed(PlugError): 1281 | pass 1282 | class InvalidURI(PlugError): 1283 | pass 1284 | class Action(object): 1285 | INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-'] 1286 | 1287 | class Buffer(object): 1288 | def __init__(self, lock, num_plugs, is_pull): 1289 | self.bar = '' 1290 | self.event = 'Updating' if is_pull else 'Installing' 1291 | self.lock = lock 1292 | self.maxy = int(vim.eval('winheight(".")')) 1293 | self.num_plugs = num_plugs 1294 | 1295 | def __where(self, name): 1296 | """ Find first line with name in current buffer. Return line num. """ 1297 | found, lnum = False, 0 1298 | matcher = re.compile('^[-+x*] {0}:'.format(name)) 1299 | for line in vim.current.buffer: 1300 | if matcher.search(line) is not None: 1301 | found = True 1302 | break 1303 | lnum += 1 1304 | 1305 | if not found: 1306 | lnum = -1 1307 | return lnum 1308 | 1309 | def header(self): 1310 | curbuf = vim.current.buffer 1311 | curbuf[0] = self.event + ' plugins ({0}/{1})'.format(len(self.bar), self.num_plugs) 1312 | 1313 | num_spaces = self.num_plugs - len(self.bar) 1314 | curbuf[1] = '[{0}{1}]'.format(self.bar, num_spaces * ' ') 1315 | 1316 | with self.lock: 1317 | vim.command('normal! 2G') 1318 | vim.command('redraw') 1319 | 1320 | def write(self, action, name, lines): 1321 | first, rest = lines[0], lines[1:] 1322 | msg = ['{0} {1}{2}{3}'.format(action, name, ': ' if first else '', first)] 1323 | msg.extend([' ' + line for line in rest]) 1324 | 1325 | try: 1326 | if action == Action.ERROR: 1327 | self.bar += 'x' 1328 | vim.command("call add(s:update.errors, '{0}')".format(name)) 1329 | elif action == Action.DONE: 1330 | self.bar += '=' 1331 | 1332 | curbuf = vim.current.buffer 1333 | lnum = self.__where(name) 1334 | if lnum != -1: # Found matching line num 1335 | del curbuf[lnum] 1336 | if lnum > self.maxy and action in set([Action.INSTALL, Action.UPDATE]): 1337 | lnum = 3 1338 | else: 1339 | lnum = 3 1340 | curbuf.append(msg, lnum) 1341 | 1342 | self.header() 1343 | except vim.error: 1344 | pass 1345 | 1346 | class Command(object): 1347 | CD = 'cd /d' if G_IS_WIN else 'cd' 1348 | 1349 | def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None): 1350 | self.cmd = cmd 1351 | if cmd_dir: 1352 | self.cmd = '{0} {1} && {2}'.format(Command.CD, cmd_dir, self.cmd) 1353 | self.timeout = timeout 1354 | self.callback = cb if cb else (lambda msg: None) 1355 | self.clean = clean if clean else (lambda: None) 1356 | self.proc = None 1357 | 1358 | @property 1359 | def alive(self): 1360 | """ Returns true only if command still running. """ 1361 | return self.proc and self.proc.poll() is None 1362 | 1363 | def execute(self, ntries=3): 1364 | """ Execute the command with ntries if CmdTimedOut. 1365 | Returns the output of the command if no Exception. 1366 | """ 1367 | attempt, finished, limit = 0, False, self.timeout 1368 | 1369 | while not finished: 1370 | try: 1371 | attempt += 1 1372 | result = self.try_command() 1373 | finished = True 1374 | return result 1375 | except CmdTimedOut: 1376 | if attempt != ntries: 1377 | self.notify_retry() 1378 | self.timeout += limit 1379 | else: 1380 | raise 1381 | 1382 | def notify_retry(self): 1383 | """ Retry required for command, notify user. """ 1384 | for count in range(3, 0, -1): 1385 | if G_STOP.is_set(): 1386 | raise KeyboardInterrupt 1387 | msg = 'Timeout. Will retry in {0} second{1} ...'.format( 1388 | count, 's' if count != 1 else '') 1389 | self.callback([msg]) 1390 | time.sleep(1) 1391 | self.callback(['Retrying ...']) 1392 | 1393 | def try_command(self): 1394 | """ Execute a cmd & poll for callback. Returns list of output. 1395 | Raises CmdFailed -> return code for Popen isn't 0 1396 | Raises CmdTimedOut -> command exceeded timeout without new output 1397 | """ 1398 | first_line = True 1399 | 1400 | try: 1401 | tfile = tempfile.NamedTemporaryFile(mode='w+b') 1402 | preexec_fn = not G_IS_WIN and os.setsid or None 1403 | self.proc = subprocess.Popen(self.cmd, stdout=tfile, 1404 | stderr=subprocess.STDOUT, 1405 | stdin=subprocess.PIPE, shell=True, 1406 | preexec_fn=preexec_fn) 1407 | thrd = thr.Thread(target=(lambda proc: proc.wait()), args=(self.proc,)) 1408 | thrd.start() 1409 | 1410 | thread_not_started = True 1411 | while thread_not_started: 1412 | try: 1413 | thrd.join(0.1) 1414 | thread_not_started = False 1415 | except RuntimeError: 1416 | pass 1417 | 1418 | while self.alive: 1419 | if G_STOP.is_set(): 1420 | raise KeyboardInterrupt 1421 | 1422 | if first_line or random.random() < G_LOG_PROB: 1423 | first_line = False 1424 | line = '' if G_IS_WIN else nonblock_read(tfile.name) 1425 | if line: 1426 | self.callback([line]) 1427 | 1428 | time_diff = time.time() - os.path.getmtime(tfile.name) 1429 | if time_diff > self.timeout: 1430 | raise CmdTimedOut(['Timeout!']) 1431 | 1432 | thrd.join(0.5) 1433 | 1434 | tfile.seek(0) 1435 | result = [line.decode('utf-8', 'replace').rstrip() for line in tfile] 1436 | 1437 | if self.proc.returncode != 0: 1438 | raise CmdFailed([''] + result) 1439 | 1440 | return result 1441 | except: 1442 | self.terminate() 1443 | raise 1444 | 1445 | def terminate(self): 1446 | """ Terminate process and cleanup. """ 1447 | if self.alive: 1448 | if G_IS_WIN: 1449 | os.kill(self.proc.pid, signal.SIGINT) 1450 | else: 1451 | os.killpg(self.proc.pid, signal.SIGTERM) 1452 | self.clean() 1453 | 1454 | class Plugin(object): 1455 | def __init__(self, name, args, buf_q, lock): 1456 | self.name = name 1457 | self.args = args 1458 | self.buf_q = buf_q 1459 | self.lock = lock 1460 | self.tag = args.get('tag', 0) 1461 | 1462 | def manage(self): 1463 | try: 1464 | if os.path.exists(self.args['dir']): 1465 | self.update() 1466 | else: 1467 | self.install() 1468 | with self.lock: 1469 | thread_vim_command("let s:update.new['{0}'] = 1".format(self.name)) 1470 | except PlugError as exc: 1471 | self.write(Action.ERROR, self.name, exc.msg) 1472 | except KeyboardInterrupt: 1473 | G_STOP.set() 1474 | self.write(Action.ERROR, self.name, ['Interrupted!']) 1475 | except: 1476 | # Any exception except those above print stack trace 1477 | msg = 'Trace:\n{0}'.format(traceback.format_exc().rstrip()) 1478 | self.write(Action.ERROR, self.name, msg.split('\n')) 1479 | raise 1480 | 1481 | def install(self): 1482 | target = self.args['dir'] 1483 | if target[-1] == '\\': 1484 | target = target[0:-1] 1485 | 1486 | def clean(target): 1487 | def _clean(): 1488 | try: 1489 | shutil.rmtree(target) 1490 | except OSError: 1491 | pass 1492 | return _clean 1493 | 1494 | self.write(Action.INSTALL, self.name, ['Installing ...']) 1495 | callback = functools.partial(self.write, Action.INSTALL, self.name) 1496 | cmd = 'git clone {0} {1} {2} {3} 2>&1'.format( 1497 | '' if self.tag else G_CLONE_OPT, G_PROGRESS, self.args['uri'], 1498 | esc(target)) 1499 | com = Command(cmd, None, G_TIMEOUT, callback, clean(target)) 1500 | result = com.execute(G_RETRIES) 1501 | self.write(Action.DONE, self.name, result[-1:]) 1502 | 1503 | def repo_uri(self): 1504 | cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url' 1505 | command = Command(cmd, self.args['dir'], G_TIMEOUT,) 1506 | result = command.execute(G_RETRIES) 1507 | return result[-1] 1508 | 1509 | def update(self): 1510 | match = re.compile(r'git::?@') 1511 | actual_uri = re.sub(match, '', self.repo_uri()) 1512 | expect_uri = re.sub(match, '', self.args['uri']) 1513 | if actual_uri != expect_uri: 1514 | msg = ['', 1515 | 'Invalid URI: {0}'.format(actual_uri), 1516 | 'Expected {0}'.format(expect_uri), 1517 | 'PlugClean required.'] 1518 | raise InvalidURI(msg) 1519 | 1520 | if G_PULL: 1521 | self.write(Action.UPDATE, self.name, ['Updating ...']) 1522 | callback = functools.partial(self.write, Action.UPDATE, self.name) 1523 | fetch_opt = '--depth 99999999' if self.tag and os.path.isfile(os.path.join(self.args['dir'], '.git/shallow')) else '' 1524 | cmd = 'git fetch {0} {1} 2>&1'.format(fetch_opt, G_PROGRESS) 1525 | com = Command(cmd, self.args['dir'], G_TIMEOUT, callback) 1526 | result = com.execute(G_RETRIES) 1527 | self.write(Action.DONE, self.name, result[-1:]) 1528 | else: 1529 | self.write(Action.DONE, self.name, ['Already installed']) 1530 | 1531 | def write(self, action, name, msg): 1532 | self.buf_q.put((action, name, msg)) 1533 | 1534 | class PlugThread(thr.Thread): 1535 | def __init__(self, tname, args): 1536 | super(PlugThread, self).__init__() 1537 | self.tname = tname 1538 | self.args = args 1539 | 1540 | def run(self): 1541 | thr.current_thread().name = self.tname 1542 | buf_q, work_q, lock = self.args 1543 | 1544 | try: 1545 | while not G_STOP.is_set(): 1546 | name, args = work_q.get_nowait() 1547 | plug = Plugin(name, args, buf_q, lock) 1548 | plug.manage() 1549 | work_q.task_done() 1550 | except queue.Empty: 1551 | pass 1552 | 1553 | class RefreshThread(thr.Thread): 1554 | def __init__(self, lock): 1555 | super(RefreshThread, self).__init__() 1556 | self.lock = lock 1557 | self.running = True 1558 | 1559 | def run(self): 1560 | while self.running: 1561 | with self.lock: 1562 | thread_vim_command('noautocmd normal! a') 1563 | time.sleep(0.33) 1564 | 1565 | def stop(self): 1566 | self.running = False 1567 | 1568 | if G_NVIM: 1569 | def thread_vim_command(cmd): 1570 | vim.session.threadsafe_call(lambda: vim.command(cmd)) 1571 | else: 1572 | def thread_vim_command(cmd): 1573 | vim.command(cmd) 1574 | 1575 | def esc(name): 1576 | return '"' + name.replace('"', '\"') + '"' 1577 | 1578 | def nonblock_read(fname): 1579 | """ Read a file with nonblock flag. Return the last line. """ 1580 | fread = os.open(fname, os.O_RDONLY | os.O_NONBLOCK) 1581 | buf = os.read(fread, 100000).decode('utf-8', 'replace') 1582 | os.close(fread) 1583 | 1584 | line = buf.rstrip('\r\n') 1585 | left = max(line.rfind('\r'), line.rfind('\n')) 1586 | if left != -1: 1587 | left += 1 1588 | line = line[left:] 1589 | 1590 | return line 1591 | 1592 | def main(): 1593 | thr.current_thread().name = 'main' 1594 | nthreads = int(vim.eval('s:update.threads')) 1595 | plugs = vim.eval('s:update.todo') 1596 | mac_gui = vim.eval('s:mac_gui') == '1' 1597 | 1598 | lock = thr.Lock() 1599 | buf = Buffer(lock, len(plugs), G_PULL) 1600 | buf_q, work_q = queue.Queue(), queue.Queue() 1601 | for work in plugs.items(): 1602 | work_q.put(work) 1603 | 1604 | start_cnt = thr.active_count() 1605 | for num in range(nthreads): 1606 | tname = 'PlugT-{0:02}'.format(num) 1607 | thread = PlugThread(tname, (buf_q, work_q, lock)) 1608 | thread.start() 1609 | if mac_gui: 1610 | rthread = RefreshThread(lock) 1611 | rthread.start() 1612 | 1613 | while not buf_q.empty() or thr.active_count() != start_cnt: 1614 | try: 1615 | action, name, msg = buf_q.get(True, 0.25) 1616 | buf.write(action, name, ['OK'] if not msg else msg) 1617 | buf_q.task_done() 1618 | except queue.Empty: 1619 | pass 1620 | except KeyboardInterrupt: 1621 | G_STOP.set() 1622 | 1623 | if mac_gui: 1624 | rthread.stop() 1625 | rthread.join() 1626 | 1627 | main() 1628 | EOF 1629 | endfunction 1630 | 1631 | function! s:update_ruby() 1632 | ruby << EOF 1633 | module PlugStream 1634 | SEP = ["\r", "\n", nil] 1635 | def get_line 1636 | buffer = '' 1637 | loop do 1638 | char = readchar rescue return 1639 | if SEP.include? char.chr 1640 | buffer << $/ 1641 | break 1642 | else 1643 | buffer << char 1644 | end 1645 | end 1646 | buffer 1647 | end 1648 | end unless defined?(PlugStream) 1649 | 1650 | def esc arg 1651 | %["#{arg.gsub('"', '\"')}"] 1652 | end 1653 | 1654 | def killall pid 1655 | pids = [pid] 1656 | if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM 1657 | pids.each { |pid| Process.kill 'INT', pid.to_i rescue nil } 1658 | else 1659 | unless `which pgrep 2> /dev/null`.empty? 1660 | children = pids 1661 | until children.empty? 1662 | children = children.map { |pid| 1663 | `pgrep -P #{pid}`.lines.map { |l| l.chomp } 1664 | }.flatten 1665 | pids += children 1666 | end 1667 | end 1668 | pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } 1669 | end 1670 | end 1671 | 1672 | require 'thread' 1673 | require 'fileutils' 1674 | require 'timeout' 1675 | running = true 1676 | iswin = VIM::evaluate('s:is_win').to_i == 1 1677 | pull = VIM::evaluate('s:update.pull').to_i == 1 1678 | base = VIM::evaluate('g:plug_home') 1679 | all = VIM::evaluate('s:update.todo') 1680 | limit = VIM::evaluate('get(g:, "plug_timeout", 60)') 1681 | tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1 1682 | nthr = VIM::evaluate('s:update.threads').to_i 1683 | maxy = VIM::evaluate('winheight(".")').to_i 1684 | cd = iswin ? 'cd /d' : 'cd' 1685 | tot = VIM::evaluate('len(s:update.todo)') || 0 1686 | bar = '' 1687 | skip = 'Already installed' 1688 | mtx = Mutex.new 1689 | take1 = proc { mtx.synchronize { running && all.shift } } 1690 | logh = proc { 1691 | cnt = bar.length 1692 | $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})" 1693 | $curbuf[2] = '[' + bar.ljust(tot) + ']' 1694 | VIM::command('normal! 2G') 1695 | VIM::command('redraw') 1696 | } 1697 | where = proc { |name| (1..($curbuf.length)).find { |l| $curbuf[l] =~ /^[-+x*] #{name}:/ } } 1698 | log = proc { |name, result, type| 1699 | mtx.synchronize do 1700 | ing = ![true, false].include?(type) 1701 | bar += type ? '=' : 'x' unless ing 1702 | b = case type 1703 | when :install then '+' when :update then '*' 1704 | when true, nil then '-' else 1705 | VIM::command("call add(s:update.errors, '#{name}')") 1706 | 'x' 1707 | end 1708 | result = 1709 | if type || type.nil? 1710 | ["#{b} #{name}: #{result.lines.to_a.last || 'OK'}"] 1711 | elsif result =~ /^Interrupted|^Timeout/ 1712 | ["#{b} #{name}: #{result}"] 1713 | else 1714 | ["#{b} #{name}"] + result.lines.map { |l| " " << l } 1715 | end 1716 | if lnum = where.call(name) 1717 | $curbuf.delete lnum 1718 | lnum = 4 if ing && lnum > maxy 1719 | end 1720 | result.each_with_index do |line, offset| 1721 | $curbuf.append((lnum || 4) - 1 + offset, line.gsub(/\e\[./, '').chomp) 1722 | end 1723 | logh.call 1724 | end 1725 | } 1726 | bt = proc { |cmd, name, type, cleanup| 1727 | tried = timeout = 0 1728 | begin 1729 | tried += 1 1730 | timeout += limit 1731 | fd = nil 1732 | data = '' 1733 | if iswin 1734 | Timeout::timeout(timeout) do 1735 | tmp = VIM::evaluate('tempname()') 1736 | system("(#{cmd}) > #{tmp}") 1737 | data = File.read(tmp).chomp 1738 | File.unlink tmp rescue nil 1739 | end 1740 | else 1741 | fd = IO.popen(cmd).extend(PlugStream) 1742 | first_line = true 1743 | log_prob = 1.0 / nthr 1744 | while line = Timeout::timeout(timeout) { fd.get_line } 1745 | data << line 1746 | log.call name, line.chomp, type if name && (first_line || rand < log_prob) 1747 | first_line = false 1748 | end 1749 | fd.close 1750 | end 1751 | [$? == 0, data.chomp] 1752 | rescue Timeout::Error, Interrupt => e 1753 | if fd && !fd.closed? 1754 | killall fd.pid 1755 | fd.close 1756 | end 1757 | cleanup.call if cleanup 1758 | if e.is_a?(Timeout::Error) && tried < tries 1759 | 3.downto(1) do |countdown| 1760 | s = countdown > 1 ? 's' : '' 1761 | log.call name, "Timeout. Will retry in #{countdown} second#{s} ...", type 1762 | sleep 1 1763 | end 1764 | log.call name, 'Retrying ...', type 1765 | retry 1766 | end 1767 | [false, e.is_a?(Interrupt) ? "Interrupted!" : "Timeout!"] 1768 | end 1769 | } 1770 | main = Thread.current 1771 | threads = [] 1772 | watcher = Thread.new { 1773 | while VIM::evaluate('getchar(1)') 1774 | sleep 0.1 1775 | end 1776 | mtx.synchronize do 1777 | running = false 1778 | threads.each { |t| t.raise Interrupt } 1779 | end 1780 | threads.each { |t| t.join rescue nil } 1781 | main.kill 1782 | } 1783 | refresh = Thread.new { 1784 | while true 1785 | mtx.synchronize do 1786 | break unless running 1787 | VIM::command('noautocmd normal! a') 1788 | end 1789 | sleep 0.2 1790 | end 1791 | } if VIM::evaluate('s:mac_gui') == 1 1792 | 1793 | clone_opt = VIM::evaluate('s:clone_opt') 1794 | progress = VIM::evaluate('s:progress_opt(1)') 1795 | nthr.times do 1796 | mtx.synchronize do 1797 | threads << Thread.new { 1798 | while pair = take1.call 1799 | name = pair.first 1800 | dir, uri, tag = pair.last.values_at *%w[dir uri tag] 1801 | exists = File.directory? dir 1802 | ok, result = 1803 | if exists 1804 | chdir = "#{cd} #{iswin ? dir : esc(dir)}" 1805 | ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url", nil, nil, nil 1806 | current_uri = data.lines.to_a.last 1807 | if !ret 1808 | if data =~ /^Interrupted|^Timeout/ 1809 | [false, data] 1810 | else 1811 | [false, [data.chomp, "PlugClean required."].join($/)] 1812 | end 1813 | elsif current_uri.sub(/git::?@/, '') != uri.sub(/git::?@/, '') 1814 | [false, ["Invalid URI: #{current_uri}", 1815 | "Expected: #{uri}", 1816 | "PlugClean required."].join($/)] 1817 | else 1818 | if pull 1819 | log.call name, 'Updating ...', :update 1820 | fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : '' 1821 | bt.call "#{chdir} && git fetch #{fetch_opt} #{progress} 2>&1", name, :update, nil 1822 | else 1823 | [true, skip] 1824 | end 1825 | end 1826 | else 1827 | d = esc dir.sub(%r{[\\/]+$}, '') 1828 | log.call name, 'Installing ...', :install 1829 | bt.call "git clone #{clone_opt unless tag} #{progress} #{uri} #{d} 2>&1", name, :install, proc { 1830 | FileUtils.rm_rf dir 1831 | } 1832 | end 1833 | mtx.synchronize { VIM::command("let s:update.new['#{name}'] = 1") } if !exists && ok 1834 | log.call name, result, ok 1835 | end 1836 | } if running 1837 | end 1838 | end 1839 | threads.each { |t| t.join rescue nil } 1840 | logh.call 1841 | refresh.kill if refresh 1842 | watcher.kill 1843 | EOF 1844 | endfunction 1845 | 1846 | function! s:shellesc(arg) 1847 | return '"'.escape(a:arg, '"').'"' 1848 | endfunction 1849 | 1850 | function! s:glob_dir(path) 1851 | return map(filter(s:glob(a:path, '**'), 'isdirectory(v:val)'), 's:dirpath(v:val)') 1852 | endfunction 1853 | 1854 | function! s:progress_bar(line, bar, total) 1855 | call setline(a:line, '[' . s:lpad(a:bar, a:total) . ']') 1856 | endfunction 1857 | 1858 | function! s:compare_git_uri(a, b) 1859 | let a = substitute(a:a, 'git:\{1,2}@', '', '') 1860 | let b = substitute(a:b, 'git:\{1,2}@', '', '') 1861 | return a ==# b 1862 | endfunction 1863 | 1864 | function! s:format_message(bullet, name, message) 1865 | if a:bullet != 'x' 1866 | return [printf('%s %s: %s', a:bullet, a:name, s:lastline(a:message))] 1867 | else 1868 | let lines = map(s:lines(a:message), '" ".v:val') 1869 | return extend([printf('x %s:', a:name)], lines) 1870 | endif 1871 | endfunction 1872 | 1873 | function! s:with_cd(cmd, dir) 1874 | return printf('cd%s %s && %s', s:is_win ? ' /d' : '', s:shellesc(a:dir), a:cmd) 1875 | endfunction 1876 | 1877 | function! s:system(cmd, ...) 1878 | try 1879 | let [sh, shrd] = s:chsh(1) 1880 | let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd 1881 | return system(s:is_win ? '('.cmd.')' : cmd) 1882 | finally 1883 | let [&shell, &shellredir] = [sh, shrd] 1884 | endtry 1885 | endfunction 1886 | 1887 | function! s:system_chomp(...) 1888 | let ret = call('s:system', a:000) 1889 | return v:shell_error ? '' : substitute(ret, '\n$', '', '') 1890 | endfunction 1891 | 1892 | function! s:git_validate(spec, check_branch) 1893 | let err = '' 1894 | if isdirectory(a:spec.dir) 1895 | let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url', a:spec.dir)) 1896 | let remote = result[-1] 1897 | if v:shell_error 1898 | let err = join([remote, 'PlugClean required.'], "\n") 1899 | elseif !s:compare_git_uri(remote, a:spec.uri) 1900 | let err = join(['Invalid URI: '.remote, 1901 | \ 'Expected: '.a:spec.uri, 1902 | \ 'PlugClean required.'], "\n") 1903 | elseif a:check_branch && has_key(a:spec, 'commit') 1904 | let result = s:lines(s:system('git rev-parse HEAD 2>&1', a:spec.dir)) 1905 | let sha = result[-1] 1906 | if v:shell_error 1907 | let err = join(add(result, 'PlugClean required.'), "\n") 1908 | elseif !s:hash_match(sha, a:spec.commit) 1909 | let err = join([printf('Invalid HEAD (expected: %s, actual: %s)', 1910 | \ a:spec.commit[:6], sha[:6]), 1911 | \ 'PlugUpdate required.'], "\n") 1912 | endif 1913 | elseif a:check_branch 1914 | let branch = result[0] 1915 | " Check tag 1916 | if has_key(a:spec, 'tag') 1917 | let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir) 1918 | if a:spec.tag !=# tag 1919 | let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', 1920 | \ (empty(tag) ? 'N/A' : tag), a:spec.tag) 1921 | endif 1922 | " Check branch 1923 | elseif a:spec.branch !=# branch 1924 | let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', 1925 | \ branch, a:spec.branch) 1926 | endif 1927 | if empty(err) 1928 | let commits = len(s:lines(s:system(printf('git rev-list origin/%s..HEAD', a:spec.branch), a:spec.dir))) 1929 | if !v:shell_error && commits 1930 | let err = join([printf('Diverged from origin/%s by %d commit(s).', a:spec.branch, commits), 1931 | \ 'Reinstall after PlugClean.'], "\n") 1932 | endif 1933 | endif 1934 | endif 1935 | else 1936 | let err = 'Not found' 1937 | endif 1938 | return [err, err =~# 'PlugClean'] 1939 | endfunction 1940 | 1941 | function! s:rm_rf(dir) 1942 | if isdirectory(a:dir) 1943 | call s:system((s:is_win ? 'rmdir /S /Q ' : 'rm -rf ') . s:shellesc(a:dir)) 1944 | endif 1945 | endfunction 1946 | 1947 | function! s:clean(force) 1948 | call s:prepare() 1949 | call append(0, 'Searching for invalid plugins in '.g:plug_home) 1950 | call append(1, '') 1951 | 1952 | " List of valid directories 1953 | let dirs = [] 1954 | let errs = {} 1955 | let [cnt, total] = [0, len(g:plugs)] 1956 | for [name, spec] in items(g:plugs) 1957 | if !s:is_managed(name) 1958 | call add(dirs, spec.dir) 1959 | else 1960 | let [err, clean] = s:git_validate(spec, 1) 1961 | if clean 1962 | let errs[spec.dir] = s:lines(err)[0] 1963 | else 1964 | call add(dirs, spec.dir) 1965 | endif 1966 | endif 1967 | let cnt += 1 1968 | call s:progress_bar(2, repeat('=', cnt), total) 1969 | normal! 2G 1970 | redraw 1971 | endfor 1972 | 1973 | let allowed = {} 1974 | for dir in dirs 1975 | let allowed[s:dirpath(fnamemodify(dir, ':h:h'))] = 1 1976 | let allowed[dir] = 1 1977 | for child in s:glob_dir(dir) 1978 | let allowed[child] = 1 1979 | endfor 1980 | endfor 1981 | 1982 | let todo = [] 1983 | let found = sort(s:glob_dir(g:plug_home)) 1984 | while !empty(found) 1985 | let f = remove(found, 0) 1986 | if !has_key(allowed, f) && isdirectory(f) 1987 | call add(todo, f) 1988 | call append(line('$'), '- ' . f) 1989 | if has_key(errs, f) 1990 | call append(line('$'), ' ' . errs[f]) 1991 | endif 1992 | let found = filter(found, 'stridx(v:val, f) != 0') 1993 | end 1994 | endwhile 1995 | 1996 | 4 1997 | redraw 1998 | if empty(todo) 1999 | call append(line('$'), 'Already clean.') 2000 | else 2001 | let s:clean_count = 0 2002 | call append(3, ['Directories to delete:', '']) 2003 | redraw! 2004 | if a:force || s:ask_no_interrupt('Delete all directories?') 2005 | call s:delete([6, line('$')], 1) 2006 | else 2007 | call setline(4, 'Cancelled.') 2008 | nnoremap d :set opfunc=delete_opg@ 2009 | nmap dd d_ 2010 | xnoremap d :call delete_op(visualmode(), 1) 2011 | echo 'Delete the lines (d{motion}) to delete the corresponding directories' 2012 | endif 2013 | endif 2014 | 4 2015 | setlocal nomodifiable 2016 | endfunction 2017 | 2018 | function! s:delete_op(type, ...) 2019 | call s:delete(a:0 ? [line("'<"), line("'>")] : [line("'["), line("']")], 0) 2020 | endfunction 2021 | 2022 | function! s:delete(range, force) 2023 | let [l1, l2] = a:range 2024 | let force = a:force 2025 | while l1 <= l2 2026 | let line = getline(l1) 2027 | if line =~ '^- ' && isdirectory(line[2:]) 2028 | execute l1 2029 | redraw! 2030 | let answer = force ? 1 : s:ask('Delete '.line[2:].'?', 1) 2031 | let force = force || answer > 1 2032 | if answer 2033 | call s:rm_rf(line[2:]) 2034 | setlocal modifiable 2035 | call setline(l1, '~'.line[1:]) 2036 | let s:clean_count += 1 2037 | call setline(4, printf('Removed %d directories.', s:clean_count)) 2038 | setlocal nomodifiable 2039 | endif 2040 | endif 2041 | let l1 += 1 2042 | endwhile 2043 | endfunction 2044 | 2045 | function! s:upgrade() 2046 | echo 'Downloading the latest version of vim-plug' 2047 | redraw 2048 | let tmp = tempname() 2049 | let new = tmp . '/plug.vim' 2050 | 2051 | try 2052 | let out = s:system(printf('git clone --depth 1 %s %s', s:plug_src, tmp)) 2053 | if v:shell_error 2054 | return s:err('Error upgrading vim-plug: '. out) 2055 | endif 2056 | 2057 | if readfile(s:me) ==# readfile(new) 2058 | echo 'vim-plug is already up-to-date' 2059 | return 0 2060 | else 2061 | call rename(s:me, s:me . '.old') 2062 | call rename(new, s:me) 2063 | unlet g:loaded_plug 2064 | echo 'vim-plug has been upgraded' 2065 | return 1 2066 | endif 2067 | finally 2068 | silent! call s:rm_rf(tmp) 2069 | endtry 2070 | endfunction 2071 | 2072 | function! s:upgrade_specs() 2073 | for spec in values(g:plugs) 2074 | let spec.frozen = get(spec, 'frozen', 0) 2075 | endfor 2076 | endfunction 2077 | 2078 | function! s:status() 2079 | call s:prepare() 2080 | call append(0, 'Checking plugins') 2081 | call append(1, '') 2082 | 2083 | let ecnt = 0 2084 | let unloaded = 0 2085 | let [cnt, total] = [0, len(g:plugs)] 2086 | for [name, spec] in items(g:plugs) 2087 | if has_key(spec, 'uri') 2088 | if isdirectory(spec.dir) 2089 | let [err, _] = s:git_validate(spec, 1) 2090 | let [valid, msg] = [empty(err), empty(err) ? 'OK' : err] 2091 | else 2092 | let [valid, msg] = [0, 'Not found. Try PlugInstall.'] 2093 | endif 2094 | else 2095 | if isdirectory(spec.dir) 2096 | let [valid, msg] = [1, 'OK'] 2097 | else 2098 | let [valid, msg] = [0, 'Not found.'] 2099 | endif 2100 | endif 2101 | let cnt += 1 2102 | let ecnt += !valid 2103 | " `s:loaded` entry can be missing if PlugUpgraded 2104 | if valid && get(s:loaded, name, -1) == 0 2105 | let unloaded = 1 2106 | let msg .= ' (not loaded)' 2107 | endif 2108 | call s:progress_bar(2, repeat('=', cnt), total) 2109 | call append(3, s:format_message(valid ? '-' : 'x', name, msg)) 2110 | normal! 2G 2111 | redraw 2112 | endfor 2113 | call setline(1, 'Finished. '.ecnt.' error(s).') 2114 | normal! gg 2115 | setlocal nomodifiable 2116 | if unloaded 2117 | echo "Press 'L' on each line to load plugin, or 'U' to update" 2118 | nnoremap L :call status_load(line('.')) 2119 | xnoremap L :call status_load(line('.')) 2120 | end 2121 | endfunction 2122 | 2123 | function! s:extract_name(str, prefix, suffix) 2124 | return matchstr(a:str, '^'.a:prefix.' \zs[^:]\+\ze:.*'.a:suffix.'$') 2125 | endfunction 2126 | 2127 | function! s:status_load(lnum) 2128 | let line = getline(a:lnum) 2129 | let name = s:extract_name(line, '-', '(not loaded)') 2130 | if !empty(name) 2131 | call plug#load(name) 2132 | setlocal modifiable 2133 | call setline(a:lnum, substitute(line, ' (not loaded)$', '', '')) 2134 | setlocal nomodifiable 2135 | endif 2136 | endfunction 2137 | 2138 | function! s:status_update() range 2139 | let lines = getline(a:firstline, a:lastline) 2140 | let names = filter(map(lines, 's:extract_name(v:val, "[x-]", "")'), '!empty(v:val)') 2141 | if !empty(names) 2142 | echo 2143 | execute 'PlugUpdate' join(names) 2144 | endif 2145 | endfunction 2146 | 2147 | function! s:is_preview_window_open() 2148 | silent! wincmd P 2149 | if &previewwindow 2150 | wincmd p 2151 | return 1 2152 | endif 2153 | endfunction 2154 | 2155 | function! s:find_name(lnum) 2156 | for lnum in reverse(range(1, a:lnum)) 2157 | let line = getline(lnum) 2158 | if empty(line) 2159 | return '' 2160 | endif 2161 | let name = s:extract_name(line, '-', '') 2162 | if !empty(name) 2163 | return name 2164 | endif 2165 | endfor 2166 | return '' 2167 | endfunction 2168 | 2169 | function! s:preview_commit() 2170 | if b:plug_preview < 0 2171 | let b:plug_preview = !s:is_preview_window_open() 2172 | endif 2173 | 2174 | let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7}') 2175 | if empty(sha) 2176 | return 2177 | endif 2178 | 2179 | let name = s:find_name(line('.')) 2180 | if empty(name) || !has_key(g:plugs, name) || !isdirectory(g:plugs[name].dir) 2181 | return 2182 | endif 2183 | 2184 | if exists('g:plug_pwindow') && !s:is_preview_window_open() 2185 | execute g:plug_pwindow 2186 | execute 'e' sha 2187 | else 2188 | execute 'pedit' sha 2189 | wincmd P 2190 | endif 2191 | setlocal previewwindow filetype=git buftype=nofile nobuflisted modifiable 2192 | execute 'silent %!cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha 2193 | setlocal nomodifiable 2194 | nnoremap q :q 2195 | wincmd p 2196 | endfunction 2197 | 2198 | function! s:section(flags) 2199 | call search('\(^[x-] \)\@<=[^:]\+:', a:flags) 2200 | endfunction 2201 | 2202 | function! s:format_git_log(line) 2203 | let indent = ' ' 2204 | let tokens = split(a:line, nr2char(1)) 2205 | if len(tokens) != 5 2206 | return indent.substitute(a:line, '\s*$', '', '') 2207 | endif 2208 | let [graph, sha, refs, subject, date] = tokens 2209 | let tag = matchstr(refs, 'tag: [^,)]\+') 2210 | let tag = empty(tag) ? ' ' : ' ('.tag.') ' 2211 | return printf('%s%s%s%s%s (%s)', indent, graph, sha, tag, subject, date) 2212 | endfunction 2213 | 2214 | function! s:append_ul(lnum, text) 2215 | call append(a:lnum, ['', a:text, repeat('-', len(a:text))]) 2216 | endfunction 2217 | 2218 | function! s:diff() 2219 | call s:prepare() 2220 | call append(0, ['Collecting changes ...', '']) 2221 | let cnts = [0, 0] 2222 | let bar = '' 2223 | let total = filter(copy(g:plugs), 's:is_managed(v:key) && isdirectory(v:val.dir)') 2224 | call s:progress_bar(2, bar, len(total)) 2225 | for origin in [1, 0] 2226 | let plugs = reverse(sort(items(filter(copy(total), (origin ? '' : '!').'(has_key(v:val, "commit") || has_key(v:val, "tag"))')))) 2227 | if empty(plugs) 2228 | continue 2229 | endif 2230 | call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:') 2231 | for [k, v] in plugs 2232 | let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..' 2233 | let diff = s:system_chomp('git log --graph --color=never --pretty=format:"%x01%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir) 2234 | if !empty(diff) 2235 | let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' 2236 | call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) 2237 | let cnts[origin] += 1 2238 | endif 2239 | let bar .= '=' 2240 | call s:progress_bar(2, bar, len(total)) 2241 | normal! 2G 2242 | redraw 2243 | endfor 2244 | if !cnts[origin] 2245 | call append(5, ['', 'N/A']) 2246 | endif 2247 | endfor 2248 | call setline(1, printf('%d plugin(s) updated.', cnts[0]) 2249 | \ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : '')) 2250 | 2251 | if cnts[0] || cnts[1] 2252 | nnoremap :silent! call preview_commit() 2253 | nnoremap o :silent! call preview_commit() 2254 | endif 2255 | if cnts[0] 2256 | nnoremap X :call revert() 2257 | echo "Press 'X' on each block to revert the update" 2258 | endif 2259 | normal! gg 2260 | setlocal nomodifiable 2261 | endfunction 2262 | 2263 | function! s:revert() 2264 | if search('^Pending updates', 'bnW') 2265 | return 2266 | endif 2267 | 2268 | let name = s:find_name(line('.')) 2269 | if empty(name) || !has_key(g:plugs, name) || 2270 | \ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y' 2271 | return 2272 | endif 2273 | 2274 | call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch), g:plugs[name].dir) 2275 | setlocal modifiable 2276 | normal! "_dap 2277 | setlocal nomodifiable 2278 | echo 'Reverted' 2279 | endfunction 2280 | 2281 | function! s:snapshot(force, ...) abort 2282 | call s:prepare() 2283 | setf vim 2284 | call append(0, ['" Generated by vim-plug', 2285 | \ '" '.strftime("%c"), 2286 | \ '" :source this file in vim to restore the snapshot', 2287 | \ '" or execute: vim -S snapshot.vim', 2288 | \ '', '', 'PlugUpdate!']) 2289 | 1 2290 | let anchor = line('$') - 3 2291 | let names = sort(keys(filter(copy(g:plugs), 2292 | \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)'))) 2293 | for name in reverse(names) 2294 | let sha = s:system_chomp('git rev-parse --short HEAD', g:plugs[name].dir) 2295 | if !empty(sha) 2296 | call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha)) 2297 | redraw 2298 | endif 2299 | endfor 2300 | 2301 | if a:0 > 0 2302 | let fn = expand(a:1) 2303 | if filereadable(fn) && !(a:force || s:ask(a:1.' already exists. Overwrite?')) 2304 | return 2305 | endif 2306 | call writefile(getline(1, '$'), fn) 2307 | echo 'Saved as '.a:1 2308 | silent execute 'e' s:esc(fn) 2309 | setf vim 2310 | endif 2311 | endfunction 2312 | 2313 | function! s:split_rtp() 2314 | return split(&rtp, '\\\@ 5 | " source: https://github.com/krampstudio/dotvim 6 | " year : 2015 7 | " 8 | 9 | " nothing yet, you can suggest yours via PR 10 | -------------------------------------------------------------------------------- /config/autocmd.vim: -------------------------------------------------------------------------------- 1 | " 2 | " WebVim Configuration : autocommands 3 | " 4 | " author: Bertrand Chevrier 5 | " source: https://github.com/krampstudio/dotvim 6 | " year : 2015 7 | " 8 | 9 | 10 | " Force filetype 11 | 12 | autocmd BufRead,BufNewFile .eslintrc setfiletype json 13 | autocmd BufRead,BufNewFile .jshintrc setfiletype json 14 | 15 | 16 | " Omni-Completion tip window to close when a selection is 17 | " made, these lines close it on movement in insert mode or when leaving 18 | " insert mode 19 | "autocmd CursorMovedI * if pumvisible() == 0|pclose|endif 20 | autocmd InsertLeave * if pumvisible() == 0|pclose|endif 21 | 22 | 23 | -------------------------------------------------------------------------------- /config/mapping.vim: -------------------------------------------------------------------------------- 1 | " 2 | " WebVim Configuration : global mapping 3 | " 4 | " author: Bertrand Chevrier 5 | " 6 | 7 | " leader 8 | let g:mapleader = "," 9 | let g:localmapleader = "\\" 10 | 11 | " move the current line below 12 | nnoremap - ddp 13 | 14 | " move the current line above 15 | nnoremap _ ddkP 16 | 17 | " switch tab 18 | nnoremap :tabn 19 | nnoremap :tabp 20 | 21 | " insert mode uppercase the current word 22 | " : go to normal mode 23 | " v : visual mode 24 | " iw : select the current word 25 | " U : uppercase selection 26 | " i : back to insert mode 27 | inoremap viwUi 28 | 29 | " remove last search highlight 30 | nnoremap :nohlsearch 31 | 32 | " Wrap a word in double quotes 33 | nnoremap " viwa"hbi"lel 34 | 35 | " Wrap a word in single quotes 36 | nnoremap ' viwa'hbi'lel 37 | 38 | " select inside parents 39 | onoremap in( :normal! f(vi( 40 | 41 | " select inside braces 42 | onoremap in{ :normal! f{vi{ 43 | 44 | " select inside brackets 45 | onoremap in[ :normal! f[vi[ 46 | 47 | " Open MYVIMRC in a vsplit 48 | nnoremap ev :split $MYVIMRC 49 | 50 | " Source MYVIMRC 51 | nnoremap sv :source $MYVIMRC 52 | 53 | 54 | if g:hardcoreMode == 1 55 | 56 | " Leave insert mode (like ) and disable 57 | inoremap jk 58 | inoremap 59 | inoremap ^[ ^[ 60 | 61 | " Disable arrow keys 62 | 63 | nnoremap 64 | nnoremap 65 | nnoremap 66 | nnoremap 67 | 68 | inoremap 69 | inoremap 70 | inoremap 71 | inoremap 72 | endif 73 | 74 | 75 | -------------------------------------------------------------------------------- /config/setting.vim: -------------------------------------------------------------------------------- 1 | " 2 | " WebVim Configuration : global settings 3 | " 4 | " author: Bertrand Chevrier 5 | " source: https://github.com/krampstudio/dotvim 6 | " year : 2015 7 | " 8 | 9 | " wrap end of line 10 | set wrap 11 | 12 | " show line numbers 13 | set number 14 | 15 | " syntax highlighting 16 | syntax on 17 | set background=dark 18 | set t_Co=256 19 | colorscheme PaperColor 20 | 21 | 22 | "indent 23 | set smartindent 24 | set autoindent 25 | set copyindent 26 | set shiftwidth=4 27 | set shiftround 28 | set backspace=indent,eol,start 29 | set smarttab 30 | set expandtab 31 | 32 | "search 33 | set showmatch 34 | set smartcase 35 | 36 | set hlsearch 37 | set incsearch 38 | 39 | 40 | " copy/paste 41 | "set paste 42 | set clipboard=unnamedplus 43 | 44 | " folding manual 45 | set foldmethod=manual 46 | 47 | " mouse 48 | set mouse=a 49 | 50 | " spell check, to be activated manually 51 | set spelllang=en_us 52 | set nospell 53 | -------------------------------------------------------------------------------- /fonts/10-powerline-symbols.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | monospace 7 | PowerlineSymbols 8 | 9 | 10 | Droid Sans Mono 11 | PowerlineSymbols 12 | 13 | 14 | Droid Sans Mono Slashed 15 | PowerlineSymbols 16 | 17 | 18 | Droid Sans Mono Dotted 19 | PowerlineSymbols 20 | 21 | 22 | DejaVu Sans Mono 23 | PowerlineSymbols 24 | 25 | 26 | DejaVu Sans Mono 27 | PowerlineSymbols 28 | 29 | 30 | Envy Code R 31 | PowerlineSymbols 32 | 33 | 34 | Inconsolata 35 | PowerlineSymbols 36 | 37 | 38 | Lucida Console 39 | PowerlineSymbols 40 | 41 | 42 | Monaco 43 | PowerlineSymbols 44 | 45 | 46 | Pragmata 47 | PowerlineSymbols 48 | 49 | 50 | PragmataPro 51 | PowerlineSymbols 52 | 53 | 54 | Menlo 55 | PowerlineSymbols 56 | 57 | 58 | Source Code Pro 59 | PowerlineSymbols 60 | 61 | 62 | Consolas 63 | PowerlineSymbols 64 | 65 | 66 | Anonymous pro 67 | PowerlineSymbols 68 | 69 | 70 | Bitstream Vera Sans Mono 71 | PowerlineSymbols 72 | 73 | 74 | Liberation Mono 75 | PowerlineSymbols 76 | 77 | 78 | Ubuntu Mono 79 | PowerlineSymbols 80 | 81 | 82 | Meslo LG L 83 | PowerlineSymbols 84 | 85 | 86 | Meslo LG L DZ 87 | PowerlineSymbols 88 | 89 | 90 | Meslo LG M 91 | PowerlineSymbols 92 | 93 | 94 | Meslo LG M DZ 95 | PowerlineSymbols 96 | 97 | 98 | Meslo LG S 99 | PowerlineSymbols 100 | 101 | 102 | Meslo LG S DZ 103 | PowerlineSymbols 104 | 105 | 106 | -------------------------------------------------------------------------------- /fonts/PowerlineSymbols.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vim-dist/webvim/10719962d722c5cea41bea46a268c20db939b931/fonts/PowerlineSymbols.otf -------------------------------------------------------------------------------- /fonts/install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | current=$(dirname "$0") 4 | fontDir="$HOME/.fonts" 5 | fontFile="$current/PowerlineSymbols.otf" 6 | fontConfDir="$HOME/.fonts.conf.d" 7 | fontConfFile="$current/10-powerline-symbols.conf" 8 | 9 | echo "Installing Powerline Font for Airline plugin into user space $HOME" 10 | 11 | #Check fc-cache is installed 12 | command -v fc-cache >/dev/null 2>&1 || { echo >&2 "This script requires fc-cache to install the font, but it's not installed. Quiting"; exit 1; } 13 | 14 | [ -d "$fontDir" ] || mkdir "$fontDir" 15 | cp "$fontFile" "$fontDir" 16 | 17 | 18 | [ -d "$fontiConfDir" ] || mkdir "$fontConfDir" 19 | cp "$fontConfFile" "$fontConfDir" 20 | 21 | fc-cache -vf "$fontDir" 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /plugins/config.vim: -------------------------------------------------------------------------------- 1 | " 2 | " WebVim Configuration : Plugins configuration 3 | " 4 | " author: Bertrand Chevrier 5 | " source: https://github.com/krampstudio/dotvim 6 | " year : 2015-2019 7 | " 8 | 9 | " TODO split by plugin ? 10 | 11 | 12 | " [> NERDTree <] 13 | 14 | " on vim enter opens nerd tree 15 | function! OpenNerdTree() 16 | let s:exclude = ['COMMIT_EDITMSG', 'MERGE_MSG'] 17 | if index(s:exclude, expand('%:t')) < 0 18 | NERDTreeFind 19 | exec "normal! \\" 20 | endif 21 | endfunction 22 | autocmd VimEnter * call OpenNerdTree() 23 | 24 | 25 | " nerdtree window resize 26 | let g:NERDTreeWinSize = 35 27 | 28 | " show hidden files 29 | let g:NERDTreeShowHidden=1 30 | 31 | " single click to open nodes 32 | " let g:NERDTreeMouseMode=3 33 | 34 | " ignored files 35 | let g:NERDTreeIgnore=['\.swp$', '\~$'] 36 | nnoremap :NERDTreeToggle 37 | 38 | " helps quiting when there's no buffers left but NerdTree 39 | function! CheckLeftBuffers() 40 | if tabpagenr('$') == 1 41 | let i = 1 42 | while i <= winnr('$') 43 | if getbufvar(winbufnr(i), '&buftype') == 'help' || 44 | \ getbufvar(winbufnr(i), '&buftype') == 'quickfix' || 45 | \ exists('t:NERDTreeBufName') && 46 | \ bufname(winbufnr(i)) == t:NERDTreeBufName || 47 | \ bufname(winbufnr(i)) == '__Tag_List__' 48 | let i += 1 49 | else 50 | break 51 | endif 52 | endwhile 53 | if i == winnr('$') + 1 54 | qall 55 | endif 56 | unlet i 57 | endif 58 | endfunction 59 | autocmd BufEnter * call CheckLeftBuffers() 60 | 61 | " git indicator in tree 62 | let g:NERDTreeIndicatorMapCustom = { 63 | \ "Modified" : "✹", 64 | \ "Staged" : "✚", 65 | \ "Untracked" : "✭", 66 | \ "Renamed" : "➜", 67 | \ "Unmerged" : "═", 68 | \ "Deleted" : "✖", 69 | \ "Dirty" : "✗", 70 | \ "Clean" : "✔︎", 71 | \ 'Ignored' : '☒', 72 | \ "Unknown" : "?" 73 | \ } 74 | 75 | " [> NERDCommenter <] 76 | 77 | noremap :call NERDComment(0, "Toggle") 78 | 79 | 80 | " [> Airline <] 81 | 82 | " status line always opened 83 | set laststatus=2 84 | 85 | let g:airline#extensions#tabline#enabled = 1 86 | 87 | " powerline font 88 | let g:airline_powerline_fonts=1 89 | 90 | let g:airline_theme='papercolor' 91 | 92 | " [> EditorConfig <] 93 | 94 | " to avoid issues with fugitive 95 | let g:EditorConfig_exclude_patterns = ['fugitive://.*'] 96 | 97 | 98 | " [> Syntastic <] 99 | 100 | "" Syntax checkers 101 | 102 | let g:syntastic_check_on_open=1 103 | let g:syntastic_enable_signs=1 104 | let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd'] 105 | let g:syntastic_html_checkers=['tidy'] 106 | let g:syntastic_vim_checkers=['vimlint'] 107 | let g:syntastic_json_checkers=['jsonlint'] 108 | let g:syntastic_yaml_checkers=['js-yaml'] 109 | let g:syntastic_sass_checkers=["sasslint"] 110 | let g:syntastic_scss_checkers=["sasslint"] 111 | let g:syntastic_css_checkers=['csslint'] 112 | let g:syntastic_handlebars_checkers=['handlebars'] 113 | let g:syntastic_tpl_checkers=['handlebars'] 114 | 115 | " get available js linters 116 | " it returns the mapping between a linter and the config files 117 | function! GetJslinters() 118 | return { 119 | \ 'eslint' : [ '.eslintrc', '.eslintrc.json', '.eslintrc.js', '.eslint.yml' ], 120 | \ 'jshint' : [ '.jshintrc'] 121 | \ } 122 | endfunction 123 | 124 | " check if the path to see if a linter config is present 125 | function! Jslinter(path, linters) 126 | let l:dir = fnamemodify(a:path, ':p:h') 127 | 128 | if(l:dir == '/') 129 | return [''] 130 | endif 131 | 132 | for l:linter in keys(a:linters) 133 | for l:linterConfig in a:linters[l:linter] 134 | if filereadable(l:dir . '/' . l:linterConfig) 135 | let l:localLinter = l:dir . '/node_modules/.bin/' . l:linter 136 | if executable(l:localLinter) 137 | return [l:linter, l:localLinter] 138 | endif 139 | return [l:linter, l:linter] 140 | endif 141 | endfor 142 | endfor 143 | 144 | return Jslinter(fnamemodify(l:dir, ':h'), a:linters) 145 | endfunction 146 | 147 | " set the jslinter into Syntastic 148 | function! SyntasticSetJsLinter() 149 | 150 | let l:availableLinters = GetJslinters() 151 | 152 | " look for linter config in the current folder 153 | let l:jslinter = Jslinter(expand('%:p'), l:availableLinters) 154 | if l:jslinter[0] == '' 155 | " otherwise look into the home dir 156 | let l:jslinter = Jslinter($HOME, l:availableLinters) 157 | endif 158 | 159 | " configure the linter 160 | if l:jslinter[0] != '' 161 | let g:syntastic_javascript_checkers=[l:jslinter[0]] 162 | if l:jslinter[0] != l:jslinter[1] 163 | exec 'let g:syntastic_javascript_' . l:jslinter[0] . '_exec = "' . l:jslinter[1] . '"' 164 | endif 165 | let g:syntastic_javascript_checkers=[l:jslinter[0]] 166 | endif 167 | endfunction 168 | 169 | call SyntasticSetJsLinter() 170 | 171 | " [> EasyAlign <] 172 | 173 | " select paragraph and start easyalign on the left 174 | nnoremap a vip(EasyAlign) 175 | 176 | " Start interactive align to the right 177 | vmap a (EasyAlign) 178 | 179 | let g:easy_align_ignore_groups = ['Comment'] 180 | 181 | let s:easy_align_delimiters_default = { 182 | \ ' ': { 'pattern': ' ', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 }, 183 | \ '=': { 'pattern': '===\|<=>\|\(&&\|||\|<<\|>>\)=\|=\~[#?]\?\|=>\|[:+/*!%^=><&|.-]\?=[#?]\?', 184 | \ 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 }, 185 | \ ':': { 'pattern': ':', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 }, 186 | \ ',': { 'pattern': ',', 'left_margin': 0, 'right_margin': 1, 'stick_to_left': 1 }, 187 | \ '|': { 'pattern': '|', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 }, 188 | \ '.': { 'pattern': '\.', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 }, 189 | \ '#': { 'pattern': '#\+', 'delimiter_align': 'l', 'ignore_groups': ['!Comment'] }, 190 | \ '&': { 'pattern': '\\\@ multiple cursor <] 199 | 200 | let g:multi_cursor_use_default_mapping=0 201 | let g:multi_cursor_next_key='' 202 | let g:multi_cursor_prev_key='' 203 | let g:multi_cursor_skip_key='' 204 | let g:multi_cursor_quit_key='' 205 | 206 | 207 | " [> JsBeautify <] 208 | 209 | " format selection 210 | autocmd FileType javascript vnoremap :call RangeJsBeautify() 211 | autocmd FileType json vnoremap :call RangeJsonBeautify() 212 | autocmd FileType html vnoremap :call RangeHtmlBeautify() 213 | autocmd FileType css vnoremap :call RangeCSSBeautify() 214 | 215 | " format the whole file 216 | autocmd FileType javascript nnoremap :call JsBeautify() 217 | autocmd FileType json nnoremap :call JsonBeautify() 218 | autocmd FileType html nnoremap :call HtmlBeautify() 219 | autocmd FileType css nnoremap :call CSSBeautify() 220 | 221 | " [> YankStack <] 222 | 223 | nmap p yankstack_substitute_older_paste 224 | nmap P yankstack_substitute_newer_paste 225 | 226 | 227 | " [> Javascript libraries syntax <] 228 | 229 | let g:used_javascript_libs = 'jquery,underscore,requirejs,chai,handlebars,d3,tape,react,vue,ramda' 230 | 231 | " [> JSON <] 232 | 233 | let g:vim_json_syntax_conceal = 0 234 | 235 | 236 | " [> YCM shortcuts <] 237 | " 238 | function! Refactor() 239 | call inputsave() 240 | let g:newName = input("Enter the new variable name : ") 241 | call inputrestore() 242 | exec ":YcmCompleter RefactorRename " . g:newName 243 | endfunction 244 | 245 | nnoremap gt :YcmCompleter GetType 246 | nnoremap gd :YcmCompleter GetDoc 247 | nnoremap go :YcmCompleter GoTo 248 | nnoremap gf :YcmCompleter GoToDefinition 249 | nnoremap gr :YcmCompleter GoToReferences 250 | nnoremap r :call Refactor() 251 | 252 | " [> Emmet shortcuts <] 253 | " 254 | let g:user_emmet_install_global = 0 255 | autocmd FileType html,tpl,hbs,css,scss EmmetInstall 256 | let g:user_emmet_leader_key='' 257 | 258 | 259 | -------------------------------------------------------------------------------- /plugins/def.vim: -------------------------------------------------------------------------------- 1 | 2 | function! InstallYCM(info) 3 | if a:info.status == 'installed' || a:info.force 4 | !./install.py 5 | !cd ./third_party/ycmd/third_party/tern_runtime && npm install 6 | endif 7 | endfunction 8 | 9 | " Start plugins definition 10 | call plug#begin($HOME.'/.vim/plugins/plugged') 11 | 12 | Plug 'scrooloose/nerdtree', { 'commit' : '84737f2ebe533ffac9ebc21da8d1f57216962641' } | Plug 'https://gist.github.com/1f40e70e615f2fa2212bf5423662277d.git', { 'dir' : g:vimDir . '/nerdtree_plugin' } | Plug 'Xuyuanp/nerdtree-git-plugin', { 'commit' : '325a1298b0c9d8a4c61388a2f9956a534a9068cd' } | Plug 'MarSoft/nerdtree-grep-plugin', { 'commit' : '09e446ebe4770687a6283905d5ff461ea268bc14' } 13 | 14 | Plug 'scrooloose/nerdcommenter', { 'commit' : '9a32fd2534427f7a1dcfe22e9c0ea6b67b6dbe78' } 15 | Plug 'NLKNguyen/papercolor-theme', { 'commit' : 'c4a4dfdc21c14f58c12d077242ae33b729c894b2' } 16 | Plug 'bling/vim-airline', { 'commit' : '1c3ae6077af76927f82f87e05a7b9fdfba47ce2c', 'do' : $HOME.'/.vim/fonts/install' } 17 | Plug 'vim-airline/vim-airline-themes', { 'commit' : '3bfe1d00d48f7c35b7c0dd7af86229c9e63e14a9' } 18 | Plug 'tpope/vim-fugitive', { 'commit' : '2564c37d0a2ade327d6381fef42d84d9fad1d057' } 19 | Plug 'tpope/vim-rhubarb', { 'commit' : '57a350e6327af0074c4bc0d30b62662dfdb993af' } 20 | Plug 'airblade/vim-gitgutter', { 'commit' : '7eeea63e62b1cc088a75c7a7c244fc774d82e5bb' } 21 | Plug 'editorconfig/editorconfig-vim', { 'commit' : '68f8136d2b018bfa9b23403e87d3d65bc942cbc3' } 22 | Plug 'bronson/vim-trailing-whitespace', { 'commit' : '733fb64337b6da4a51c85a43450cd620d8b617b5' } 23 | Plug 'scrooloose/syntastic', { 'commit' : '6ffba7395c562e152cb84bc8f7906de2b1ed0b8a' } 24 | Plug 'gcorne/vim-sass-lint', { 'commit' : 'b9ff33141294c7af143f12687e9b1cf9a3a54e0f' } 25 | Plug 'junegunn/vim-easy-align', { 'commit' : '0cb6b98fc155717b0a56c110551ac57d1d951ddb' } 26 | Plug 'terryma/vim-multiple-cursors', { 'commit' : '51d0717f63cc231f11b4b63ee5b611f589dce1b3' } 27 | Plug 'maksimr/vim-jsbeautify', { 'commit' : 'caffda66a2a8852ee132f95291115af67370c5e7', 'do' : 'git submodule update --init --recursive && npm install' } 28 | Plug 'maxbrunsfeld/vim-yankstack', { 'commit' : '157a659c1b101c899935d961774fb5c8f0775370' } 29 | Plug 'tpope/vim-surround', { 'commit' : 'e49d6c2459e0f5569ff2d533b4df995dd7f98313'} 30 | Plug 'elzr/vim-json', { 'commit' : '3727f089410e23ae113be6222e8a08dd2613ecf2'} 31 | Plug 'othree/yajs.vim', { 'commit' : '437be4ccf0e78fe54cb482657091cff9e8479488'} 32 | Plug 'othree/es.next.syntax.vim', { 'commit' : 'ad2d6a27073e43e41b8041b3655f2444a251c444'} 33 | Plug 'othree/javascript-libraries-syntax.vim', { 'commit' : '5ef435d8c28ebc3c9b52fb865f4c06db629857f7'} 34 | Plug 'hail2u/vim-css3-syntax', { 'commit' : '3e40dde46c6a3bc4f0339248b000bbe96e39dc2d'} 35 | Plug 'cakebaker/scss-syntax.vim', { 'commit' : '4461789d02f81fd328afbdf27d6404b6c763c25f'} 36 | Plug 'othree/html5.vim', { 'commit' : 'bc7faabe7a4dfc0d963d6d8a406c3b7284e2866f'} 37 | Plug 'Valloric/YouCompleteMe', { 'commit' : 'ddf18cc6ec3bb0108bb89ac366fd74394815f2c6', 'do': function('InstallYCM') } 38 | Plug 'moll/vim-node', { 'commit' : 'ede047791792b9530ba1ae73ed86e9671cdd96b8'} 39 | Plug 'syngan/vim-vimlint', { 'commit' : 'c8b9cd9d8a0fb6dc69667d32819aeef503cff55c'} 40 | Plug 'ynkdir/vim-vimlparser', { 'commit' : '2fff43c58968a18bc01bc8304df68bde01af04d9'} 41 | Plug 'mattn/emmet-vim', { 'commit' : 'd698f1658770ca5fa58c87e80421c8d65bbe9065'} 42 | Plug 'martinda/Jenkinsfile-vim-syntax' 43 | 44 | call plug#end() 45 | -------------------------------------------------------------------------------- /resources/WebVim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vim-dist/webvim/10719962d722c5cea41bea46a268c20db939b931/resources/WebVim.png -------------------------------------------------------------------------------- /resources/WebVim.svg: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------