├── .gitignore ├── .vim └── coc-settings.json ├── LICENSE ├── README.md ├── cmd └── jarvim │ └── main.go ├── go.mod ├── go.sum ├── install.sh ├── internal ├── cli │ └── cli.go ├── logic │ ├── interactive.go │ └── logic.go ├── plugin │ ├── appearance.go │ ├── autoload.go │ ├── core.go │ ├── database.go │ ├── enhance.go │ ├── event.go │ ├── explorer.go │ ├── filetype.go │ ├── fuzzyfind.go │ ├── general.go │ ├── initvim.go │ ├── installscript.go │ ├── keymap.go │ ├── languages.go │ ├── lsp.go │ ├── pluginmanage.go │ ├── program.go │ ├── textobj.go │ ├── theme.go │ └── versioncontrol.go ├── render │ ├── dein │ │ └── dein.go │ ├── render.go │ └── vimplug │ │ └── vimplug.go └── vim │ └── vim.go ├── pkg ├── cli │ └── cli.go ├── color │ └── color.go └── util │ └── util.go └── template ├── bufkill.go ├── difftools.go ├── hlsearch.go ├── nicefold.go └── whitespace.go /.gitignore: -------------------------------------------------------------------------------- 1 | */jarvis 2 | -------------------------------------------------------------------------------- /.vim/coc-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "defx", 4 | "rhysd" 5 | ] 6 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Raphael 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Generate a module vim configruation like VIM PRO!

4 |
5 | 6 | > I have been maintaining [Thinkvim](https://github.com/hardcoreplayers/ThinkVim) for a long time, and slowly it deviated from my original intention. At first I wanted 7 | > to use it as a vim configuration template for Vimer to use, but slowly it has to accept everyone’s preferences, I have 8 | > to get Add more language support and other plug-in configurations, thinkvim becomes more and more bloated. This is wrong. 9 | > I think that vim should be lightweight, so I wrote this cli tool jarvim, which will generate a greateful configuration 10 | > for you, there are some useful hacks in the generated configuration, I hope it can help you, if you are new to vim, you 11 | > no longer need to refer to other people's configurations, you can use the generated configuration as your starting point 12 | > This will greatly save your time. 13 | 14 | ## Install 15 | 16 | You can download build binary file from release page https://github.com/glepnir/jarvim/releases 17 | 18 | **MacOs brew** 19 | 20 | ```console 21 | brew tap glepnir/jarvim 22 | brew install jarvim 23 | ``` 24 | 25 | **Linux** 26 | 27 | ```console 28 | curl -fLo install.sh https://raw.githubusercontent.com/glepnir/jarvim/master/install.sh 29 | sh install.sh 30 | ./jarvim -g 31 | ``` 32 | 33 | **Install From Source** 34 | 35 | ```go 36 | go get github.com/glepnir/jarvim 37 | ``` 38 | 39 | ## Usage 40 | 41 | **Here is a [gif](https://github.com/glepnir/jarvim/wiki) to show how to use jarvim.** 42 | 43 | ``` 44 | -v to print jarvim version. 45 | -g to generate vim configuration. 46 | ``` 47 | 48 | ## FAQ 49 | 50 | - Why the symbols look weird in my vim ? 51 | 52 | Make sure you have installed nerdfont font from https://www.nerdfonts.com/, Different fonts may be inconsistent in the performance of symbols. 53 | The solution, If you use Mac with iterm2, you can set a different font for the symbol. 54 | 55 |
56 | 57 |
58 | 59 | Another way I recommend you to use [kitty terminal](https://github.com/kovidgoyal/kitty), it has built-in symbol font support.Kitty support 60 | Mac and Linux. 61 | 62 | Normal graphics should be like this 63 | 64 |
65 | 66 |
67 | 68 | ## Donate 69 | 70 | Do you like jarvim? buy me a coffe 😘! 71 | 72 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/bobbyhub) 73 | 74 | | Wechat | AliPay | 75 | | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | 76 | | ![wechat](https://user-images.githubusercontent.com/41671631/84404718-c8312a00-ac39-11ea-90d7-ee679fbb3705.png) | ![ali](https://user-images.githubusercontent.com/41671631/84403276-1a714b80-ac38-11ea-8607-8492df84e516.png) | 77 | 78 | ## LICENSE 79 | 80 | - MIT 81 | -------------------------------------------------------------------------------- /cmd/jarvim/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The jarvim Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "github.com/glepnir/jarvim/internal/cli" 8 | 9 | func main() { 10 | cli.Execute() 11 | } 12 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/glepnir/jarvim 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/AlecAivazis/survey/v2 v2.0.8 7 | github.com/spf13/cobra v1.0.0 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/AlecAivazis/survey v1.8.8 h1:Y4yypp763E8cbqb5RBqZhGgkCFLRFnbRBHrxnpMMsgQ= 3 | github.com/AlecAivazis/survey/v2 v2.0.8 h1:zVjWKN+JIAfmrq6nGWG3DfLS8ypEBhxYy0p7FM+riFk= 4 | github.com/AlecAivazis/survey/v2 v2.0.8/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk= 5 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 6 | github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= 7 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 8 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 9 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 10 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 11 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 12 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 13 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 14 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 15 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 16 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 17 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 18 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 19 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 20 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 21 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 22 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 23 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 24 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 25 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 26 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 27 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 28 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 29 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 30 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 31 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 32 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 33 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 34 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 35 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 36 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 37 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 38 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 39 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 40 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 41 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 42 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 43 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 44 | github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= 45 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 46 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 47 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 48 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= 49 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= 50 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 51 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 52 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 53 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 54 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 55 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 56 | github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 57 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 58 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 59 | github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= 60 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 61 | github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= 62 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 63 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 64 | github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= 65 | github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= 66 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 67 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 68 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 69 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 70 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 71 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 72 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 73 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 74 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 75 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 76 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 77 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 78 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 79 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 80 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 81 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 82 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 83 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 84 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 85 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 86 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 87 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 88 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 89 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 90 | github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= 91 | github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= 92 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 93 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= 94 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 95 | github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= 96 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 97 | github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 98 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 99 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 100 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 101 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 102 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 103 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 104 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 105 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 106 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 107 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 108 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 109 | golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 h1:8dUaAV7K4uHsF56JQWkprecIQKdPHtR9jCHF5nB8uzc= 110 | golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 111 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 112 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 113 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 114 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 115 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 116 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 117 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 118 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 119 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 120 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 121 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 122 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 123 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 124 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 125 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 126 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 127 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 128 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 129 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 130 | golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1 h1:R4dVlxdmKenVdMRS/tTspEpSTRWINYrHD8ySIU9yCIU= 131 | golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 132 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 133 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 134 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 135 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 136 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 137 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 138 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 139 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 140 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 141 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 142 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 143 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 144 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 145 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 146 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 147 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 148 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 149 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 150 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -u 4 | 5 | APP=jarvim 6 | 7 | DOWNLOAD_URL="https://github.com/glepnir/jarvim/releases/latest/download/" 8 | 9 | exists() { 10 | command -v "$1" >/dev/null 2>&1 11 | } 12 | 13 | download() { 14 | local from=$1 15 | local to=$2 16 | if exists "curl"; then 17 | curl -fLo "$to" "$from" 18 | elif exists 'wget'; then 19 | wget --output-document="$to" "$from" 20 | else 21 | echo 'curl or wget is required' 22 | exit 1 23 | fi 24 | } 25 | 26 | try_download() { 27 | local asset=$1 28 | if [ -z "${TMPDIR+x}" ]; then 29 | rm -f $APP 30 | download "$DOWNLOAD_URL/$asset" $APP 31 | else 32 | local temp=${TMPDIR}/jarvim 33 | download "$DOWNLOAD_URL/$asset" "$temp" 34 | mv "$temp" $APP 35 | fi 36 | chmod a+x "$APP" 37 | } 38 | 39 | main() { 40 | osname=$(uname -sm) 41 | case "${osname}" in 42 | "Linux x86_64") 43 | try_download "$APP"-x86_64-linux ;; 44 | "Darwin x86_64") 45 | try_download "$APP"-x86_64-darwin ;; 46 | *) 47 | echo "No prebuilt jarvim binary available for ${osname}." 48 | exit 1 49 | ;; 50 | esac 51 | } 52 | 53 | main 54 | -------------------------------------------------------------------------------- /internal/cli/cli.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The jarvim Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cli 6 | 7 | import ( 8 | "fmt" 9 | "log" 10 | "os" 11 | 12 | "github.com/glepnir/jarvim/internal/logic" 13 | "github.com/spf13/cobra" 14 | ) 15 | 16 | var ( 17 | cli_version = "0.2.3" 18 | version bool 19 | genConfig bool 20 | ) 21 | 22 | var rootCmd = &cobra.Command{ 23 | Use: "jarvim", 24 | Short: "jarvim is a cli tool to generate a module vim configruation which like a pro", 25 | Long: "jarvim is a cli tool to generate a module vim configruation which like a pro", 26 | RunE: func(cmd *cobra.Command, args []string) error { 27 | if version { 28 | return printVersion() 29 | } 30 | if genConfig { 31 | return logic.RunLogic() 32 | } 33 | return cmd.Help() 34 | }, 35 | } 36 | 37 | func init() { 38 | cobra.OnInitialize() 39 | rootCmd.Flags().BoolVarP(&version, "Version", "v", false, "show current version of CLI") 40 | rootCmd.Flags().BoolVarP(&genConfig, "Generate vim config", "g", false, "generate new configuration") 41 | } 42 | 43 | // Execute do the rootmcmd.Execute() function 44 | func Execute() { 45 | if err := rootCmd.Execute(); err != nil { 46 | log.Fatal(err) 47 | os.Exit(1) 48 | } 49 | } 50 | 51 | func printVersion() error { 52 | fmt.Println("Version: ", cli_version) 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /internal/logic/interactive.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The jarvim Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package logic 6 | 7 | import ( 8 | "github.com/glepnir/jarvim/internal/plugin" 9 | "github.com/glepnir/jarvim/internal/render" 10 | "github.com/glepnir/jarvim/internal/render/dein" 11 | "github.com/glepnir/jarvim/internal/render/vimplug" 12 | "github.com/glepnir/jarvim/internal/vim" 13 | "github.com/glepnir/jarvim/pkg/cli" 14 | ) 15 | 16 | // PluginManage return the plugin management plugin 17 | // that user select 18 | func PluginManage() render.Render { 19 | message := "What is plugin manage do you use?" 20 | options := []string{"dein", "vim-plug"} 21 | pm := cli.SingleSelectTemplate(message, options) 22 | if pm == "dein" { 23 | return new(dein.Dein) 24 | } else { 25 | return new(vimplug.VimPlug) 26 | } 27 | } 28 | 29 | // NewDatFileMap according the render type return 30 | // datafilemap 31 | func NewDataFileMap(r render.Render) map[string]string { 32 | _, ok := r.(*dein.Dein) 33 | if ok { 34 | return map[string]string{ 35 | "MarkDown": plugin.DeinMarkDown, 36 | "Toml": plugin.DeinToml, 37 | "Nginx": plugin.DeinNginx, 38 | "Json": plugin.DeinJson, 39 | "Dockerfile": plugin.DeinDockerFile, 40 | } 41 | } 42 | return map[string]string{ 43 | "MarkDown": plugin.PlugMarkDown, 44 | "Toml": plugin.PlugToml, 45 | "Nginx": plugin.PlugNginx, 46 | "Json": plugin.PlugJson, 47 | "Dockerfile": plugin.PlugDockerFile, 48 | } 49 | 50 | } 51 | 52 | // NewENewEnhancePluginMap return the enhance plugin map 53 | // according plugin management type 54 | func NewEnhancePluginMap(r render.Render) map[string]string { 55 | _, ok := r.(*dein.Dein) 56 | if ok { 57 | return map[string]string{ 58 | "accelerated-jk accelerate up-down moving (j and k mapping)": plugin.DeinFastJK, 59 | "vim-mundo vim undo tree": plugin.DeinMundo, 60 | "vim-easymotion fast jump": plugin.DeinEasyMotion, 61 | "rainbow rainbow parentheses": plugin.DeinRainbow, 62 | "vim-floterm vim terminal float": plugin.DeinFloaterm, 63 | } 64 | } 65 | return map[string]string{ 66 | "accelerated-jk accelerate up-down moving (j and k mapping)": plugin.PlugFastJK, 67 | "vim-mundo vim undo tree": plugin.PlugMundo, 68 | "vim-easymotion fast jump": plugin.PlugEasyMotion, 69 | "rainbow rainbow parentheses": plugin.PlugRainbow, 70 | "vim-floterm vim terminal float": plugin.PlugFloaterm, 71 | } 72 | } 73 | 74 | // NewVersionPluginMap return the version control map 75 | func NewVersionPluginMap(r render.Render) map[string]string { 76 | _, ok := r.(*dein.Dein) 77 | if ok { 78 | return map[string]string{ 79 | "jreybert/vimagit": plugin.DeinVimagt, 80 | "tpope/vim-fugitive": plugin.DeinFugiTive, 81 | "lambdalisue/gina.vim": plugin.DeinGina, 82 | } 83 | } 84 | return map[string]string{ 85 | "jreybert/vimagit": plugin.PlugVimagit, 86 | "tpope/vim-fugitive": plugin.PlugFugTive, 87 | "lambdalisue/gina.vim": plugin.PlugGina, 88 | } 89 | 90 | } 91 | 92 | // NewLanguagePlugMap return the lanuages config map 93 | func NewLanguagePlugMap(r render.Render) map[string]string { 94 | _, ok := r.(*dein.Dein) 95 | if ok { 96 | return map[string]string{ 97 | "C-family": plugin.DeinCFamily, 98 | "R": plugin.DeinR, 99 | "Javascript": plugin.DeinJavascript, 100 | "Typescript": plugin.DeinTypescript, 101 | "Dart": plugin.DeinDart, 102 | "React": plugin.DeinReact, 103 | "Vue": plugin.DeinVue, 104 | "Go": plugin.DeinGo, 105 | "Rust": plugin.DeinRust, 106 | "Haskell": plugin.DeinHaskell, 107 | "Php": plugin.DeinPhp, 108 | "Ruby": plugin.DeinRuby, 109 | "Scala": plugin.DeinScala, 110 | "Shell": plugin.DeinShell, 111 | "Lua": plugin.DeinLua, 112 | "Python": plugin.DeinPython, 113 | "Html": plugin.DeinHtml, 114 | "Css": plugin.DeinCss, 115 | "Less": plugin.DeinLess, 116 | "Sass scss": plugin.DeinSass, 117 | "Stylus": plugin.DeinStylus, 118 | } 119 | } 120 | return map[string]string{ 121 | "C-family": plugin.PlugCFamily, 122 | "R": plugin.PlugR, 123 | "Javascript": plugin.PlugJavascript, 124 | "Typescript": plugin.PlugTypescript, 125 | "Dart": plugin.PlugDart, 126 | "React": plugin.PlugReact, 127 | "Vue": plugin.PlugVue, 128 | "Go": plugin.PlugGo, 129 | "Rust": plugin.PlugRust, 130 | "Haskell": plugin.PlugHaskell, 131 | "Php": plugin.PlugPhp, 132 | "Ruby": plugin.PlugRuby, 133 | "Scala": plugin.PlugScala, 134 | "Shell": plugin.PlugShell, 135 | "Lua": plugin.PlugLua, 136 | "Python": plugin.PlugPython, 137 | "Html": plugin.PlugHtml, 138 | "Css": plugin.PlugCss, 139 | "Less": plugin.PlugLess, 140 | "Sass scss": plugin.PlugSass, 141 | "Stylus": plugin.PlugStylus, 142 | } 143 | 144 | } 145 | 146 | // Leaderkey get the user LeaderKey 147 | func LeaderKey() string { 148 | message := "What is your Leader Key?" 149 | options := []string{"Space", "Comma(,)", "Semicolon(;)"} 150 | return cli.SingleSelectTemplate(message, options) 151 | } 152 | 153 | // LocalLeaderKey get the user LocalLeaderKey 154 | func LocalLeaderKey() string { 155 | message := "What is your LocalLeader Key?" 156 | options := []string{"Space", "Comma(,)", "Semicolon(;)"} 157 | return cli.SingleSelectTemplate(message, options) 158 | } 159 | 160 | // Colorscheme get the user colorshemes 161 | func Colorscheme() []string { 162 | questionname := "Colorscheme Question" 163 | message := "Choose your favorite colorscheme" 164 | pagesize := 19 165 | options := make([]string, 0) 166 | for k, _ := range vim.ColorschemeMap { 167 | options = append(options, k) 168 | } 169 | return cli.MultiSelectTemplate(questionname, message, options, pagesize) 170 | } 171 | 172 | // DashboardPlugin return bool according user choose 173 | func DashboardPlugin() bool { 174 | message := "Do you want use dashboard-nvim a better StartScreenPlugin?" 175 | return cli.ConfirmTemplate(message) 176 | } 177 | 178 | // BufferLinePlugin return bool according user choose 179 | func BufferLinePlugin() bool { 180 | message := "Do you want use vim-buffet as your bufferline?" 181 | return cli.ConfirmTemplate(message) 182 | } 183 | 184 | // SpacelinePlugin return bool according user choose 185 | func SpacelinePlugin() bool { 186 | message := "Do you want use spaceline.vim a light and beautiful statusline?" 187 | return cli.ConfirmTemplate(message) 188 | } 189 | 190 | // ExplorerPlugin return the explorer plugin 191 | func ExplorerPlugin() string { 192 | message := "What is your explorer plugin?" 193 | options := []string{"defx.nvim", "nerdtree", "coc-explorer"} 194 | return cli.SingleSelectTemplate(message, options) 195 | } 196 | 197 | // DatabasePlugin return bool according user choose 198 | func DatabasePlugin() bool { 199 | message := "Do you need database plugins?" 200 | return cli.ConfirmTemplate(message) 201 | } 202 | 203 | // FuzzyFindPlugin return bool according user choose 204 | func FuzzyFindPlugin() bool { 205 | message := "Do you want use fuzzy find plugin vim-clap?" 206 | return cli.ConfirmTemplate(message) 207 | } 208 | 209 | // EditorConfigPlugin return bool according user choose 210 | func EditorConfigPlugin() bool { 211 | message := "Do you want use editorconfig to control program style(like indent,whitespace etc)" 212 | return cli.ConfirmTemplate(message) 213 | } 214 | 215 | // IndentLinePlugin return string according user choose 216 | func IndentLinePlugin() string { 217 | message := "Choose your favorite indentline plugin?" 218 | options := []string{"Yggdroot/indentLine", "nathanaelkane/vim-indent-guides"} 219 | return cli.SingleSelectTemplate(message, options) 220 | } 221 | 222 | // CommentPlugin return bool according user choose 223 | func CommentPlugin() bool { 224 | message := "Do you want to use Caw.vim as comment plugin?" 225 | return cli.ConfirmTemplate(message) 226 | } 227 | 228 | // ViewSymbolsPlugin return bool according user choose 229 | func ViewSymbolsPlugin() bool { 230 | message := "Do you want to use vista.vim to view tags and LSP symbols in sidebar" 231 | return cli.ConfirmTemplate(message) 232 | } 233 | 234 | // GentagsPlugin return bool according user choose 235 | func GentagsPlugin() bool { 236 | message := "Do you want to use vim-gutentags to gen tags" 237 | return cli.ConfirmTemplate(message) 238 | } 239 | 240 | // QuickRunPlugin return bool according user choose 241 | func QuickRunPlugin() bool { 242 | message := "Do you want to use vim-quickrun to fast run program in vim?" 243 | return cli.ConfirmTemplate(message) 244 | } 245 | 246 | // DataTypeFile return string slice according user choose 247 | func DataTypeFile(r render.Render) []string { 248 | questionname := "Data filetype" 249 | message := "Which Data filetype you need?" 250 | pagesize := 10 251 | options := make([]string, 0) 252 | for k, _ := range NewDataFileMap(r) { 253 | options = append(options, k) 254 | } 255 | 256 | return cli.MultiSelectTemplate(questionname, message, options, pagesize) 257 | } 258 | 259 | // EnhancePlugin return string slice according user choose 260 | func EnhancePlugin(r render.Render) []string { 261 | questionname := "Enhance question" 262 | message := "Choose the enhance plugins that you need " 263 | pagesize := 10 264 | options := make([]string, 0) 265 | for k, _ := range NewEnhancePluginMap(r) { 266 | options = append(options, k) 267 | } 268 | 269 | return cli.MultiSelectTemplate(questionname, message, options, pagesize) 270 | } 271 | 272 | // SandWichPlugin return bool according user choose 273 | func SandWichPlugin() bool { 274 | message := "Do you want use vim-sandwich more useful than vim-surround?" 275 | return cli.ConfirmTemplate(message) 276 | } 277 | 278 | // VersionControlPlugin return string slice according user choose 279 | func VersionControlPlugin(r render.Render) []string { 280 | questionname := "Version Control plugin" 281 | message := "Choose the version control plugins that you need" 282 | pagesize := 10 283 | 284 | options := make([]string, 0) 285 | for k, _ := range NewVersionPluginMap(r) { 286 | options = append(options, k) 287 | } 288 | 289 | return cli.MultiSelectTemplate(questionname, message, options, pagesize) 290 | } 291 | 292 | // LanguageServerProtocol return string slice according user choose 293 | func LanguageServerProtocol(r render.Render) []string { 294 | questionname := "LanguageQuestion" 295 | message := "What Languages do you write" 296 | pagesize := 19 297 | options := make([]string, 0) 298 | for k, _ := range NewLanguagePlugMap(r) { 299 | options = append(options, k) 300 | } 301 | return cli.MultiSelectTemplate(questionname, message, options, pagesize) 302 | } 303 | -------------------------------------------------------------------------------- /internal/logic/logic.go: -------------------------------------------------------------------------------- 1 | // Package logic provides ... 2 | package logic 3 | 4 | import ( 5 | "github.com/glepnir/jarvim/internal/vim" 6 | "github.com/glepnir/jarvim/pkg/util" 7 | ) 8 | 9 | // RunLogic run our logic 10 | func RunLogic() error { 11 | util.EnsureFoldersExist(vim.ConfPath, vim.ConfCore, vim.ConfAutoload, vim.ConfModules, vim.CachePath, vim.ConfPlugin) 12 | r := PluginManage() 13 | vim.Leaderkey = LeaderKey() 14 | vim.LocalLeaderKey = LocalLeaderKey() 15 | vim.Colorscheme = Colorscheme() 16 | vim.StartScreenPlugin = DashboardPlugin() 17 | vim.StatusLine = SpacelinePlugin() 18 | vim.BufferLine = BufferLinePlugin() 19 | vim.Explorer = ExplorerPlugin() 20 | vim.Database = DatabasePlugin() 21 | vim.Fuzzyfind = FuzzyFindPlugin() 22 | vim.EditorConfig = EditorConfigPlugin() 23 | vim.IndentPlugin = IndentLinePlugin() 24 | vim.CommentPlugin = CommentPlugin() 25 | vim.OutLinePlugin = ViewSymbolsPlugin() 26 | vim.TagsPlugin = GentagsPlugin() 27 | vim.QuickRun = QuickRunPlugin() 28 | vim.DataTypeFile = DataTypeFile(r) 29 | vim.EnhancePlugins = EnhancePlugin(r) 30 | vim.SandwichPlugin = SandWichPlugin() 31 | vim.VersionControlPlugin = VersionControlPlugin(r) 32 | vim.UserLanguages = LanguageServerProtocol(r) 33 | r.GenerateInit() 34 | r.GenerateCore(vim.Leaderkey, vim.LocalLeaderKey, vim.LeaderKeyMap) 35 | r.GeneratePlugMan() 36 | r.GenerateGeneral() 37 | r.GenerateAutoloadFunc() 38 | r.GeneratePluginFolder() 39 | r.GenerateDevIcons() 40 | r.GenerateTheme() 41 | r.GenerateCacheTheme(vim.Colorscheme, vim.ColorschemeMap) 42 | r.GenerateColorscheme(vim.Colorscheme) 43 | r.GenerateDashboard(vim.StartScreenPlugin) 44 | r.GenerateBufferLine(vim.BufferLine) 45 | r.GenerateStatusLine(vim.StatusLine) 46 | r.GenerateExplorer(vim.Explorer) 47 | r.GenerateDatabase(vim.Database) 48 | r.GenerateFuzzyFind(vim.Fuzzyfind) 49 | r.GenerateEditorConfig(vim.EditorConfig) 50 | r.GenerateIndentLine(vim.IndentPlugin) 51 | r.GenerateComment(vim.CommentPlugin) 52 | r.GenerateOutLine(vim.OutLinePlugin) 53 | r.GenerateTags(vim.TagsPlugin) 54 | r.GenerateQuickRun(vim.QuickRun) 55 | r.GenerateDataTypeFile(vim.DataTypeFile, NewDataFileMap(r)) 56 | r.GenerateEnhanceplugin(vim.EnhancePlugins, NewEnhancePluginMap(r)) 57 | r.GenerateSandWich(vim.SandwichPlugin) 58 | r.GenerateTextObj() 59 | r.GenerateVersionControl(vim.VersionControlPlugin, NewVersionPluginMap(r)) 60 | r.GenerateCocJson() 61 | r.GenerateVimMap() 62 | r.GenerateLanguagePlugin(vim.UserLanguages, NewLanguagePlugMap(r)) 63 | r.GenerateInstallScripts() 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /internal/plugin/appearance.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | // DeinDevicons plugin 6 | DeinDevicons = ` 7 | [[plugins]] 8 | repo = 'ryanoasis/vim-devicons' 9 | ` 10 | DeinColorscheme = ` 11 | {{range .}} 12 | [[plugins]] 13 | repo = '{{.}}' 14 | {{end}} 15 | ` 16 | 17 | // DeinDashboard plugin 18 | DeinDashboard = ` 19 | [[plugins]] 20 | repo = 'glepnir/dashboard-nvim' 21 | ` 22 | // DeinStatusline plugin 23 | DeinStatusline = ` 24 | [[plugins]] 25 | repo = 'glepnir/spaceline.vim' 26 | hook_source = ''' 27 | let g:spaceline_seperate_style= 'slant' 28 | ''' 29 | ` 30 | // DeinBufferLine plugin 31 | DeinBufferLine = ` 32 | [[plugins]] 33 | repo = 'romgrk/barbar.nvim' 34 | on_event = ['BufReadPre','BufNewFile'] 35 | ` 36 | // PlugColorscheme 37 | PlugColorscheme = ` 38 | {{range .}} 39 | Plug '{{.}}' 40 | {{end}} 41 | ` 42 | // PlugDevicons 43 | PlugDevicons = ` 44 | Plug 'ryanoasis/vim-devicons' 45 | ` 46 | // PlugDashboard 47 | PlugDashboard = ` 48 | Plug 'glepnir/dashboard-nvim' 49 | ` 50 | //PlugBufferLine 51 | PlugBufferLine = ` 52 | Plug 'romgrk/barbar.nvim' 53 | ` 54 | //PlugStatusline 55 | PlugStatusline = ` 56 | Plug 'glepnir/spaceline.vim' 57 | ` 58 | // PlugStatuslineSetting 59 | PlugStatuslineSetting = ` 60 | let g:spaceline_seperate_style= 'slant' 61 | ` 62 | ) 63 | -------------------------------------------------------------------------------- /internal/plugin/autoload.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | // AutoloadLoadEnv is a hack load data from .env file 5 | const AutoloadLoadEnv = ` 6 | " Load Env file and return env content 7 | function! initself#load_env() 8 | let l:env_file = getenv("HOME")."/.env" 9 | let l:env_dict={} 10 | if filereadable(l:env_file) 11 | let l:env_content = readfile(l:env_file) 12 | for item in l:env_content 13 | let l:env_dict[split(item,"=")[0]] = split(item,"=")[1] 14 | endfor 15 | return l:env_dict 16 | else 17 | echo "env file doesn't exist" 18 | endif 19 | endfunction 20 | 21 | " Load database connection from env file 22 | function! initself#load_db_from_env() 23 | let l:env = initself#load_env() 24 | let l:dbs={} 25 | for key in keys(l:env) 26 | if stridx(key,"DB_CONNECTION_") >= 0 27 | let l:dbs[split(key,"_")[2]] = l:env[key] 28 | endif 29 | endfor 30 | if empty(l:dbs) 31 | echo "Env Database config error" 32 | endif 33 | return l:dbs 34 | endfunction 35 | ` 36 | 37 | // AutoloadSourceFile is a hack to source file 38 | const AutoloadSourceFile = ` 39 | function! initself#source_file(root_path,path, ...) 40 | " Source user configuration files with set/global sensitivity 41 | let use_global = get(a:000, 0, ! has('vim_starting')) 42 | let abspath = resolve(a:root_path . '/' . a:path) 43 | if ! use_global 44 | execute 'source' fnameescape(abspath) 45 | return 46 | endif 47 | 48 | let tempfile = tempname() 49 | let content = map(readfile(abspath), 50 | \ "substitute(v:val, '^\\W*\\zsset\\ze\\W', 'setglobal', '')") 51 | try 52 | call writefile(content, tempfile) 53 | execute printf('source %s', fnameescape(tempfile)) 54 | finally 55 | if filereadable(tempfile) 56 | call delete(tempfile) 57 | endif 58 | endtry 59 | endfunction 60 | ` 61 | 62 | // AutoloadMkdir ensure dir exist 63 | const AutoloadMkdir = ` 64 | " Credits: https://github.com/Shougo/shougo-s-github/blob/master/vim/rc/options.rc.vim#L147 65 | " mkdir 66 | function! initself#mkdir_as_necessary(dir, force) abort 67 | if !isdirectory(a:dir) && &l:buftype == '' && 68 | \ (a:force || input(printf('"%s" does not exist. Create? [y/N]', 69 | \ a:dir)) =~? '^y\%[es]$') 70 | call mkdir(iconv(a:dir, &encoding, &termencoding), 'p') 71 | endif 72 | endfunction 73 | ` 74 | 75 | // AutoloadCoc 76 | const AutoloadCoc = ` 77 | " Jump definition in other window 78 | function! initself#definition_other_window() abort 79 | if winnr('$') >= 4 || winwidth(0) < 120 80 | exec "normal \(coc-definition)" 81 | else 82 | exec 'vsplit' 83 | exec "normal \(coc-definition)" 84 | endif 85 | endfunction 86 | 87 | " COC select the current word 88 | function! initself#select_current_word() 89 | if !get(g:, 'coc_cursors_activated', 0) 90 | return "\(coc-cursors-word)" 91 | endif 92 | return "*\(coc-cursors-word):nohlsearch\" 93 | endfunction 94 | ` 95 | -------------------------------------------------------------------------------- /internal/plugin/core.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | // Core is dein 5 | const Core = ` 6 | if &compatible 7 | " vint: -ProhibitSetNoCompatible 8 | set nocompatible 9 | " vint: +ProhibitSetNoCompatible 10 | endif 11 | 12 | " Set main configuration directory as parent directory 13 | let $VIM_PATH = fnamemodify(resolve(expand(':p')), ':h:h') 14 | 15 | " Set data/cache directory as $XDG_CACHE_HOME/vim 16 | let $DATA_PATH = 17 | \ expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache') . '/vim') 18 | 19 | " Disable vim distribution plugins 20 | let g:loaded_gzip = 1 21 | let g:loaded_tar = 1 22 | let g:loaded_tarPlugin = 1 23 | let g:loaded_zip = 1 24 | let g:loaded_zipPlugin = 1 25 | 26 | let g:loaded_getscript = 1 27 | let g:loaded_getscriptPlugin = 1 28 | let g:loaded_vimball = 1 29 | let g:loaded_vimballPlugin = 1 30 | 31 | let g:loaded_matchit = 1 32 | let g:loaded_matchparen = 1 33 | let g:loaded_2html_plugin = 1 34 | let g:loaded_logiPat = 1 35 | let g:loaded_rrhelper = 1 36 | 37 | let g:loaded_netrw = 1 38 | let g:loaded_netrwPlugin = 1 39 | let g:loaded_netrwSettings = 1 40 | let g:loaded_netrwFileHandlers = 1 41 | 42 | " Initialize base requirements 43 | if has('vim_starting') 44 | " Use spacebar as leader and ; as secondary-leader 45 | " Required before loading plugins! 46 | let g:mapleader="{{index . 0}}" 47 | let g:maplocalleader="{{index . 1}}" 48 | 49 | " Release keymappings prefixes, evict entirely for use of plug-ins. 50 | nnoremap 51 | xnoremap 52 | nnoremap , 53 | xnoremap , 54 | nnoremap ; 55 | xnoremap ; 56 | 57 | endif 58 | 59 | call initself#source_file($VIM_PATH,'core/dein.vim') 60 | call initself#source_file($VIM_PATH,'core/general.vim') 61 | call initself#source_file($VIM_PATH,'core/event.vim') 62 | call initself#source_file($VIM_PATH,'core/pmap.vim') 63 | call initself#source_file($VIM_PATH,'core/vmap.vim') 64 | call theme#theme_init() 65 | 66 | set secure 67 | 68 | " vim: set ts=2 sw=2 tw=80 noet : 69 | ` 70 | 71 | // PlugCore is vim-plug 72 | const PlugCore = ` 73 | if &compatible 74 | " vint: -ProhibitSetNoCompatible 75 | set nocompatible 76 | " vint: +ProhibitSetNoCompatible 77 | endif 78 | 79 | " Set main configuration directory as parent directory 80 | let $VIM_PATH = fnamemodify(resolve(expand(':p')), ':h:h') 81 | 82 | " Set data/cache directory as $XDG_CACHE_HOME/vim 83 | let $DATA_PATH = 84 | \ expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache') . '/vim') 85 | 86 | " Disable vim distribution plugins 87 | let g:loaded_gzip = 1 88 | let g:loaded_tar = 1 89 | let g:loaded_tarPlugin = 1 90 | let g:loaded_zip = 1 91 | let g:loaded_zipPlugin = 1 92 | 93 | let g:loaded_getscript = 1 94 | let g:loaded_getscriptPlugin = 1 95 | let g:loaded_vimball = 1 96 | let g:loaded_vimballPlugin = 1 97 | 98 | let g:loaded_matchit = 1 99 | let g:loaded_matchparen = 1 100 | let g:loaded_2html_plugin = 1 101 | let g:loaded_logiPat = 1 102 | let g:loaded_rrhelper = 1 103 | 104 | let g:loaded_netrw = 1 105 | let g:loaded_netrwPlugin = 1 106 | let g:loaded_netrwSettings = 1 107 | let g:loaded_netrwFileHandlers = 1 108 | 109 | " Initialize base requirements 110 | if has('vim_starting') 111 | " Use spacebar as leader and ; as secondary-leader 112 | " Required before loading plugins! 113 | let g:mapleader="{{index . 0}}" 114 | let g:maplocalleader="{{index . 1}}" 115 | 116 | " Release keymappings prefixes, evict entirely for use of plug-ins. 117 | nnoremap 118 | xnoremap 119 | nnoremap , 120 | xnoremap , 121 | nnoremap ; 122 | xnoremap ; 123 | 124 | endif 125 | 126 | call initself#source_file($VIM_PATH,'core/plug.vim') 127 | call initself#source_file($VIM_PATH,'core/general.vim') 128 | call initself#source_file($VIM_PATH,'core/event.vim') 129 | call initself#source_file($VIM_PATH,'core/vmap.vim') 130 | call theme#theme_init() 131 | 132 | let s:config_paths = split(globpath('$VIM_PATH/modules/', '*'), '\n') 133 | 134 | for config in s:config_paths 135 | exec 'source'. config .'/config.vim' 136 | endfor 137 | 138 | set secure 139 | 140 | " vim: set ts=2 sw=2 tw=80 noet : 141 | ` 142 | -------------------------------------------------------------------------------- /internal/plugin/database.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | // DeinDatabase 6 | DeinDatabase = ` 7 | [[plugins]] 8 | repo = 'tpope/vim-dadbod' 9 | 10 | [[plugins]] 11 | repo = 'kristijanhusak/vim-dadbod-ui' 12 | on_cmd = ['DBUIToggle', 'DBUIAddConnection', 'DBUI', 'DBUIFindBuffer', 'DBUIRenameBuffer'] 13 | on_source = 'vim-dadbod' 14 | hook_source = ''' 15 | let g:db_ui_show_help = 0 16 | let g:db_ui_win_position = 'left' 17 | let g:db_ui_use_nerd_fonts = 1 18 | let g:db_ui_winwidth = 35 19 | let g:db_ui_save_location = $DATA_PATH . '/db_ui_queries' 20 | let g:dbs = initself#load_db_from_env() 21 | ''' 22 | ` 23 | //PlugDatabase 24 | PlugDatabase = ` 25 | Plug 'tpope/vim-dadbod' 26 | Plug 'kristijanhusak/vim-dadbod-ui',{'on':['DBUIToggle', 'DBUIAddConnection', 'DBUI', 'DBUIFindBuffer', 'DBUIRenameBuffer']} 27 | ` 28 | //PlugDatabaseUiSetting 29 | PlugDatabaseUiSetting = ` 30 | let g:db_ui_show_help = 0 31 | let g:db_ui_win_position = 'left' 32 | let g:db_ui_use_nerd_fonts = 1 33 | let g:db_ui_winwidth = 35 34 | let g:db_ui_save_location = $DATA_PATH . '/db_ui_queries' 35 | let g:dbs = initself#load_db_from_env() 36 | ` 37 | ) 38 | -------------------------------------------------------------------------------- /internal/plugin/enhance.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | // DeinDein 6 | DeinDein = ` 7 | [[plugins]] 8 | repo = 'Shougo/dein.vim' 9 | ` 10 | //DeinFastJK 11 | DeinFastJK = ` 12 | [[plugins]] 13 | repo = 'rhysd/accelerated-jk' 14 | on_map = {n = ''} 15 | hook_add = ''' 16 | nmap j (accelerated_jk_gj) 17 | nmap k (accelerated_jk_gk) 18 | ''' 19 | ` 20 | // DeinMundo 21 | DeinMundo = ` 22 | [[plugins]] 23 | repo = 'simnalamburt/vim-mundo' 24 | on_cmd = 'MundoToggle' 25 | ` 26 | // DeinEasyMotion 27 | DeinEasyMotion = ` 28 | [[plugins]] 29 | repo = 'easymotion/vim-easymotion' 30 | on_map = { n = '' } 31 | hook_source = ''' 32 | let g:EasyMotion_do_mapping = 0 33 | let g:EasyMotion_prompt = 'Jump to → ' 34 | let g:EasyMotion_keys = 'fjdkswbeoavn' 35 | let g:EasyMotion_smartcase = 1 36 | let g:EasyMotion_use_smartsign_us = 1 37 | ''' 38 | ` 39 | // DeinRainbow 40 | DeinRainbow = ` 41 | [[plugins]] 42 | repo = 'luochen1990/rainbow' 43 | on_ft = [ 44 | 'html', 45 | 'css', 46 | 'javascript', 47 | 'javascriptreact', 48 | 'go', 49 | 'python', 50 | 'lua', 51 | 'rust', 52 | 'vim', 53 | 'less', 54 | 'stylus', 55 | 'sass', 56 | 'scss', 57 | 'json', 58 | 'ruby', 59 | 'toml', 60 | ] 61 | hook_source = ''' 62 | let g:rainbow_active = 1 63 | ''' 64 | ` 65 | // DeinFloaterm 66 | DeinFloaterm = ` 67 | repo = 'voldikss/vim-floaterm' 68 | on_cmd = ['FloatermNew', 'FloatermToggle', 'FloatermPrev', 'FloatermNext', 'FloatermSend'] 69 | hook_source= ''' 70 | let g:floaterm_position = 'center' 71 | let g:floaterm_wintype = 'floating' 72 | 73 | " Set floaterm window's background to black 74 | hi Floaterm guibg=black 75 | " Set floating window border line color to cyan, and background to orange 76 | hi FloatermBorder guibg=none guifg=cyan 77 | ''' 78 | ` 79 | // PlugFastJK 80 | PlugFastJK = ` 81 | Plug 'rhysd/accelerated-jk' 82 | ` 83 | // PlugMundo 84 | PlugMundo = ` 85 | Plug 'simnalamburt/vim-mundo' 86 | ` 87 | // PlugEasyMotion 88 | PlugEasyMotion = ` 89 | Plug 'easymotion/vim-easymotion' 90 | ` 91 | // PlugRainbow 92 | PlugRainbow = ` 93 | Plug 'luochen1990/rainbow',{'for': ['html','css','javascript','javascriptreact','go','python','lua','rust','vim','less','sass','scss','json','ruby','toml']} 94 | ` 95 | 96 | // PlugFloaterm 97 | PlugFloaterm = ` 98 | Plug 'voldikss/vim-floaterm' 99 | ` 100 | // PlugRainbowSetting 101 | PlugRainbowSetting = ` 102 | " Rainbow 103 | let g:rainbow_active = 1 104 | ` 105 | // PlugFloatermSetting 106 | PlugFloatermSetting = ` 107 | "Floaterm 108 | let g:floaterm_position = 'center' 109 | let g:floaterm_wintype = 'floating' 110 | 111 | " Set floaterm window's background to black 112 | hi Floaterm guibg=black 113 | " Set floating window border line color to cyan, and background to orange 114 | hi FloatermBorder guibg=none guifg=cyan 115 | ` 116 | // PlugEasyMotionSetting 117 | PlugEasyMotionSetting = ` 118 | " Easymotion 119 | let g:EasyMotion_do_mapping = 0 120 | let g:EasyMotion_prompt = 'Jump to → ' 121 | let g:EasyMotion_keys = 'fjdkswbeoavn' 122 | let g:EasyMotion_smartcase = 1 123 | let g:EasyMotion_use_smartsign_us = 1 124 | ` 125 | // PlugFastJKSetting 126 | PlugFastJKSetting = ` 127 | "accelerated-jk 128 | nmap j (accelerated_jk_gj) 129 | nmap k (accelerated_jk_gk) 130 | ` 131 | ) 132 | -------------------------------------------------------------------------------- /internal/plugin/event.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | // Event is event.vim 5 | const Event = ` 6 | augroup common "{{{ 7 | autocmd! 8 | " Reload vim config automatically 9 | autocmd BufWritePost $VIM_PATH/{*.vim,*.yaml,vimrc} nested 10 | \ source $MYVIMRC | redraw 11 | 12 | " Reload Vim script automatically if setlocal autoread 13 | autocmd BufWritePost,FileWritePost *.vim nested 14 | \ if &l:autoread > 0 | source | 15 | \ echo 'source ' . bufname('%') | 16 | \ endif 17 | 18 | " Update filetype on save if empty 19 | autocmd BufWritePost * nested 20 | \ if &l:filetype ==# '' || exists('b:ftdetect') 21 | \ | unlet! b:ftdetect 22 | \ | filetype detect 23 | \ | endif 24 | 25 | " Highlight current line only on focused window 26 | autocmd WinEnter,InsertLeave * if &ft !~# '^\(denite\|clap_\)' | 27 | \ set cursorline | endif 28 | 29 | autocmd WinLeave,InsertEnter * if &ft !~# '^\(denite\|clap_\)' | 30 | \ set nocursorline | endif 31 | 32 | " Automatically set read-only for files being edited elsewhere 33 | autocmd SwapExists * nested let v:swapchoice = 'o' 34 | 35 | " Equalize window dimensions when resizing vim window 36 | autocmd VimResized * tabdo wincmd = 37 | 38 | " Force write shada on leaving nvim 39 | autocmd VimLeave * if has('nvim') | wshada! | else | wviminfo! | endif 40 | 41 | " Check if file changed when its window is focus, more eager than 'autoread' 42 | autocmd FocusGained * checktime 43 | 44 | autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif 45 | 46 | autocmd Syntax * if line('$') > 5000 | syntax sync minlines=200 | endif 47 | 48 | " Make directory automatically. 49 | autocmd BufWritePre * call initself#mkdir_as_necessary(expand(':p:h'), v:cmdbang) 50 | 51 | autocmd BufNewFile,BufRead coc-settings.json setlocal filetype=jsonc 52 | 53 | augroup END "}}} 54 | ` 55 | -------------------------------------------------------------------------------- /internal/plugin/explorer.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | // DeinDefx 6 | DeinDefx = ` 7 | [[plugins]] 8 | repo = 'Shougo/defx.nvim' 9 | on_cmd = 'Defx' 10 | hook_source = ''' 11 | call defx#custom#option('_', { 12 | \ 'resume': 1, 13 | \ 'winwidth': 30, 14 | \ 'split': 'vertical', 15 | \ 'direction': 'topleft', 16 | \ 'show_ignored_files': 0, 17 | \ 'columns': 'indent:git:icons:filename', 18 | \ 'root_marker': ' ', 19 | \ 'floating_preview': 1, 20 | \ 'vertical_preview': 1, 21 | \ 'preview_height': 50, 22 | \ }) 23 | 24 | call defx#custom#column('git', { 25 | \ 'indicators': { 26 | \ 'Modified' : '•', 27 | \ 'Staged' : '✚', 28 | \ 'Untracked' : 'ᵁ', 29 | \ 'Renamed' : '≫', 30 | \ 'Unmerged' : '≠', 31 | \ 'Ignored' : 'ⁱ', 32 | \ 'Deleted' : '✖', 33 | \ 'Unknown' : '⁇' 34 | \ } 35 | \ }) 36 | 37 | call defx#custom#column('mark', { 'readonly_icon': '', 'selected_icon': '' }) 38 | 39 | " Events 40 | " --- 41 | 42 | augroup user_plugin_defx 43 | autocmd! 44 | 45 | " Define defx window mappings 46 | autocmd FileType defx call defx_mappings() 47 | 48 | " Delete defx if it's the only buffer left in the window 49 | autocmd WinEnter * if &filetype == 'defx' && winnr('$') == 1 | bdel | endif 50 | 51 | " Move focus to the next window if current buffer is defx 52 | autocmd TabLeave * if &filetype == 'defx' | wincmd w | endif 53 | 54 | augroup END 55 | 56 | " Internal functions 57 | " --- 58 | function! s:jump_dirty(dir) abort 59 | " Jump to the next position with defx-git dirty symbols 60 | let l:icons = get(g:, 'defx_git_indicators', {}) 61 | let l:icons_pattern = join(values(l:icons), '\|') 62 | 63 | if ! empty(l:icons_pattern) 64 | let l:direction = a:dir > 0 ? 'w' : 'bw' 65 | return search(printf('\(%s\)', l:icons_pattern), l:direction) 66 | endif 67 | endfunction 68 | 69 | function! s:defx_toggle_tree() abort 70 | " Open current file, or toggle directory expand/collapse 71 | if defx#is_directory() 72 | return defx#do_action('open_or_close_tree') 73 | endif 74 | return defx#do_action('multi', ['drop']) 75 | endfunction 76 | 77 | function! s:defx_mappings() abort 78 | " Defx window keyboard mappings 79 | setlocal signcolumn=no expandtab 80 | 81 | nnoremap defx#do_action('drop') 82 | nnoremap l defx_toggle_tree() 83 | nnoremap h defx#async_action('cd', ['..']) 84 | nnoremap st defx#do_action('multi', [['drop', 'tabnew'], 'quit']) 85 | nnoremap s defx#do_action('open', 'botright vsplit') 86 | nnoremap i defx#do_action('open', 'botright split') 87 | nnoremap P defx#do_action('preview') 88 | nnoremap K defx#do_action('new_directory') 89 | nnoremap N defx#do_action('new_multiple_files') 90 | nnoremap dd defx#do_action('remove_trash') 91 | nnoremap r defx#do_action('rename') 92 | nnoremap x defx#do_action('execute_system') 93 | nnoremap . defx#do_action('toggle_ignored_files') 94 | nnoremap yy defx#do_action('yank_path') 95 | nnoremap ~ defx#async_action('cd') 96 | nnoremap q defx#do_action('quit') 97 | nnoremap winnr('$') != 1 ? 98 | \ ':wincmd w' : 99 | \ ':Defx -buffer-name=temp -split=vertical' 100 | " Defx's buffer management 101 | nnoremap q defx#do_action('quit') 102 | nnoremap se defx#do_action('save_session') 103 | nnoremap defx#do_action('redraw') 104 | nnoremap defx#do_action('print') 105 | " File/dir management 106 | nnoremap c defx#do_action('copy') 107 | nnoremap m defx#do_action('move') 108 | nnoremap p defx#do_action('paste') 109 | nnoremap r defx#do_action('rename') 110 | nnoremap dd defx#do_action('remove_trash') 111 | nnoremap K defx#do_action('new_directory') 112 | nnoremap N defx#do_action('new_multiple_files') 113 | 114 | " Jump 115 | nnoremap [g :call jump_dirty(-1) 116 | nnoremap ]g :call jump_dirty(1) 117 | 118 | " Change directory 119 | nnoremap \ defx#do_action('cd', getcwd()) 120 | nnoremap & defx#do_action('cd', getcwd()) 121 | nnoremap defx#async_action('cd', ['..']) 122 | nnoremap ~ defx#async_action('cd') 123 | nnoremap u defx#do_action('cd', ['..']) 124 | nnoremap 2u defx#do_action('cd', ['../..']) 125 | nnoremap 3u defx#do_action('cd', ['../../..']) 126 | nnoremap 4u defx#do_action('cd', ['../../../..']) 127 | 128 | " Selection 129 | nnoremap * defx#do_action('toggle_select_all') 130 | nnoremap 131 | \ defx#do_action('toggle_select') . 'j' 132 | 133 | nnoremap S defx#do_action('toggle_sort', 'Time') 134 | nnoremap C 135 | \ defx#do_action('toggle_columns', 'indent:mark:filename:type:size:time') 136 | endfunction 137 | ''' 138 | 139 | [[plugins]] 140 | repo = 'kristijanhusak/defx-git' 141 | on_source = 'defx.nvim' 142 | hook_source = ''' 143 | let g:defx_git#indicators = { 144 | \ 'Modified' : '•', 145 | \ 'Staged' : '✚', 146 | \ 'Untracked' : 'ᵁ', 147 | \ 'Renamed' : '≫', 148 | \ 'Unmerged' : '≠', 149 | \ 'Ignored' : 'ⁱ', 150 | \ 'Deleted' : '✖', 151 | \ 'Unknown' : '⁇' 152 | \ } 153 | ''' 154 | 155 | [[plugins]] 156 | repo = 'kristijanhusak/defx-icons' 157 | on_source = 'defx.nvim' 158 | hook_add = ''' 159 | let g:defx_icons_column_length = 1 160 | let g:defx_icons_mark_icon = '' 161 | ''' 162 | ` 163 | 164 | DeinNerdTree = ` 165 | [[plugins]] 166 | repo = 'preservim/nerdtree' 167 | on_map = { n = '' } 168 | hook_source: ''' 169 | let g:NERDTreeWinSize = 30 170 | let g:NERDTreeDirArrowExpandable = '▷' 171 | let g:NERDTreeDirArrowCollapsible = '▼' 172 | ''' 173 | 174 | [[plugins]] 175 | repo = 'liuchengxu/nerdtree-dash' 176 | on_source = 'nerdtree' 177 | ''' 178 | 179 | [[plugins]] 180 | repo = 'Xuyuanp/nerdtree-git-plugin' 181 | on_source = 'nerdtree' 182 | ` 183 | 184 | PlugDefx = ` 185 | Plug 'Shougo/defx.nvim' 186 | Plug 'kristijanhusak/defx-icons' 187 | Plug 'kristijanhusak/defx-git' 188 | ` 189 | 190 | PlugNerdTree = ` 191 | Plug 'preservim/nerdtree' 192 | Plug 'liuchengxu/nerdtree-dash' 193 | Plug 'Xuyuanp/nerdtree-git-plugin' 194 | ` 195 | 196 | PlugDefxSetting = ` 197 | call defx#custom#option('_', { 198 | \ 'resume': 1, 199 | \ 'winwidth': 30, 200 | \ 'split': 'vertical', 201 | \ 'direction': 'topleft', 202 | \ 'show_ignored_files': 0, 203 | \ 'columns': 'indent:git:icons:filename', 204 | \ 'root_marker': ' ', 205 | \ 'floating_preview': 1, 206 | \ 'vertical_preview': 1, 207 | \ 'preview_height': 50, 208 | \ }) 209 | 210 | call defx#custom#column('git', { 211 | \ 'indicators': { 212 | \ 'Modified' : '•', 213 | \ 'Staged' : '✚', 214 | \ 'Untracked' : 'ᵁ', 215 | \ 'Renamed' : '≫', 216 | \ 'Unmerged' : '≠', 217 | \ 'Ignored' : 'ⁱ', 218 | \ 'Deleted' : '✖', 219 | \ 'Unknown' : '⁇' 220 | \ } 221 | \ }) 222 | 223 | call defx#custom#column('mark', { 'readonly_icon': '', 'selected_icon': '' }) 224 | 225 | " Events 226 | " --- 227 | 228 | augroup user_plugin_defx 229 | autocmd! 230 | 231 | " Define defx window mappings 232 | autocmd FileType defx call defx_mappings() 233 | 234 | " Delete defx if it's the only buffer left in the window 235 | autocmd WinEnter * if &filetype == 'defx' && winnr('$') == 1 | bdel | endif 236 | 237 | " Move focus to the next window if current buffer is defx 238 | autocmd TabLeave * if &filetype == 'defx' | wincmd w | endif 239 | 240 | augroup END 241 | 242 | " Internal functions 243 | " --- 244 | function! s:jump_dirty(dir) abort 245 | " Jump to the next position with defx-git dirty symbols 246 | let l:icons = get(g:, 'defx_git_indicators', {}) 247 | let l:icons_pattern = join(values(l:icons), '\|') 248 | 249 | if ! empty(l:icons_pattern) 250 | let l:direction = a:dir > 0 ? 'w' : 'bw' 251 | return search(printf('\(%s\)', l:icons_pattern), l:direction) 252 | endif 253 | endfunction 254 | 255 | function! s:defx_toggle_tree() abort 256 | " Open current file, or toggle directory expand/collapse 257 | if defx#is_directory() 258 | return defx#do_action('open_or_close_tree') 259 | endif 260 | return defx#do_action('multi', ['drop']) 261 | endfunction 262 | 263 | function! s:defx_mappings() abort 264 | " Defx window keyboard mappings 265 | setlocal signcolumn=no expandtab 266 | 267 | nnoremap defx#do_action('drop') 268 | nnoremap l defx_toggle_tree() 269 | nnoremap h defx#async_action('cd', ['..']) 270 | nnoremap st defx#do_action('multi', [['drop', 'tabnew'], 'quit']) 271 | nnoremap s defx#do_action('open', 'botright vsplit') 272 | nnoremap i defx#do_action('open', 'botright split') 273 | nnoremap P defx#do_action('preview') 274 | nnoremap K defx#do_action('new_directory') 275 | nnoremap N defx#do_action('new_multiple_files') 276 | nnoremap dd defx#do_action('remove_trash') 277 | nnoremap r defx#do_action('rename') 278 | nnoremap x defx#do_action('execute_system') 279 | nnoremap . defx#do_action('toggle_ignored_files') 280 | nnoremap yy defx#do_action('yank_path') 281 | nnoremap ~ defx#async_action('cd') 282 | nnoremap q defx#do_action('quit') 283 | nnoremap winnr('$') != 1 ? 284 | \ ':wincmd w' : 285 | \ ':Defx -buffer-name=temp -split=vertical' 286 | " Defx's buffer management 287 | nnoremap q defx#do_action('quit') 288 | nnoremap se defx#do_action('save_session') 289 | nnoremap defx#do_action('redraw') 290 | nnoremap defx#do_action('print') 291 | " File/dir management 292 | nnoremap c defx#do_action('copy') 293 | nnoremap m defx#do_action('move') 294 | nnoremap p defx#do_action('paste') 295 | nnoremap r defx#do_action('rename') 296 | nnoremap dd defx#do_action('remove_trash') 297 | nnoremap K defx#do_action('new_directory') 298 | nnoremap N defx#do_action('new_multiple_files') 299 | 300 | " Jump 301 | nnoremap [g :call jump_dirty(-1) 302 | nnoremap ]g :call jump_dirty(1) 303 | 304 | " Change directory 305 | nnoremap \ defx#do_action('cd', getcwd()) 306 | nnoremap & defx#do_action('cd', getcwd()) 307 | nnoremap defx#async_action('cd', ['..']) 308 | nnoremap ~ defx#async_action('cd') 309 | nnoremap u defx#do_action('cd', ['..']) 310 | nnoremap 2u defx#do_action('cd', ['../..']) 311 | nnoremap 3u defx#do_action('cd', ['../../..']) 312 | nnoremap 4u defx#do_action('cd', ['../../../..']) 313 | 314 | " Selection 315 | nnoremap * defx#do_action('toggle_select_all') 316 | nnoremap 317 | \ defx#do_action('toggle_select') . 'j' 318 | 319 | nnoremap S defx#do_action('toggle_sort', 'Time') 320 | nnoremap C 321 | \ defx#do_action('toggle_columns', 'indent:mark:filename:type:size:time') 322 | endfunction 323 | 324 | let g:defx_git#indicators = { 325 | \ 'Modified' : '•', 326 | \ 'Staged' : '✚', 327 | \ 'Untracked' : 'ᵁ', 328 | \ 'Renamed' : '≫', 329 | \ 'Unmerged' : '≠', 330 | \ 'Ignored' : 'ⁱ', 331 | \ 'Deleted' : '✖', 332 | \ 'Unknown' : '⁇' 333 | \ } 334 | 335 | let g:defx_icons_column_length = 1 336 | let g:defx_icons_mark_icon = '' 337 | ` 338 | PlugNerdTreeSetting = ` 339 | let g:NERDTreeWinSize = 30 340 | let g:NERDTreeDirArrowExpandable = '▷' 341 | let g:NERDTreeDirArrowCollapsible = '▼' 342 | ` 343 | ) 344 | 345 | var PlugCocExplorer = false 346 | -------------------------------------------------------------------------------- /internal/plugin/filetype.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinContextFileType = ` 6 | [[plugins]] 7 | repo = 'Shougo/context_filetype.vim' 8 | ` 9 | 10 | DeinMarkDown = ` 11 | [[plugins]] 12 | repo = 'plasticboy/vim-markdown' 13 | on_ft = 'markdown' 14 | hook_add = ''' 15 | let g:vim_markdown_folding_level = 1 16 | let g:vim_markdown_folding_style_pythonic = 1 17 | let g:vim_markdown_frontmatter = 1 18 | let g:vim_markdown_auto_insert_bullets = 1 19 | let g:vim_markdown_new_list_item_indent = 0 20 | let g:vim_markdown_conceal_code_blocks = 0 21 | let g:vim_markdown_conceal = 0 22 | let g:vim_markdown_strikethrough = 1 23 | let g:vim_markdown_edit_url_in = 'vsplit' 24 | let g:vim_markdown_fenced_languages = [ 25 | \ 'c++=cpp', 26 | \ 'viml=vim', 27 | \ 'bash=sh', 28 | \ 'ini=dosini', 29 | \ 'js=javascript', 30 | \ 'json=javascript', 31 | \ 'jsx=javascriptreact', 32 | \ 'tsx=typescriptreact', 33 | \ 'docker=Dockerfile', 34 | \ 'makefile=make', 35 | \ 'py=python' 36 | \ ] 37 | ''' 38 | 39 | [[plugins]] 40 | repo = 'iamcco/markdown-preview.nvim' 41 | on_ft = ['markdown', 'pandoc.markdown', 'rmd'] 42 | build = 'sh -c "cd app & yarn install"' 43 | hook_source = ''' 44 | let g:mkdp_auto_start = 0 45 | ''' 46 | ` 47 | 48 | DeinToml = ` 49 | [[plugins]] 50 | repo = 'cespare/vim-toml' 51 | on_ft = 'toml' 52 | ` 53 | DeinNginx = ` 54 | [[plugins]] 55 | repo = 'chr4/nginx.vim' 56 | on_ft = 'nginx' 57 | ` 58 | 59 | DeinJson = ` 60 | [[plugins]] 61 | repo = 'kevinoid/vim-jsonc' 62 | on_ft = 'json' 63 | ` 64 | 65 | DeinDockerFile = ` 66 | [[plugins]] 67 | repo = 'ekalinin/Dockerfile.vim' 68 | on_ft = [ 'Dockerfile', 'docker-compose' ] 69 | ` 70 | PlugContextFileType = ` 71 | Plug 'Shougo/context_filetype.vim' 72 | ` 73 | PlugMarkDown = ` 74 | Plug 'plasticboy/vim-markdown', {'for': 'markdown'} 75 | Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install','for':'markdown' } 76 | ` 77 | PlugMarkDownSetting = ` 78 | "vim-markdown 79 | let g:vim_markdown_folding_level = 1 80 | let g:vim_markdown_folding_style_pythonic = 1 81 | let g:vim_markdown_frontmatter = 1 82 | let g:vim_markdown_auto_insert_bullets = 1 83 | let g:vim_markdown_new_list_item_indent = 0 84 | let g:vim_markdown_conceal_code_blocks = 0 85 | let g:vim_markdown_conceal = 0 86 | let g:vim_markdown_strikethrough = 1 87 | let g:vim_markdown_edit_url_in = 'vsplit' 88 | let g:vim_markdown_fenced_languages = [ 89 | \ 'c++=cpp', 90 | \ 'viml=vim', 91 | \ 'bash=sh', 92 | \ 'ini=dosini', 93 | \ 'js=javascript', 94 | \ 'json=javascript', 95 | \ 'jsx=javascriptreact', 96 | \ 'tsx=typescriptreact', 97 | \ 'docker=Dockerfile', 98 | \ 'makefile=make', 99 | \ 'py=python' 100 | \ ] 101 | 102 | "Markdwon Preview 103 | let g:mkdp_auto_start = 0 104 | ` 105 | PlugToml = ` 106 | Plug 'cespare/vim-toml', {'for': 'toml'} 107 | ` 108 | PlugNginx = ` 109 | Plug 'chr4/nginx.vim', {'for': 'nginx'} 110 | ` 111 | 112 | PlugJson = ` 113 | Plug 'kevinoid/vim-jsonc',{'for': ['json','jsonc']} 114 | ` 115 | PlugDockerFile = ` 116 | Plug 'ekalinin/Dockerfile.vim',{'for':['Dockerfile','docker-compose']} 117 | ` 118 | ) 119 | -------------------------------------------------------------------------------- /internal/plugin/fuzzyfind.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinClap = ` 6 | [[plugins]] 7 | repo = 'liuchengxu/vim-clap' 8 | merged = 0 9 | build = 'bash install.sh' 10 | on_map = { n = '' } 11 | hook_source = ''' 12 | let s:zshrc = expand($HOME . '/.zshrc') 13 | let s:tmux_conf = expand($HOME . '/.tmux.conf') 14 | let g:clap_cache_directory = $DATA_PATH . '/clap' 15 | let g:clap_theme = 'material_design_dark' 16 | let g:clap_current_selection_sign= { 'text': '➤', 'texthl': "ClapCurrentSelectionSign", "linehl": "ClapCurrentSelection"} 17 | let g:clap_layout = { 'relative': 'editor' } 18 | let g:clap_enable_icon = 1 19 | let g:clap_search_box_border_style = 'curve' 20 | let g:clap_provider_grep_enable_icon = 1 21 | let g:clap_prompt_format = '%spinner%%forerunner_status% %provider_id%: ' 22 | let g:clap_provider_personalconf = { 23 | \ 'source': [s:zshrc,s:tmux_conf], 24 | \ 'sink': 'e', 25 | \ } 26 | 27 | " A funtion to config highlight of ClapSymbol 28 | " when the background color is opactiy 29 | function! s:ClapSymbolHL() abort 30 | let s:current_bgcolor = synIDattr(hlID("Normal"), "bg") 31 | if s:current_bgcolor == '' 32 | hi ClapSymbol guibg=NONE ctermbg=NONE 33 | endif 34 | endfunction 35 | 36 | autocmd User ClapOnEnter call s:ClapSymbolHL() 37 | ''' 38 | 39 | [[plugins]] 40 | repo = 'vn-ki/coc-clap' 41 | on_source = 'vim-clap' 42 | ` 43 | PlugClap = ` 44 | Plug 'liuchengxu/vim-clap', { 'do': ':Clap install-binary!' } 45 | Plug 'vn-ki/coc-clap' 46 | ` 47 | 48 | PlugClapSetting = ` 49 | let s:zshrc = expand($HOME . '/.zshrc') 50 | let s:tmux_conf = expand($HOME . '/.tmux.conf') 51 | let g:clap_cache_directory = $DATA_PATH . '/clap' 52 | let g:clap_theme = 'material_design_dark' 53 | let g:clap_current_selection_sign= { 'text': '➤', 'texthl': "ClapCurrentSelectionSign", "linehl": "ClapCurrentSelection"} 54 | let g:clap_layout = { 'relative': 'editor' } 55 | let g:clap_enable_icon = 1 56 | let g:clap_search_box_border_style = 'curve' 57 | let g:clap_provider_grep_enable_icon = 1 58 | let g:clap_prompt_format = '%spinner%%forerunner_status% %provider_id%: ' 59 | let g:clap_provider_personalconf = { 60 | \ 'source': [s:zshrc,s:tmux_conf], 61 | \ 'sink': 'e', 62 | \ } 63 | 64 | " A funtion to config highlight of ClapSymbol 65 | " when the background color is opactiy 66 | function! s:ClapSymbolHL() abort 67 | let s:current_bgcolor = synIDattr(hlID("Normal"), "bg") 68 | if s:current_bgcolor == '' 69 | hi ClapSymbol guibg=NONE ctermbg=NONE 70 | endif 71 | endfunction 72 | 73 | autocmd User ClapOnEnter call s:ClapSymbolHL() 74 | ` 75 | ) 76 | -------------------------------------------------------------------------------- /internal/plugin/general.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const General = ` 5 | "General settins{{{ 6 | set mouse=nv " Disable mouse in command-line mode 7 | set report=0 " Don't report on line changes 8 | set errorbells " Trigger bell on error 9 | set visualbell " Use visual bell instead of beeping 10 | set hidden " hide buffers when abandoned instead of unload 11 | set fileformats=unix,dos,mac " Use Unix as the standard file type 12 | set magic " For regular expressions turn magic on 13 | set path+=** " Directories to search when using gf and friends 14 | set isfname-== " Remove =, detects filename in var=/foo/bar 15 | set virtualedit=block " Position cursor anywhere in visual block 16 | set synmaxcol=2500 " Don't syntax highlight long lines 17 | set formatoptions+=1 " Don't break lines after a one-letter word 18 | set formatoptions-=t " Don't auto-wrap text 19 | set formatoptions-=o " Disable comment-continuation (normal 'o'/'O') 20 | if has('patch-7.3.541') 21 | set formatoptions+=j " Remove comment leader when joining lines 22 | endif 23 | 24 | if has('vim_starting') 25 | set encoding=utf-8 26 | scriptencoding utf-8 27 | endif 28 | 29 | " What to save for views and sessions: 30 | set viewoptions=folds,cursor,curdir,slash,unix 31 | set sessionoptions=curdir,help,tabpages,winsize 32 | 33 | if has('mac') 34 | let g:clipboard = { 35 | \ 'name': 'macOS-clipboard', 36 | \ 'copy': { 37 | \ '+': 'pbcopy', 38 | \ '*': 'pbcopy', 39 | \ }, 40 | \ 'paste': { 41 | \ '+': 'pbpaste', 42 | \ '*': 'pbpaste', 43 | \ }, 44 | \ 'cache_enabled': 0, 45 | \ } 46 | endif 47 | 48 | if has('clipboard') 49 | set clipboard& clipboard+=unnamedplus 50 | endif 51 | 52 | " Wildmenu {{{ 53 | " -------- 54 | if has('wildmenu') 55 | if ! has('nvim') 56 | set wildmode=list:longest 57 | endif 58 | 59 | " if has('nvim') 60 | " set wildoptions=pum 61 | " else 62 | " set nowildmenu 63 | " set wildmode=list:longest,full 64 | " set wildoptions=tagfile 65 | " endif 66 | set wildignorecase 67 | set wildignore+=.git,.hg,.svn,.stversions,*.pyc,*.spl,*.o,*.out,*~,%* 68 | set wildignore+=*.jpg,*.jpeg,*.png,*.gif,*.zip,**/tmp/**,*.DS_Store 69 | set wildignore+=**/node_modules/**,**/bower_modules/**,*/.sass-cache/* 70 | set wildignore+=application/vendor/**,**/vendor/ckeditor/**,media/vendor/** 71 | set wildignore+=__pycache__,*.egg-info,.pytest_cache,.mypy_cache/** 72 | set wildcharm= " substitue for 'wildchar' () in macros 73 | endif 74 | " }}} 75 | 76 | " Vim Directories {{{ 77 | " --------------- 78 | set nobackup 79 | set nowritebackup 80 | set undofile noswapfile 81 | set directory=$DATA_PATH/swap//,$DATA_PATH,~/tmp,/var/tmp,/tmp 82 | set undodir=$DATA_PATH/undo//,$DATA_PATH,~/tmp,/var/tmp,/tmp 83 | set backupdir=$DATA_PATH/backup/,$DATA_PATH,~/tmp,/var/tmp,/tmp 84 | set viewdir=$DATA_PATH/view/ 85 | " Use the coc-spell-checker to do this 86 | set spellfile=~/.cache/vim/spell/en.utf-8.add 87 | 88 | " History saving 89 | set history=2000 90 | 91 | if has('nvim') && ! has('win32') && ! has('win64') 92 | set shada=!,'300,<50,@100,s10,h 93 | else 94 | set viminfo='300,<10,@50,h,n$DATA_PATH/viminfo 95 | endif 96 | 97 | augroup user_persistent_undo 98 | autocmd! 99 | au BufWritePre /tmp/* setlocal noundofile 100 | au BufWritePre COMMIT_EDITMSG setlocal noundofile 101 | au BufWritePre MERGE_MSG setlocal noundofile 102 | au BufWritePre *.tmp setlocal noundofile 103 | au BufWritePre *.bak setlocal noundofile 104 | augroup END 105 | 106 | " If sudo, disable vim swap/backup/undo/shada/viminfo writing 107 | if $SUDO_USER !=# '' && $USER !=# $SUDO_USER 108 | \ && $HOME !=# expand('~'.$USER) 109 | \ && $HOME ==# expand('~'.$SUDO_USER) 110 | 111 | set noswapfile 112 | set nobackup 113 | set noundofile 114 | if has('nvim') 115 | set shada="NONE" 116 | else 117 | set viminfo="NONE" 118 | endif 119 | endif 120 | 121 | " Secure sensitive information, disable backup files in temp directories 122 | if exists('&backupskip') 123 | set backupskip+=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*,/private/var/* 124 | set backupskip+=.vault.vim 125 | endif 126 | 127 | " Disable swap/undo/viminfo/shada files in temp directories or shm 128 | augroup user_secure 129 | autocmd! 130 | silent! autocmd BufNewFile,BufReadPre 131 | \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*,/private/var/*,.vault.vim 132 | \ setlocal noswapfile noundofile nobackup nowritebackup viminfo= shada= 133 | augroup END 134 | 135 | " }}} 136 | 137 | " Tabs and Indents {{{ 138 | " ---------------- 139 | set textwidth=80 " Text width maximum chars before wrapping 140 | set noexpandtab " Don't expand tabs to spaces 141 | set tabstop=2 " The number of spaces a tab is 142 | set shiftwidth=2 " Number of spaces to use in auto(indent) 143 | set softtabstop=-1 " Automatically keeps in sync with shiftwidth 144 | set smarttab " Tab insert blanks according to 'shiftwidth' 145 | set autoindent " Use same indenting on new lines 146 | set smartindent " Smart autoindenting on new lines 147 | set shiftround " Round indent to multiple of 'shiftwidth' 148 | 149 | if exists('&breakindent') 150 | set breakindentopt=shift:2,min:20 151 | endif 152 | 153 | " }}} 154 | 155 | " Timing {{{ 156 | " ------ 157 | set timeout ttimeout 158 | set timeoutlen=500 " Time out on mappings 159 | set ttimeoutlen=10 " Time out on key codes 160 | set updatetime=100 " Idle time to write swap and trigger CursorHold 161 | set redrawtime=1500 " Time in milliseconds for stopping display redraw 162 | 163 | " }}} 164 | 165 | " Searching {{{ 166 | " --------- 167 | set ignorecase " Search ignoring case 168 | set smartcase " Keep case when searching with * 169 | set infercase " Adjust case in insert completion mode 170 | set incsearch " Incremental search 171 | set wrapscan " Searches wrap around the end of the file 172 | set hlsearch " Highlight search results 173 | 174 | set complete=.,w,b,k " C-n completion: Scan buffers, windows and dictionary 175 | 176 | if exists('+inccommand') 177 | set inccommand=nosplit 178 | endif 179 | 180 | if executable('rg') 181 | set grepformat=%f:%l:%m 182 | let &grepprg = 'rg --vimgrep' . (&smartcase ? ' --smart-case' : '') 183 | elseif executable('ag') 184 | set grepformat=%f:%l:%m 185 | let &grepprg = 'ag --vimgrep' . (&smartcase ? ' --smart-case' : '') 186 | endif 187 | 188 | " }}} 189 | 190 | " Behavior {{{ 191 | " -------- 192 | set autoread " Auto readfile 193 | set nowrap " No wrap by default 194 | set linebreak " Break long lines at 'breakat' 195 | set breakat=\ \ ;:,!? " Long lines break chars 196 | set nostartofline " Cursor in same column for few commands 197 | set whichwrap+=h,l,<,>,[,],~ " Move to following line on certain keys 198 | set splitbelow splitright " Splits open bottom right 199 | set switchbuf=useopen,vsplit " Jump to the first open window 200 | set backspace=indent,eol,start " Intuitive backspacing in insert mode 201 | set diffopt=filler,iwhite " Diff mode: show fillers, ignore whitespace 202 | set completeopt=menu,menuone " Always show menu, even for one item 203 | set completeopt+=noselect,noinsert 204 | 205 | if exists('+completepopup') 206 | set completeopt+=popup 207 | set completepopup=height:4,width:60,highlight:InfoPopup 208 | endif 209 | 210 | if has('patch-8.1.0360') || has('nvim-0.4') 211 | set diffopt+=internal,algorithm:patience 212 | " set diffopt=indent-heuristic,algorithm:patience 213 | endif 214 | " }}} 215 | 216 | " Editor UI {{{ 217 | set termguicolors " Enable true color 218 | set number " Show number 219 | set relativenumber " Show relative number 220 | set noshowmode " Don't show mode on bottom 221 | set noruler " Disable default status ruler 222 | set shortmess=aFc 223 | set scrolloff=2 " Keep at least 2 lines above/below 224 | set fillchars+=vert:\| " add a bar for vertical splits 225 | set fcs=eob:\ " hide ~ tila 226 | set list 227 | set listchars=tab:»·,nbsp:+,trail:·,extends:→,precedes:← 228 | set title 229 | " Title length. 230 | set titlelen=95 231 | " Title string. 232 | let &g:titlestring=" 233 | \ %{expand('%:p:~:.')}%(%m%r%w%) 234 | \ %<\[%{fnamemodify(getcwd(), ':~')}\] - Neovim" 235 | 236 | set showmatch " Jump to matching bracket 237 | set matchpairs+=<:> " Add HTML brackets to pair matching 238 | set matchtime=1 " Tenths of a second to show the matching paren 239 | 240 | set showtabline=2 " Always show the tabs line 241 | set winwidth=30 " Minimum width for active window 242 | set winminwidth=10 " Minimum width for inactive windows 243 | " set winheight=4 " Minimum height for active window 244 | set winminheight=1 " Minimum height for inactive window 245 | set pumheight=15 " Pop-up menu's line height 246 | set helpheight=12 " Minimum help window height 247 | set previewheight=12 " Completion preview height 248 | 249 | set showcmd " Show command in status line 250 | set cmdheight=2 " Height of the command line 251 | set cmdwinheight=5 " Command-line lines 252 | set noequalalways " Don't resize windows on split or close 253 | set laststatus=2 " Always show a status line 254 | "set colorcolumn=+0 " Column highlight at textwidth's max character-limit 255 | set display=lastline 256 | 257 | if has('folding') && has('vim_starting') 258 | set foldenable 259 | set foldmethod=indent 260 | set foldlevelstart=99 261 | endif 262 | 263 | if has('nvim-0.4') 264 | set signcolumn=yes:1 265 | else 266 | set signcolumn=yes " Always show signs column 267 | endif 268 | 269 | if has('conceal') && v:version >= 703 270 | " For snippet_complete marker 271 | set conceallevel=2 concealcursor=niv 272 | endif 273 | 274 | if exists('+previewpopup') 275 | set previewpopup=height:10,width:60 276 | endif 277 | 278 | " Pseudo-transparency for completion menu and floating windows 279 | if &termguicolors 280 | if exists('&pumblend') 281 | set pumblend=10 282 | endif 283 | if exists('&winblend') 284 | set winblend=10 285 | endif 286 | endif 287 | 288 | " }}} 289 | 290 | " vim: set foldmethod=marker ts=2 sw=2 tw=80 noet : 291 | ` 292 | -------------------------------------------------------------------------------- /internal/plugin/initvim.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const InitVim = `execute 'source' fnamemodify(expand(''), ':h').'/core/core.vim'` 5 | -------------------------------------------------------------------------------- /internal/plugin/installscript.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinMakeFile = ` 6 | SHELL = /bin/bash 7 | vim := $(if $(shell which nvim),nvim,$(shell which vim)) 8 | vim_version := '${shell $(vim) --version}' 9 | XDG_CACHE_HOME ?= $(HOME)/.cache 10 | 11 | default: install 12 | 13 | install: 14 | @mkdir -vp "$(XDG_CACHE_HOME)/vim/"{backup,session,swap,tags,undo}; \ 15 | $(vim) -V1 -es -i NONE -N --noplugin -u core/dein.vim -c "try | call dein#update() | call dein#recache_runtimepath() | finally | echomsg '' | qall! | endtry" 16 | 17 | upgrade: 18 | $(vim) -V1 -es -i NONE -N --noplugin -u init.vim -c "try | call dein#clear_state() | call dein#update() | finally | qall! | endtry" 19 | ` 20 | DeinInstallShell = ` 21 | #!/usr/bin/env bash 22 | 23 | # Colors 24 | ESC_SEQ="\x1b[" 25 | COL_RESET=$ESC_SEQ"39;49;00m" 26 | COL_RED=$ESC_SEQ"31;01m" 27 | COL_GREEN=$ESC_SEQ"32;01m" 28 | COL_YELLOW=$ESC_SEQ"33;01m" 29 | COL_BLUE=$ESC_SEQ"34;01m" 30 | COL_MAGENTA=$ESC_SEQ"35;01m" 31 | COL_CYAN=$ESC_SEQ"36;01m" 32 | 33 | function ok() { 34 | echo -e "$COL_GREEN[ok]$COL_CYAN "$1 35 | } 36 | 37 | function running() { 38 | echo -e "$COL_YELLOW ⇒ $COL_RESET "$1": " 39 | } 40 | 41 | function action() { 42 | echo -e "\n$COL_YELLOW[action]:$COL_MAGENTA\n ⇒ $1..." 43 | } 44 | 45 | function warn() { 46 | echo -e "$COL_YELLOW[warning]$COL_RESET "$1 47 | } 48 | 49 | function error() { 50 | echo -e "$COL_RED[error]$COL_RESET "$1 51 | } 52 | 53 | _try_pyenv() { 54 | local name='' src='' 55 | if hash pyenv 2>/dev/null; then 56 | echo '===> pyenv found, searching virtualenvs…' 57 | for name in 'neovim' 'neovim3' 'nvim'; do 58 | src="$(pyenv prefix "${name}" 2>/dev/null)" 59 | if [ -d "${src}" ]; then 60 | error "===> pyenv virtualenv found '${name}'" 61 | # Symlink virtualenv for easy access 62 | ln -fhs "${src}" "${__venv}" 63 | return 0 64 | fi 65 | done 66 | warn "===> skipping pyenv. manual virtualenv isn't found" 67 | warn 68 | warn "Press Ctrl+C and use pyenv to create one yourself (name it 'neovim')" 69 | warn "and run ${0} again. Or press Enter to continue and try 'python3'." 70 | read -r 71 | else 72 | warn '===> pyenv not found, skipping' 73 | fi 74 | return 1 75 | } 76 | 77 | _try_python() { 78 | if ! hash python3 2>/dev/null; then 79 | warn '===> python3 not found, skipping' 80 | return 1 81 | fi 82 | ok "===> python3 found" 83 | [ -d "${__venv}" ] || python3 -m venv "${__venv}" 84 | } 85 | 86 | Install_Pynvim() { 87 | # Concat a base path for vim cache and virtual environment 88 | local __cache="${XDG_CACHE_HOME:-$HOME/.cache}/vim" 89 | local __venv="${__cache}/venv" 90 | mkdir -p "${__cache}" 91 | 92 | if [ -d "${__venv}/neovim3" ]; then 93 | error -n '===> ERROR: Python 2 has ended its life, only one virtualenv is ' 94 | warn 'created now.' 95 | warn "Delete '${__venv}' (or backup!) first, and then run ${0} again." 96 | elif _try_pyenv || _try_python; then 97 | # Install Python 3 requirements 98 | "${__venv}/bin/pip" install -U pynvim PyYAML Send2Trash 99 | ok '===> success' 100 | else 101 | error '===> ERROR: unable to setup python3 virtualenv.' 102 | warn -e '\nConsider using pyenv with its virtualenv plugin:' 103 | warn '- https://github.com/pyenv/pyenv' 104 | warn '- https://github.com/pyenv/pyenv-virtualenv' 105 | fi 106 | } 107 | 108 | action "Checking node and yarn..." 109 | 110 | node --version | grep "v" &> /dev/null 111 | if [ $? != 0 ]; then 112 | error "Node not installed" 113 | warn "Please install node use this script 'curl -sL install-node.now.sh/lts | bash' " 114 | exit 1; 115 | fi 116 | 117 | yarn --version | grep "v" &> /dev/null 118 | if [ $? == 0 ]; then 119 | error "yarn not installed" 120 | warn "Please install yarn use this script 'curl --compressed -o- -L https://yarnpkg.com/install.sh | bash' " 121 | exit 1; 122 | fi 123 | 124 | ok "===> check pass" 125 | 126 | action "Install tools" 127 | 128 | unameOut="$(uname -s)" 129 | case "${unameOut}" in 130 | Linux*) machine=Linux;; 131 | Darwin*) machine=Mac;; 132 | CYGWIN*) machine=Cygwin;; 133 | MINGW*) machine=MinGw;; 134 | *) machine="UNKNOWN:${unameOut}" 135 | esac 136 | 137 | 138 | if [ "$(uname)" == "Darwin" ]; then 139 | running "Found you use mac" 140 | brew install bat 141 | brew install ripgrep 142 | brew install --HEAD universal-ctags/universal-ctags/universal-ctags 143 | elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then 144 | running "Found you use Linux" 145 | if [ -x "$(command -v apk)" ];then sudo apk add bat ripgrep ; fi 146 | if [ -x "$(command -v pkg)" ];then sudo pkg install bat ripgrep ; fi 147 | if [ -x "$(command -v pacman)" ];then sudo pacman -S bat ripgrep ; fi 148 | if [ -x "$(command -v apt-get)" ]; then sudo apt-get install bat ripgrep ; fi 149 | if [ -x "$(command -v dnf)" ]; then sudo dnf install bat ripgrep ; fi 150 | if [ -x "$(command -v nix-env)" ]; then sudo nix-env -i bat ripgrep ; fi 151 | if [ -x "$(command -v zypper)" ]; then sudo zypper install bat ripgrep ; fi 152 | if [ -x "$(command -v yum)" ]; then sudo yum install bat ripgrep ; fi 153 | fi 154 | 155 | action "Install pynvim..." 156 | Install_Pynvim 157 | 158 | action "Install plugins" 159 | cd $HOME/.config/nvim/ 160 | make 161 | running "Clean up..." 162 | rm -rf "$HOME/.cache/vim/dein/cache_nvim" 163 | rm -rf "$HOME/.cache/vim/dein/state_nvim.vim" 164 | rm -rf "$HOME/.cache/vim/dein/.cache/" 165 | nvim -u init.vim -c 'call dein#recache_runtimepath()|q' 166 | 167 | ok "\n 168 | Congratulations thinkvim install success!!!\n 169 | Install your favorite font on here https://www.nerdfonts.com/font-downloads\n 170 | If you use linux,you need install ctags with janson support.\n 171 | Install the Lsp for your languages.\n 172 | Thanks for you love this neovim config." 173 | ` 174 | 175 | PlugMakefile = ` 176 | SHELL = /bin/bash 177 | vim := $(if $(shell which nvim),nvim,$(shell which vim)) 178 | vim_version := '${shell $(vim) --version}' 179 | XDG_CACHE_HOME ?= $(HOME)/.cache 180 | 181 | default: install 182 | 183 | install: 184 | @mkdir -vp "$(XDG_CACHE_HOME)/vim/"{backup,session,swap,tags,undo}; \ 185 | $(vim) +'PlugInstall --sync' +qa 186 | 187 | upgrade: 188 | $(vim) +'PlugUpdate --sync' +qa 189 | ` 190 | 191 | PlugInstallShell = ` 192 | #!/usr/bin/env bash 193 | 194 | # Colors 195 | ESC_SEQ="\x1b[" 196 | COL_RESET=$ESC_SEQ"39;49;00m" 197 | COL_RED=$ESC_SEQ"31;01m" 198 | COL_GREEN=$ESC_SEQ"32;01m" 199 | COL_YELLOW=$ESC_SEQ"33;01m" 200 | COL_BLUE=$ESC_SEQ"34;01m" 201 | COL_MAGENTA=$ESC_SEQ"35;01m" 202 | COL_CYAN=$ESC_SEQ"36;01m" 203 | 204 | function ok() { 205 | echo -e "$COL_GREEN[ok]$COL_CYAN "$1 206 | } 207 | 208 | function running() { 209 | echo -e "$COL_YELLOW ⇒ $COL_RESET "$1": " 210 | } 211 | 212 | function action() { 213 | echo -e "\n$COL_YELLOW[action]:$COL_MAGENTA\n ⇒ $1..." 214 | } 215 | 216 | function warn() { 217 | echo -e "$COL_YELLOW[warning]$COL_RESET "$1 218 | } 219 | 220 | function error() { 221 | echo -e "$COL_RED[error]$COL_RESET "$1 222 | } 223 | 224 | _try_pyenv() { 225 | local name='' src='' 226 | if hash pyenv 2>/dev/null; then 227 | echo '===> pyenv found, searching virtualenvs…' 228 | for name in 'neovim' 'neovim3' 'nvim'; do 229 | src="$(pyenv prefix "${name}" 2>/dev/null)" 230 | if [ -d "${src}" ]; then 231 | error "===> pyenv virtualenv found '${name}'" 232 | # Symlink virtualenv for easy access 233 | ln -fhs "${src}" "${__venv}" 234 | return 0 235 | fi 236 | done 237 | warn "===> skipping pyenv. manual virtualenv isn't found" 238 | warn 239 | warn "Press Ctrl+C and use pyenv to create one yourself (name it 'neovim')" 240 | warn "and run ${0} again. Or press Enter to continue and try 'python3'." 241 | read -r 242 | else 243 | warn '===> pyenv not found, skipping' 244 | fi 245 | return 1 246 | } 247 | 248 | _try_python() { 249 | if ! hash python3 2>/dev/null; then 250 | warn '===> python3 not found, skipping' 251 | return 1 252 | fi 253 | ok "===> python3 found" 254 | [ -d "${__venv}" ] || python3 -m venv "${__venv}" 255 | } 256 | 257 | Install_Pynvim() { 258 | # Concat a base path for vim cache and virtual environment 259 | local __cache="${XDG_CACHE_HOME:-$HOME/.cache}/vim" 260 | local __venv="${__cache}/venv" 261 | mkdir -p "${__cache}" 262 | 263 | if [ -d "${__venv}/neovim3" ]; then 264 | error -n '===> ERROR: Python 2 has ended its life, only one virtualenv is ' 265 | warn 'created now.' 266 | warn "Delete '${__venv}' (or backup!) first, and then run ${0} again." 267 | elif _try_pyenv || _try_python; then 268 | # Install Python 3 requirements 269 | "${__venv}/bin/pip" install -U pynvim PyYAML Send2Trash 270 | ok '===> success' 271 | else 272 | error '===> ERROR: unable to setup python3 virtualenv.' 273 | warn -e '\nConsider using pyenv with its virtualenv plugin:' 274 | warn '- https://github.com/pyenv/pyenv' 275 | warn '- https://github.com/pyenv/pyenv-virtualenv' 276 | fi 277 | } 278 | 279 | action "Checking node and yarn..." 280 | 281 | node --version | grep "v" &> /dev/null 282 | if [ $? != 0 ]; then 283 | error "Node not installed" 284 | warn "Please install node use this script 'curl -sL install-node.now.sh/lts | bash' " 285 | exit 1; 286 | fi 287 | 288 | yarn --version | grep "v" &> /dev/null 289 | if [ $? == 0 ]; then 290 | error "yarn not installed" 291 | warn "Please install yarn use this script 'curl --compressed -o- -L https://yarnpkg.com/install.sh | bash' " 292 | exit 1; 293 | fi 294 | 295 | ok "===> check pass" 296 | 297 | action "Install tools" 298 | 299 | unameOut="$(uname -s)" 300 | case "${unameOut}" in 301 | Linux*) machine=Linux;; 302 | Darwin*) machine=Mac;; 303 | CYGWIN*) machine=Cygwin;; 304 | MINGW*) machine=MinGw;; 305 | *) machine="UNKNOWN:${unameOut}" 306 | esac 307 | 308 | 309 | if [ "$(uname)" == "Darwin" ]; then 310 | running "Found you use mac" 311 | brew install bat 312 | brew install ripgrep 313 | brew install --HEAD universal-ctags/universal-ctags/universal-ctags 314 | elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then 315 | running "Found you use Linux" 316 | if [ -x "$(command -v apk)" ];then sudo apk add bat ripgrep ; fi 317 | if [ -x "$(command -v pkg)" ];then sudo pkg install bat ripgrep ; fi 318 | if [ -x "$(command -v pacman)" ];then sudo pacman -S bat ripgrep ; fi 319 | if [ -x "$(command -v apt-get)" ]; then sudo apt-get install bat ripgrep ; fi 320 | if [ -x "$(command -v dnf)" ]; then sudo dnf install bat ripgrep ; fi 321 | if [ -x "$(command -v nix-env)" ]; then sudo nix-env -i bat ripgrep ; fi 322 | if [ -x "$(command -v zypper)" ]; then sudo zypper install bat ripgrep ; fi 323 | if [ -x "$(command -v yum)" ]; then sudo yum install bat ripgrep ; fi 324 | fi 325 | 326 | action "Install pynvim..." 327 | Install_Pynvim 328 | 329 | action "Install plugins" 330 | cd $HOME/.config/nvim/ 331 | make 332 | running "Clean up..." 333 | 334 | ok "\n 335 | Congratulations thinkvim install success!!!\n 336 | Install your favorite font on here https://www.nerdfonts.com/font-downloads\n 337 | If you use linux,you need install ctags with janson support.\n 338 | Install the Lsp for your languages.\n 339 | Thanks for you love this neovim config." 340 | ` 341 | ) 342 | -------------------------------------------------------------------------------- /internal/plugin/keymap.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const VimKeyMap = ` 5 | " See plugin/bufkill.vim 6 | " use emacs keybind 7 | nmap k :BD 8 | "Write buffer (save) 9 | nnoremap :write 10 | "yank to end 11 | nnoremap Y y$ 12 | " Whitespace jump (see plugin/whitespace.vim) 13 | nnoremap ]w :WhitespaceNext 14 | nnoremap [w :WhitespacePrev 15 | " Remove spaces at the end of lines 16 | nnoremap cw :silent! keeppatterns %substitute/\s\+$//e 17 | 18 | " insert keymap like emacs 19 | inoremap diwa 20 | inoremap 21 | inoremap 22 | inoremap d$a 23 | inoremap u 24 | inoremap 25 | inoremap 26 | inoremap ^i 27 | inoremap pumvisible() ? "\" : "\" 28 | "insert a newline 29 | inoremap o 30 | imap :w 31 | imap :wq 32 | 33 | " command line alias 34 | cnoremap 35 | cnoremap 36 | cnoremap 37 | cnoremap 38 | cnoremap 39 | cnoremap 40 | cnoremap 41 | cnoremap =expand("%:p:h") . "/" 42 | 43 | tnoremap 44 | 45 | function! s:QuiteVim() abort 46 | if empty(expand('%:t')) 47 | execute ":q" 48 | else 49 | execute ":wq!" 50 | endif 51 | endfunction 52 | " Quiet 53 | nnoremap qq :call QuiteVim() 54 | nnoremap qw :q! 55 | 56 | "switch window 57 | nnoremap h 58 | nnoremap l 59 | nnoremap j 60 | nnoremap k 61 | 62 | " settings for resize splitted window 63 | nmap [ :vertical resize -3 64 | nmap ] :vertical resize +3 65 | 66 | " Session management shortcuts (see plugin/sessions.vim) 67 | nmap ss :SessionSave 68 | nmap sl :SessionLoad 69 | ` 70 | 71 | const BuffetKeyMap = ` 72 | "--------------------------" 73 | " vim-buffet Keymap " 74 | "--------------------------" 75 | nnoremap ]b :bp 76 | nnoremap [b :bn 77 | nnoremap bc :Bonly 78 | nnoremap bx :Bw 79 | nmap 1 BuffetSwitch(1) 80 | nmap 2 BuffetSwitch(2) 81 | nmap 3 BuffetSwitch(3) 82 | nmap 4 BuffetSwitch(4) 83 | nmap 5 BuffetSwitch(5) 84 | nmap 6 BuffetSwitch(6) 85 | nmap 7 BuffetSwitch(7) 86 | nmap 8 BuffetSwitch(8) 87 | nmap 9 BuffetSwitch(9) 88 | nmap 0 BuffetSwitch(10) 89 | ` 90 | const DefxKeyMap = ` 91 | nnoremap e 92 | \ :Defx -resume -toggle -buffer-name=tab` + "`tabpagenr()`" 93 | const DefxFindKeyMap = ` 94 | nnoremap F 95 | \ :Defx 96 | \ -search=` + "`escape(expand('%:p'), ' :')`" + `\ -buffer-name=explorer` + "`tabpagenr()`" 97 | 98 | const MarkdwonPreviewKeyMap = ` 99 | nnoremap om :MarkdownPreview 100 | ` 101 | const FloatermKeyMap = ` 102 | nnoremap t :FloatermToggle 103 | ` 104 | 105 | const DataBaseKeyMap = ` 106 | nnoremap od :DBUIToggle 107 | ` 108 | 109 | const CocClapKeyMap = ` 110 | "--------------------------" 111 | " coc-clap Keymap " 112 | "--------------------------" 113 | " Show all diagnostics 114 | nnoremap ce :Clap coc_diagnostics 115 | " Manage extensions 116 | nnoremap ; :Clap coc_extensions 117 | " Show commands 118 | nnoremap , :Clap coc_commands 119 | " Search workspace symbols 120 | nnoremap cs :Clap coc_symbols 121 | nnoremap cS :Clap coc_services 122 | nnoremap ct :Clap coc_outline 123 | ` 124 | 125 | const CocKeyMap = ` 126 | "--------------------------" 127 | " Coc Keymap " 128 | "--------------------------" 129 | " Remap for do codeAction of selected region 130 | function! s:cocActionsOpenFromSelected(type) abort 131 | execute 'CocCommand actions.open ' . a:type 132 | endfunction 133 | xmap a :execute 'CocCommand actions.open ' . visualmode() 134 | nmap a :set operatorfunc=cocActionsOpenFromSelectedg@ 135 | " Do default action for next item. 136 | nmap [a :CocNext 137 | " Do default action for previous item. 138 | nmap ]a :CocPrev 139 | " Use [e and ]e for navigate diagnostics 140 | nmap ]e (coc-diagnostic-prev) 141 | nmap [e (coc-diagnostic-next) 142 | " Remap for rename current word 143 | nmap cn (coc-rename) 144 | " Remap for format selected region 145 | vmap cf (coc-format-selected) 146 | nmap cf (coc-format-selected) 147 | " Fix autofix problem of current line 148 | nmap cF (coc-fix-current) 149 | " Remap keys for gotos 150 | nmap gd :call initself#definition_other_window() 151 | nmap gy (coc-type-definition) 152 | nmap ci (coc-implementation) 153 | nmap gr (coc-references) 154 | " Use K for show documentation in float window 155 | nnoremap K :call CocActionAsync('doHover') 156 | " use for trigger completion. 157 | inoremap coc#refresh() 158 | nmap ]g (coc-git-prevchunk) 159 | nmap [g (coc-git-nextchunk) 160 | " show chunk diff at current position 161 | nmap gi (coc-git-chunkinfo) 162 | " show commit contains current position 163 | nmap gm (coc-git-commit) 164 | " float window scroll 165 | nnoremap coc#float#has_float() ? coc#float#float_scroll(1) : "\" 166 | nnoremap coc#float#has_float() ? coc#float#float_scroll(0) : "\" 167 | " Use for selections ranges. 168 | " NOTE: Requires 'textDocument/selectionRange' support from the language server. 169 | " coc-tsserver, coc-python are the examples of servers that support it. 170 | nmap (coc-range-select) 171 | xmap (coc-range-select) 172 | " Add :OR command for organize imports of the current buffer. 173 | command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') 174 | nnoremap co :OR 175 | " multiple cursors 176 | nmap (coc-cursors-position) 177 | nmap initself#select_current_word() 178 | xmap (coc-cursors-range) 179 | nmap (coc-cursors-operator) 180 | 181 | " Use :Format for format current buffer 182 | command! -nargs=0 Format :call CocAction('format') 183 | 184 | nnoremap fz :CocSearch -w 185 | " Introduce function text object 186 | " NOTE: Requires 'textDocument.documentSymbol' support from the language server. 187 | xmap if (coc-funcobj-i) 188 | xmap af (coc-funcobj-a) 189 | omap if (coc-funcobj-i) 190 | omap af (coc-funcobj-a) 191 | nmap gcj :execute 'CocCommand docthis.documentThis' 192 | ` 193 | 194 | const ClapKeyMap = ` 195 | "--------------------------" 196 | " vim-clap Keymap " 197 | "--------------------------" 198 | nnoremap tc :Clap colors 199 | nnoremap bb :Clap buffers 200 | nnoremap fa :Clap grep2 201 | nnoremap fb :Clap marks 202 | "like emacs counsel-find-file 203 | nnoremap :Clap filer 204 | nnoremap ff :Clap files ++finder=rg --ignore --hidden --files 205 | nnoremap fg :Clap gfiles 206 | nnoremap fw :Clap grep ++query= 207 | nnoremap fh :Clap history 208 | nnoremap fW :Clap windows 209 | nnoremap fl :Clap loclist 210 | nnoremap fu :Clap git_diff_files 211 | nnoremap fv :Clap grep ++query=@visual 212 | nnoremap oc :Clap personalconf 213 | ` 214 | const CawKeyMap = ` 215 | function! InitCaw() abort 216 | if ! (&l:modifiable && &buftype ==# '') 217 | silent! nunmap gc 218 | silent! xunmap gc 219 | silent! nunmap gcc 220 | silent! xunmap gcc 221 | else 222 | nmap gc (caw:prefix) 223 | xmap gc (caw:prefix) 224 | nmap gcc (caw:hatpos:toggle) 225 | xmap gcc (caw:hatpos:toggle) 226 | endif 227 | endfunction 228 | autocmd FileType * call InitCaw() 229 | call InitCaw() 230 | ` 231 | 232 | const CommittiaKeyMap = ` 233 | let g:committia_hooks = {} 234 | function! g:committia_hooks.edit_open(info) 235 | imap (committia-scroll-diff-down-half) 236 | imap (committia-scroll-diff-up-half) 237 | setlocal winminheight=1 winheight=1 238 | resize 10 239 | startinsert 240 | endfunction 241 | ` 242 | 243 | const QuickRunKeyMap = ` 244 | nnoremap cr :QuickRun 245 | ` 246 | 247 | const VistaKeyMap = ` 248 | nnoremap i :Vista!! 249 | ` 250 | 251 | const EasyMotionKeyMap = ` 252 | nmap gsj (easymotion-w) 253 | nmap gsk (easymotion-b) 254 | nmap gsf (easymotion-overwin-f) 255 | ` 256 | 257 | const MundoKeyMap = ` 258 | nnoremap m :MundoToggle 259 | ` 260 | 261 | const SandWichKeyMap = ` 262 | nmap sa (operator-sandwich-add) 263 | xmap sa (operator-sandwich-add) 264 | omap sa (operator-sandwich-g@) 265 | nmap sd (operator-sandwich-delete)(operator-sandwich-release-count)(textobj-sandwich-query-a) 266 | xmap sd (operator-sandwich-delete) 267 | nmap sr (operator-sandwich-replace)(operator-sandwich-release-count)(textobj-sandwich-query-a) xmap sr (operator-sandwich-replace) 268 | nmap sdb (operator-sandwich-delete)(operator-sandwich-release-count)(textobj-sandwich-auto-a) 269 | nmap srb (operator-sandwich-replace)(operator-sandwich-release-count)(textobj-sandwich-auto-a) 270 | omap ib (textobj-sandwich-auto-i) 271 | xmap ib (textobj-sandwich-auto-i) 272 | omap ab (textobj-sandwich-auto-a) 273 | xmap ab (textobj-sandwich-auto-a) 274 | omap is (textobj-sandwich-query-i) 275 | xmap is (textobj-sandwich-query-i) 276 | omap as (textobj-sandwich-query-a) 277 | xmap as (textobj-sandwich-query-a) 278 | ` 279 | 280 | const NiceBlockKeyMap = ` 281 | silent! xmap I (niceblock-I) 282 | silent! xmap gI (niceblock-gI) 283 | silent! xmap A (niceblock-A) 284 | ` 285 | 286 | const VimExpandRegionKeyMap = ` 287 | xmap v (expand_region_expand) 288 | xmap V (expand_region_shrink) 289 | ` 290 | const DsfKeyMap = ` 291 | nmap dsf DsfDelete 292 | nmap csf DsfChange 293 | ` 294 | 295 | const SplitJoinKeyMap = ` 296 | let g:splitjoin_join_mapping = '' 297 | let g:splitjoin_split_mapping = '' 298 | nmap sj :SplitjoinJoin 299 | nmap sk :SplitjoinSplit 300 | ` 301 | 302 | const OperatorReplaceKeyMap = ` 303 | xmap p (operator-replace) 304 | ` 305 | 306 | const MultiBlockKeyMap = ` 307 | omap ab (textobj-multiblock-a) 308 | omap ib (textobj-multiblock-i) 309 | xmap ab (textobj-multiblock-a) 310 | xmap ib (textobj-multiblock-i) 311 | ` 312 | 313 | const TextObjFunctionKeyMap = ` 314 | omap af (textobj-function-a) 315 | omap if (textobj-function-i) 316 | xmap af (textobj-function-a) 317 | xmap if (textobj-function-i) 318 | ` 319 | 320 | const VimagitKeyMap = ` 321 | nnoremap gg :Magit 322 | ` 323 | 324 | const FugiTiveKeyMap = ` 325 | nnoremap ga :Git add %:p 326 | nnoremap gd :Gdiffsplit 327 | nnoremap gc :Git commit 328 | nnoremap gb :Git blame 329 | nnoremap gf :Gfetch 330 | nnoremap gs :Git 331 | nnoremap gp :Gpush 332 | ` 333 | 334 | const NerdTreeKeyMap = ` 335 | nnoremap e :NERDTreeToggle 336 | nnoremap F :NERDTreeFind 337 | ` 338 | 339 | const CocExplorerKeyMap = ` 340 | nmap e :CocCommand explorer 341 | ` 342 | -------------------------------------------------------------------------------- /internal/plugin/languages.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinCFamily = ` 6 | [[pluings]] 7 | repo = 'jackguo380/vim-lsp-cxx-highlight' 8 | on_ft = [ 'c','cpp' ] 9 | hook_source = ''' 10 | call coc#config('languageserver', { 11 | \ 'ccls': { 12 | \ "command": "ccls", 13 | \ "rootPatterns": [".ccls", "compile_commands.json", ".git/", ".hg/"], 14 | \ "filetypes": ["c","cpp","objc","objcpp"], 15 | \ "initializationOptions": { 16 | \ "cache":{ 17 | \ "directory": "/tmp/ccls" 18 | \ } 19 | \ } 20 | \ } 21 | \}) 22 | ''' 23 | ` 24 | DeinR = ` 25 | [[plugins]] 26 | repo = 'jalvesaq/Nvim-R' 27 | on_ft = 'R' 28 | ` 29 | 30 | DeinRExtension = "coc-R" 31 | 32 | DeinJavascript = ` 33 | [[plugins]] 34 | repo = 'pangloss/vim-javascript' 35 | on_ft = [ 'javascript', 'javascriptreact' ] 36 | hook_source = ''' 37 | let g:javascript_plugin_jsdoc = 1 38 | let g:javascript_plugin_flow = 1 39 | ''' 40 | 41 | [[plugins]] 42 | repo = 'moll/vim-node' 43 | on_ft = [ 'javascript', 'javascriptreact' ] 44 | ` 45 | 46 | DeinTypescript = ` 47 | [[plugin]] 48 | repo = 'HerringtonDarkholme/yats.vim' 49 | on_ft = [ 'typescript', 'typescriptreact' ] 50 | ` 51 | 52 | DeinReact = ` 53 | [[plugins]] 54 | repo = 'MaxMEllon/vim-jsx-pretty' 55 | on_ft = [ 'javascript', 'javascriptreact', 'typescriptreact' ] 56 | depends = 'vim-javascript' 57 | hook_add = ''' 58 | let g:vim_jsx_pretty_colorful_config = 1 59 | ''' 60 | ` 61 | DeinVue = ` 62 | [[plugins]] 63 | repo = 'posva/vim-vue' 64 | on_ft = 'vue' 65 | ` 66 | DeinVueExtension = "coc-vetur" 67 | 68 | DeinGo = ` 69 | [[plugins]] 70 | repo = 'fatih/vim-go' 71 | on_ft = ['go','gomod'] 72 | hook_source = ''' 73 | call coc#config('languageserver', { 74 | \ 'golang': { 75 | \ "command": "gopls", 76 | \ "rootPatterns": ["go.mod"], 77 | \ "disableWorkspaceFolders": "true", 78 | \ "filetypes": ["go"] 79 | \ } 80 | \}) 81 | ''' 82 | ` 83 | 84 | DeinRust = ` 85 | [[plugins]] 86 | repo = 'rust-lang/rust.vim' 87 | on_ft = 'rust' 88 | ` 89 | DeinRustExtension = "coc-rust-analyzer" 90 | 91 | DeinHaskell = ` 92 | [[plugins]] 93 | repo = 'neovimhaskell/haskell-vim' 94 | on_ft = 'haskell' 95 | hook_source = ''' 96 | call coc#config('languageserver', { 97 | \ 'haskell': { 98 | \ "command": "hie-wrapper", 99 | \ "rootPatterns": [".stack.yaml","cabal.config","package.yaml"], 100 | \ "filetypes": ["hs","lhs","haskell"], 101 | \ "initializationOptions":{}, 102 | \ "settings":{ 103 | \ "languageServerHaskell":{ 104 | \ "hlintOn":"true", 105 | \ "maxNumberOfProblems":10, 106 | \ "completionSnippetsOn": "true" 107 | \ } 108 | \ } 109 | \ } 110 | \}) 111 | ''' 112 | ` 113 | 114 | DeinPhp = ` 115 | [[plugins]] 116 | repo = 'StanAngeloff/php.vim' 117 | on_ft = 'php' 118 | hook_source = ''' 119 | "php lsp config 120 | call coc#config('languageserver', { 121 | \ 'intelephense': { 122 | \ "command": "intelephense", 123 | \ "args": ["--stdio"], 124 | \ "filetypes": ["php"], 125 | \ "initializationOptions": { 126 | \ "storagePath": "/tmp/intelephense" 127 | \ } 128 | \ } 129 | \}) 130 | ''' 131 | ` 132 | DeinRuby = ` 133 | [[plugins]] 134 | repo = 'vim-ruby/vim-ruby' 135 | on_ft = 'ruby' 136 | ` 137 | DeinRubyExtension = "coc-solargraph" 138 | 139 | DeinScala = ` 140 | [[plugins]] 141 | repo = 'derekwyatt/vim-scala' 142 | on_ft = 'scala' 143 | ` 144 | DeinScalaExtension = "coc-metals" 145 | 146 | DeinShell = ` 147 | [[plugins]] 148 | repo = 'arzg/vim-sh' 149 | on_ft = [ 'sh','zsh' ] 150 | hook_source = ''' 151 | call coc#config('languageserver', { 152 | \ 'bash': { 153 | \ "command": "bash-language-server", 154 | \ "args" : ["start"], 155 | \ "ignoredRootPaths": ["~"], 156 | \ "filetypes": ["sh"] 157 | \ } 158 | \}) 159 | ''' 160 | ` 161 | DeinLua = ` 162 | [[plugins]] 163 | repo = 'tbastos/vim-lua' 164 | on_ft = 'lua' 165 | hook_source = ''' 166 | call coc#config ('languageserver', { 167 | \'lua': { 168 | \ "cwd": "full path of lua-language-server directory", (not sure this one is really necessary) 169 | \ "command": "full path to lua-language-server executable", 170 | \ "args": ["-E", "-e", "LANG=en", "[full path of lua-language-server directory]/main.lua"], 171 | \ "filetypes": ["lua"], 172 | \ "rootPatterns": [".git/"] 173 | \} 174 | \}) 175 | ''' 176 | ` 177 | 178 | DeinPythonExtension = "coc-python" 179 | 180 | DeinPython = ` 181 | [[plugins]] 182 | repo = 'vim-python/python-syntax' 183 | on_ft = 'python' 184 | hook_source = ''' 185 | let g:python_highlight_all = 1 186 | ''' 187 | 188 | [[plugins]] 189 | repo = 'Vimjas/vim-python-pep8-indent' 190 | on_ft = 'python' 191 | 192 | [[plugins]] 193 | repo = 'vim-scripts/python_match.vim' 194 | on_ft = 'python' 195 | 196 | [[plugins]] 197 | repo = 'raimon49/requirements.txt.vim' 198 | on_ft = 'requirements' 199 | ` 200 | 201 | DeinHtml = ` 202 | [[plugins]] 203 | repo = 'othree/html5.vim' 204 | on_ft = 'html' 205 | hook_source = ''' 206 | let g:html5_event_handler_attributes_complete = 0 207 | let g:html5_rdfa_attributes_complete = 0 208 | let g:html5_microdata_attributes_complete = 0 209 | let g:html5_aria_attributes_complete = 0 210 | ''' 211 | ` 212 | DeinHtmlExtension = "coc-html" 213 | 214 | DeinCss = ` 215 | [[plugins]] 216 | repo = 'hail2u/vim-css3-syntax' 217 | on_ft = 'css' 218 | ` 219 | DeinCssExtension = "coc-css" 220 | 221 | DeinLess = ` 222 | repo = 'groenewege/vim-less' 223 | on_ft = 'less' 224 | ` 225 | DeinSass = ` 226 | [[plugins]] 227 | repo = 'cakebaker/scss-syntax.vim' 228 | on_ft = [ 'scss', 'sass' ] 229 | ` 230 | DeinStylus = ` 231 | [[plugins]] 232 | repo = 'iloginow/vim-stylus' 233 | on_ft = 'stylus' 234 | ` 235 | 236 | DeinDart = ` 237 | [[plugins]] 238 | repo = 'dart-lang/dart-vim-plugin' 239 | on_ft = 'dart' 240 | hook_source = ''' 241 | call coc#add_extension('coc-flutter') 242 | ''' 243 | ` 244 | PlugCFamily = ` 245 | Plug 'jackguo380/vim-lsp-cxx-highlight',{'for' : [ 'c','cpp' ]} 246 | ` 247 | PlugCFamilyLsp = ` 248 | " ccls config 249 | call coc#config('languageserver', { 250 | \ 'ccls': { 251 | \ "command": "ccls", 252 | \ "rootPatterns": [".ccls", "compile_commands.json", ".git/", ".hg/"], 253 | \ "filetypes": ["c","cpp","objc","objcpp"], 254 | \ "initializationOptions": { 255 | \ "cache":{ 256 | \ "directory": "/tmp/ccls" 257 | \ } 258 | \ } 259 | \ } 260 | \}) 261 | ''' 262 | ` 263 | PlugR = ` 264 | Plug 'jalvesaq/Nvim-R' ,{'for': 'R'} 265 | ` 266 | PlugRLsp = ` 267 | call coc#add_extension('coc-R') 268 | ` 269 | PlugJavascript = ` 270 | Plug 'pangloss/vim-javascript', {'for': [ 'javascript', 'javascriptreact' ]} 271 | Plug 'moll/vim-node', {'for': [ 'javascript', 'javascriptreact' ]} 272 | ` 273 | PlugJavascriptLsp = ` 274 | let g:javascript_plugin_jsdoc = 1 275 | let g:javascript_plugin_flow = 1 276 | "javascript lsp config 277 | call coc#add_extension('coc-tsserver','coc-eslint','coc-prettier','coc-docthis') 278 | ` 279 | 280 | PlugTypescript = ` 281 | Plug 'HerringtonDarkholme/yats.vim' , {'for' : [ 'typescript', 'typescriptreact' ]} 282 | ` 283 | PlugTypescriptLsp = ` 284 | call coc#add_extension('coc-tsserver','coc-eslint', 'coc-prettier', 'coc-tslint-plugin' ,'coc-docthis') 285 | ` 286 | 287 | PlugReact = ` 288 | Plug 'MaxMEllon/vim-jsx-pretty', {'for': [ 'javascript', 'javascriptreact', 'typescriptreact' ]} 289 | ` 290 | PlugReactLsp = ` 291 | call coc#add_extension('coc-style-helper','coc-react-refactor') 292 | ` 293 | PlugVue = ` 294 | Plug 'posva/vim-vue' , {'for': 'vue'} 295 | ` 296 | 297 | PlugVueLsp = ` 298 | call coc#add_extension('coc-vetur') 299 | ` 300 | PlugGo = ` 301 | Plug 'fatih/vim-go' , {'for' : ['go','gomod']} 302 | ` 303 | PlugGoLsp = ` 304 | call coc#config('languageserver', { 305 | \ 'golang': { 306 | \ "command": "gopls", 307 | \ "rootPatterns": ["go.mod"], 308 | \ "disableWorkspaceFolders": "true", 309 | \ "filetypes": ["go"] 310 | \ } 311 | \}) 312 | ` 313 | 314 | PlugRust = ` 315 | Plug 'rust-lang/rust.vim' ,{'for' : 'rust'} 316 | ` 317 | PlugRustLsp = ` 318 | call coc#add_extension('coc-rust-analyzer') 319 | ` 320 | PlugHaskell = ` 321 | Plug 'neovimhaskell/haskell-vim' , {'for': 'haskell'} 322 | ` 323 | 324 | PlugHaskellLsp = ` 325 | call coc#config('languageserver', { 326 | \ 'haskell': { 327 | \ "command": "hie-wrapper", 328 | \ "rootPatterns": [".stack.yaml","cabal.config","package.yaml"], 329 | \ "filetypes": ["hs","lhs","haskell"], 330 | \ "initializationOptions":{}, 331 | \ "settings":{ 332 | \ "languageServerHaskell":{ 333 | \ "hlintOn":"true", 334 | \ "maxNumberOfProblems":10, 335 | \ "completionSnippetsOn": "true" 336 | \ } 337 | \ } 338 | \ } 339 | \}) 340 | ` 341 | 342 | PlugPhp = ` 343 | Plug 'StanAngeloff/php.vim' , {'for': 'php'} 344 | ` 345 | PlugPhpLsp = ` 346 | call coc#config('languageserver', { 347 | \ 'intelephense': { 348 | \ "command": "intelephense", 349 | \ "args": ["--stdio"], 350 | \ "filetypes": ["php"], 351 | \ "initializationOptions": { 352 | \ "storagePath": "/tmp/intelephense" 353 | \ } 354 | \ } 355 | \}) 356 | ` 357 | PlugRuby = ` 358 | Plug 'vim-ruby/vim-ruby' ,{'for' : 'ruby'} 359 | ` 360 | PlugRubyLsp = ` 361 | call coc#add_extension('coc-solargraph') 362 | ` 363 | 364 | PlugScala = ` 365 | Plug 'derekwyatt/vim-scala',{'for': 'scala'} 366 | ` 367 | PlugScalaLsp = ` 368 | call coc#add_extension('coc-metals') 369 | ` 370 | PlugShell = ` 371 | Plug 'arzg/vim-sh', {'for': [ 'sh','zsh' ]} 372 | ` 373 | PlugShellLsp = ` 374 | call coc#config('languageserver', { 375 | \ 'bash': { 376 | \ "command": "bash-language-server", 377 | \ "args" : ["start"], 378 | \ "ignoredRootPaths": ["~"], 379 | \ "filetypes": ["sh"] 380 | \ } 381 | \}) 382 | ` 383 | PlugLua = ` 384 | Plug 'tbastos/vim-lua',{'for': 'lua'} 385 | ` 386 | PlugLuaLsp = ` 387 | call coc#config ('languageserver', { 388 | \'lua': { 389 | \ "cwd": "full path of lua-language-server directory", (not sure this one is really necessary) 390 | \ "command": "full path to lua-language-server executable", 391 | \ "args": ["-E", "-e", "LANG=en", "[full path of lua-language-server directory]/main.lua"], 392 | \ "filetypes": ["lua"], 393 | \ "rootPatterns": [".git/"] 394 | \} 395 | \}) 396 | ` 397 | 398 | PlugPython = ` 399 | Plug 'vim-python/python-syntax' ,{'for': 'python'} 400 | Plug 'Vimjas/vim-python-pep8-indent',{'for': 'python'} 401 | Plug 'vim-scripts/python_match.vim',{'for': 'python'} 402 | Plug 'raimon49/requirements.txt.vim',{'for': 'python'} 403 | ` 404 | PlugPythonLsp = ` 405 | let g:python_highlight_all = 1 406 | call coc#add_extension('coc-python') 407 | ` 408 | 409 | PlugHtml = ` 410 | Plug 'othree/html5.vim', {'for': 'html'} 411 | ` 412 | 413 | PlugHtmlLsp = ` 414 | let g:html5_event_handler_attributes_complete = 0 415 | let g:html5_rdfa_attributes_complete = 0 416 | let g:html5_microdata_attributes_complete = 0 417 | let g:html5_aria_attributes_complete = 0 418 | 419 | call coc#add_extension('coc-html') 420 | ` 421 | 422 | PlugCss = ` 423 | Plug 'hail2u/vim-css3-syntax' ,{'for': 'css'} 424 | ` 425 | PlugCssLsp = ` 426 | call coc#add_extension('coc-css') 427 | ` 428 | PlugLess = ` 429 | Plug 'groenewege/vim-less' ,{'for' : 'less'} 430 | ` 431 | PlugSass = ` 432 | Plug 'cakebaker/scss-syntax.vim' ,{'for' : [ 'scss', 'sass' ]} 433 | ` 434 | PlugStylus = ` 435 | Plug 'iloginow/vim-stylus' , {'for' : 'stylus'} 436 | ` 437 | 438 | PlugDart = ` 439 | Plug 'dart-lang/dart-vim-plugin' ,{'for': 'dart'} 440 | ` 441 | 442 | PlugDartLsp = ` 443 | call coc#add_extension('coc-flutter') 444 | ` 445 | ) 446 | 447 | var JsTsExtensions = []string{ 448 | "coc-tsserver", 449 | "coc-eslint", 450 | "coc-prettier", 451 | "coc-tslint-plugin", 452 | "coc-docthis", 453 | } 454 | 455 | var ReactExtensions = []string{ 456 | "coc-style-helper", 457 | "coc-react-refactor", 458 | } 459 | -------------------------------------------------------------------------------- /internal/plugin/lsp.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | const ( 4 | DeinCoC = ` 5 | [[plugins]] 6 | repo = 'neoclide/coc.nvim' 7 | merged = 0 8 | rev = 'release' 9 | hook_add = ''' 10 | let g:coc_snippet_next = '' 11 | let g:coc_snippet_prev = '' 12 | let g:coc_status_error_sign = '•' 13 | let g:coc_status_warning_sign = '•' 14 | let g:coc_global_extensions =[ 15 | \ 'coc-snippets', 16 | \ 'coc-pairs', 17 | \ 'coc-json', 18 | \ 'coc-highlight', 19 | \ 'coc-git', 20 | \ 'coc-emoji', 21 | \ 'coc-lists', 22 | \ 'coc-stylelint', 23 | \ 'coc-yaml', 24 | \ 'coc-gitignore', 25 | \ 'coc-yank', 26 | \ 'coc-actions', 27 | \ 'coc-db', 28 | \ 'coc-spell-checker', 29 | \ 'coc-vimlsp', 30 | {{ range . -}} 31 | \ '{{.}}', 32 | {{ end -}} 33 | \] 34 | 35 | augroup coc_event 36 | autocmd! 37 | " Setup formatexpr specified filetype(s). 38 | autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') 39 | " Update signature help on jump placeholder 40 | autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') 41 | augroup end 42 | 43 | " Highlight symbol under cursor on CursorHold 44 | autocmd CursorHold * silent call CocActionAsync('highlight') 45 | 46 | "Use tab for trigger completion with characters ahead and navigate 47 | inoremap 48 | \ pumvisible() ? "\" : 49 | \ check_back_space() ? "\" : 50 | \ coc#refresh() 51 | 52 | inoremap pumvisible() ? "\" : "\" 53 | inoremap pumvisible() ? coc#_select_confirm() : "\u\\=coc#on_enter()\" 54 | 55 | function! s:check_back_space() abort 56 | let col = col('.') - 1 57 | return !col || getline('.')[col - 1] =~# '\s' 58 | endfunction 59 | ''' 60 | 61 | [[plugins]] 62 | repo = 'honza/vim-snippets' 63 | depends = 'coc.nvim' 64 | if = 'has("python3")' 65 | merged = 0 66 | ` 67 | PlugCoc = ` 68 | Plug 'neoclide/coc.nvim', {'branch': 'release'} 69 | Plug 'honza/vim-snippets' 70 | ` 71 | 72 | PlugCocSetting = ` 73 | let g:coc_snippet_next = '' 74 | let g:coc_snippet_prev = '' 75 | let g:coc_status_error_sign = '•' 76 | let g:coc_status_warning_sign = '•' 77 | 78 | {{ if index . 1}} 79 | let g:coc_global_extensions =[ 80 | \ 'coc-snippets', 81 | \ 'coc-pairs', 82 | \ 'coc-json', 83 | \ 'coc-highlight', 84 | \ 'coc-git', 85 | \ 'coc-emoji', 86 | \ 'coc-lists', 87 | \ 'coc-stylelint', 88 | \ 'coc-yaml', 89 | \ 'coc-gitignore', 90 | \ 'coc-yank', 91 | \ 'coc-actions', 92 | \ 'coc-db', 93 | \ 'coc-spell-checker', 94 | \ 'coc-vimlsp', 95 | \ 'coc-explorer', 96 | \] 97 | {{else}} 98 | let g:coc_global_extensions =[ 99 | \ 'coc-snippets', 100 | \ 'coc-pairs', 101 | \ 'coc-json', 102 | \ 'coc-highlight', 103 | \ 'coc-git', 104 | \ 'coc-emoji', 105 | \ 'coc-lists', 106 | \ 'coc-stylelint', 107 | \ 'coc-yaml', 108 | \ 'coc-gitignore', 109 | \ 'coc-yank', 110 | \ 'coc-actions', 111 | \ 'coc-db', 112 | \ 'coc-spell-checker', 113 | \ 'coc-vimlsp', 114 | \] 115 | {{end}} 116 | 117 | 118 | augroup coc_event 119 | autocmd! 120 | " Setup formatexpr specified filetype(s). 121 | autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') 122 | " Update signature help on jump placeholder 123 | autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') 124 | augroup end 125 | 126 | " Highlight symbol under cursor on CursorHold 127 | autocmd CursorHold * silent call CocActionAsync('highlight') 128 | 129 | "Use tab for trigger completion with characters ahead and navigate 130 | inoremap 131 | \ pumvisible() ? "\" : 132 | \ check_back_space() ? "\" : 133 | \ coc#refresh() 134 | 135 | inoremap pumvisible() ? "\" : "\" 136 | inoremap pumvisible() ? coc#_select_confirm() : "\u\\=coc#on_enter()\" 137 | 138 | function! s:check_back_space() abort 139 | let col = col('.') - 1 140 | return !col || getline('.')[col - 1] =~# '\s' 141 | endfunction 142 | ` 143 | ) 144 | 145 | const CocJson = ` 146 | { 147 | "suggest.triggerAfterInsertEnter": false, 148 | "suggest.timeout": 500, 149 | "suggest.noselect": false, 150 | "suggest.detailField": "abbr", 151 | "suggest.snippetIndicator": "🌟", 152 | "suggest.triggerCompletionWait": 100, 153 | "suggest.echodocSupport": true, 154 | "suggest.completionItemKindLabels": { 155 | "keyword": "\uf1de", 156 | "variable": "\ue79b", 157 | "value": "\uf89f", 158 | "operator": "\u03a8", 159 | "function": "\u0192", 160 | "reference": "\ufa46", 161 | "constant": "\uf8fe", 162 | "method": "\uf09a", 163 | "struct": "\ufb44", 164 | "class": "\uf0e8", 165 | "interface": "\uf417", 166 | "text": "\ue612", 167 | "enum": "\uf435", 168 | "enumMember": "\uf02b", 169 | "module": "\uf40d", 170 | "color": "\ue22b", 171 | "property": "\ue624", 172 | "field": "\uf9be", 173 | "unit": "\uf475", 174 | "event": "\ufacd", 175 | "file": "\uf15c", 176 | "folder": "\uf114", 177 | "snippet": "\ue60b", 178 | "typeParameter": "\uf728", 179 | "default": "\uf29c" 180 | }, 181 | //diagnostic 182 | "diagnostic.signOffset": 9999999, 183 | "diagnostic.errorSign": "●", 184 | "diagnostic.warningSign": "●", 185 | "diagnostic.infoSign": "●", 186 | "diagnostic.displayByAle": false, 187 | "diagnostic.refreshOnInsertMode": true, 188 | //git 189 | "git.enableGutters": true, 190 | "git.branchCharacter": "\uf418", 191 | "git.addGBlameToBufferVar": true, 192 | "git.addGBlameToVirtualText": true, 193 | "git.virtualTextPrefix": " ❯❯❯ ", 194 | "git.addedSign.hlGroup": "GitGutterAdd", 195 | "git.changedSign.hlGroup": "GitGutterChange", 196 | "git.removedSign.hlGroup": "GitGutterDelete", 197 | "git.topRemovedSign.hlGroup": "GitGutterDelete", 198 | "git.changeRemovedSign.hlGroup": "GitGutterChangeDelete", 199 | "git.addedSign.text": "▋", 200 | "git.changedSign.text": "▋", 201 | "git.removedSign.text": "▋", 202 | "git.topRemovedSign.text": "▔", 203 | "git.changeRemovedSign.text": "▋", 204 | //Snippet 205 | "coc.preferences.snippetStatusText": "Ⓢ ", 206 | //CocList 207 | "list.source.files.defaultOptions": ["--auto-preview"], 208 | "list.source.outline.defaultOptions": ["--auto-preview"], 209 | //prettier 210 | "coc.preferences.formatOnSaveFiletypes": [ 211 | "html", 212 | "css", 213 | "markdown", 214 | "javascript", 215 | "javascriptreact", 216 | "typescript", 217 | "typescriptreact", 218 | "go", 219 | "json" 220 | ], 221 | "prettier.statusItemText": "ⓟ ", 222 | "prettier.eslintIntegration": true, 223 | "prettier.tslintIntegration": false, 224 | "prettier.stylelintIntegration": true, 225 | "prettier.disableSuccessMessage": true, 226 | //emmet 227 | "emmet.includeLanguages": { 228 | "vue-html": "html", 229 | "javascript": "javascriptreact", 230 | "typescriptreact": "typescriptreact" 231 | }, 232 | //imselect 233 | "imselect.enableStatusItem": false, 234 | //multiple curssor 235 | "cursors.nextKey": "", 236 | "cursors.previousKey": "", 237 | "cursors.cancelKey": "", 238 | //sessions 239 | "session.directory": "~/.cache/vim/session", 240 | // coc-explorer 241 | "explorer.icon.expanded": "▾", 242 | "explorer.icon.collapsed": "▸", 243 | "explorer.width": 30, 244 | "explorer.icon.enableNerdfont": true, 245 | "explorer.quitOnOpen": true, 246 | "explorer.floating.width": -20, 247 | "explorer.floating.height": -10, 248 | "explorer.openAction.strategy": "sourceWindow", 249 | // eslint 250 | "eslint.filetypes": [ 251 | "javascript", 252 | "javascriptreact", 253 | "typescript", 254 | "typescriptreact" 255 | ], 256 | "eslint.autoFix": true, 257 | "eslint.autoFixOnSave": true, 258 | // coc-actions 259 | "coc-actions.hideCursor": false, 260 | // Cspell 261 | "cSpell.fixSpellingWithRenameProvider": true, 262 | "cSpell.showStatus": false, 263 | "cSpell.enabledLanguageIds": [ 264 | "asciidoc", 265 | "c", 266 | "cpp", 267 | "csharp", 268 | "css", 269 | "git-commit", 270 | "gitcommit", 271 | "go", 272 | "haskell", 273 | "html", 274 | "java", 275 | "javascript", 276 | "javascriptreact", 277 | "json", 278 | "jsonc", 279 | "latex", 280 | "less", 281 | "markdown", 282 | "php", 283 | "plaintext", 284 | "python", 285 | "pug", 286 | "restructuredtext", 287 | "rust", 288 | "scala", 289 | "scss", 290 | "text", 291 | "typescript", 292 | "typescriptreact", 293 | "yaml", 294 | "yml", 295 | "vim" 296 | ] 297 | } 298 | ` 299 | -------------------------------------------------------------------------------- /internal/plugin/pluginmanage.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const Dein = ` 5 | " Set main configuration directory as parent directory 6 | let $VIM_PATH = 7 | \ get(g:, 'etc_vim_path', 8 | \ exists('*stdpath') ? stdpath('config') : 9 | \ ! empty($MYVIMRC) ? fnamemodify(expand($MYVIMRC), ':h') : 10 | \ ! empty($VIMCONFIG) ? expand($VIMCONFIG) : 11 | \ ! empty($VIM_PATH) ? expand($VIM_PATH) : 12 | \ fnamemodify(resolve(expand(':p')), ':h:h') 13 | \ ) 14 | 15 | " Set data/cache directory as $XDG_CACHE_HOME/vim 16 | let $DATA_PATH = 17 | \ expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache') . '/vim') 18 | 19 | " Collection of plugins list config file-paths 20 | let s:config_paths = split(globpath('$VIM_PATH/modules', '*'), '\n') 21 | 22 | function! s:main() 23 | if has('vim_starting') 24 | " When using VIMINIT trick for exotic MYVIMRC locations, add path now. 25 | if &runtimepath !~# $VIM_PATH 26 | set runtimepath^=$VIM_PATH 27 | endif 28 | 29 | " Ensure data directories 30 | for s:path in [ 31 | \ $DATA_PATH, 32 | \ $DATA_PATH . '/undo', 33 | \ $DATA_PATH . '/backup', 34 | \ $DATA_PATH . '/session'] 35 | if ! isdirectory(s:path) 36 | call mkdir(s:path, 'p') 37 | endif 38 | endfor 39 | 40 | " Python interpreter settings 41 | if has('nvim') 42 | " Try using pyenv virtualenv called 'neovim' 43 | let l:virtualenv = '' 44 | if ! empty($PYENV_ROOT) 45 | let l:virtualenv = $PYENV_ROOT . '/versions/neovim/bin/python' 46 | endif 47 | if empty(l:virtualenv) || ! filereadable(l:virtualenv) 48 | " Fallback to old virtualenv location 49 | let l:virtualenv = $DATA_PATH . '/venv/neovim3/bin/python' 50 | endif 51 | if filereadable(l:virtualenv) 52 | let g:python3_host_prog = l:virtualenv 53 | endif 54 | 55 | elseif has('pythonx') 56 | if has('python3') 57 | set pyxversion=3 58 | elseif has('python') 59 | set pyxversion=2 60 | endif 61 | endif 62 | endif 63 | 64 | " Initializes chosen package manager 65 | call s:use_dein() 66 | endfunction 67 | 68 | function! s:use_dein() 69 | let l:cache_path = $DATA_PATH . '/dein' 70 | 71 | if has('vim_starting') 72 | " Use dein as a plugin manager 73 | let g:dein#auto_recache = 1 74 | let g:dein#install_max_processes = 12 75 | let g:dein#install_progress_type = 'title' 76 | let g:dein#enable_notification = 1 77 | let g:dein#install_log_filename = $DATA_PATH . '/dein.log' 78 | 79 | " Add dein to vim's runtimepath 80 | if &runtimepath !~# '/dein.vim' 81 | let s:dein_dir = l:cache_path . '/repos/github.com/Shougo/dein.vim' 82 | " Clone dein if first-time setup 83 | if ! isdirectory(s:dein_dir) 84 | execute '!git clone https://github.com/Shougo/dein.vim' s:dein_dir 85 | if v:shell_error 86 | call s:error('dein installation has failed! is git installed?') 87 | finish 88 | endif 89 | endif 90 | 91 | execute 'set runtimepath+='.substitute( 92 | \ fnamemodify(s:dein_dir, ':p') , '/$', '', '') 93 | endif 94 | endif 95 | 96 | " Initialize dein.vim (package manager) 97 | if dein#load_state(l:cache_path) 98 | 99 | " Start propagating file paths and plugin presets 100 | call dein#begin(l:cache_path, extend([expand('')], s:config_paths)) 101 | 102 | for l:repo_toml in s:config_paths 103 | call dein#load_toml(l:repo_toml) 104 | endfor 105 | 106 | call dein#end() 107 | 108 | " Save cached state for faster startups 109 | if ! g:dein#_is_sudo 110 | call dein#save_state() 111 | endif 112 | 113 | " Update or install plugins if a change detected 114 | if dein#check_install() 115 | if ! has('nvim') 116 | set nomore 117 | endif 118 | call dein#install() 119 | endif 120 | endif 121 | 122 | filetype plugin indent on 123 | 124 | " Only enable syntax when vim is starting 125 | if has('vim_starting') 126 | syntax enable 127 | endif 128 | 129 | " Trigger source event hooks 130 | call dein#call_hook('source') 131 | call dein#call_hook('post_source') 132 | endfunction 133 | 134 | call s:main() 135 | ` 136 | 137 | const VimPlug = ` 138 | " Set main configuration directory as parent directory 139 | let $VIM_PATH = 140 | \ get(g:, 'etc_vim_path', 141 | \ exists('*stdpath') ? stdpath('config') : 142 | \ ! empty($MYVIMRC) ? fnamemodify(expand($MYVIMRC), ':h') : 143 | \ ! empty($VIMCONFIG) ? expand($VIMCONFIG) : 144 | \ ! empty($VIM_PATH) ? expand($VIM_PATH) : 145 | \ fnamemodify(resolve(expand(':p')), ':h:h') 146 | \ ) 147 | 148 | " Set data/cache directory as $XDG_CACHE_HOME/vim 149 | let $DATA_PATH = 150 | \ expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache') . '/vim') 151 | 152 | " Collection of plugins list config file-paths 153 | let s:plugin_paths = split(globpath('$VIM_PATH/modules/', '*'), '\n') 154 | 155 | function! s:main() 156 | if has('vim_starting') 157 | " When using VIMINIT trick for exotic MYVIMRC locations, add path now. 158 | if &runtimepath !~# $VIM_PATH 159 | set runtimepath^=$VIM_PATH 160 | endif 161 | 162 | " Ensure data directories 163 | for s:path in [ 164 | \ $DATA_PATH, 165 | \ $DATA_PATH . '/undo', 166 | \ $DATA_PATH . '/backup', 167 | \ $DATA_PATH . '/session'] 168 | if ! isdirectory(s:path) 169 | call mkdir(s:path, 'p') 170 | endif 171 | endfor 172 | 173 | " Python interpreter settings 174 | if has('nvim') 175 | " Try using pyenv virtualenv called 'neovim' 176 | let l:virtualenv = '' 177 | if ! empty($PYENV_ROOT) 178 | let l:virtualenv = $PYENV_ROOT . '/versions/neovim/bin/python' 179 | endif 180 | if empty(l:virtualenv) || ! filereadable(l:virtualenv) 181 | " Fallback to old virtualenv location 182 | let l:virtualenv = $DATA_PATH . '/venv/neovim3/bin/python' 183 | endif 184 | if filereadable(l:virtualenv) 185 | let g:python3_host_prog = l:virtualenv 186 | endif 187 | 188 | elseif has('pythonx') 189 | if has('python3') 190 | set pyxversion=3 191 | elseif has('python') 192 | set pyxversion=2 193 | endif 194 | endif 195 | endif 196 | 197 | " Initializes chosen package manager 198 | call s:use_plug() 199 | endfunction 200 | 201 | function! s:use_plug() abort 202 | " vim-plug package-manager initialization 203 | let l:cache_root = $DATA_PATH . '/plug' 204 | let l:cache_init = l:cache_root . '/init.vimplug' 205 | let l:cache_repos = l:cache_root . '/repos' 206 | 207 | augroup user_plugin_vimplug 208 | autocmd! 209 | augroup END 210 | 211 | if &runtimepath !~# '/init.vimplug' 212 | 213 | if empty(glob(l:cache_init.'/autoload/plug.vim')) 214 | execute '!git clone --depth=1 https://github.com/junegunn/vim-plug' l:cache_init.'/autoload' 215 | if v:shell_error 216 | call s:error('vim-plug installation has failed! is git installed?') 217 | return 218 | endif 219 | autocmd VimEnter * PlugInstall --sync | source $MYVIMRC 220 | endif 221 | 222 | execute 'set runtimepath+='.substitute( 223 | \ fnamemodify(l:cache_init, ':p') , '/$', '', '') 224 | endif 225 | 226 | call plug#begin(l:cache_repos) 227 | 228 | " Automatically install missing plugins on startup 229 | if !empty(filter(copy(g:plugs), '!isdirectory(v:val.dir)')) 230 | autocmd VimEnter * PlugInstall --sync | q 231 | endif 232 | 233 | for l:plugin in s:plugin_paths 234 | exec 'source'. l:plugin .'/plugins.vim' 235 | endfor 236 | 237 | call plug#end() 238 | endfunction 239 | 240 | function! s:str2list(expr) 241 | " Convert string to list 242 | return type(a:expr) ==# v:t_list ? a:expr : split(a:expr, '\n') 243 | endfunction 244 | 245 | function! s:error(msg) 246 | for l:mes in s:str2list(a:msg) 247 | echohl WarningMsg | echomsg '[config/init] ' . l:mes | echohl None 248 | endfor 249 | endfunction 250 | 251 | call s:main() 252 | ` 253 | -------------------------------------------------------------------------------- /internal/plugin/program.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinEditorConfig = ` 6 | [[plugins]] 7 | repo = 'editorconfig/editorconfig-vim' 8 | ` 9 | 10 | DeinIndentLine = ` 11 | [[plugins]] 12 | repo = 'Yggdroot/indentLine' 13 | on_event = 'BufReadPre' 14 | hook_source = ''' 15 | let g:indentLine_enabled = 1 16 | let g:indentLine_char='┆' 17 | let g:indentLine_fileTypeExclude = ['defx', 'denite','startify','tagbar','vista_kind','vista','coc-explorer','dashboard'] 18 | let g:indentLine_concealcursor = 'niv' 19 | let g:indentLine_showFirstIndentLevel =1 20 | ''' 21 | ` 22 | DeinIndenGuides = ` 23 | [[plugins]] 24 | repo = 'nathanaelkane/vim-indent-guides' 25 | on_event = 'FileType' 26 | hook_post_source: IndentGuidesEnable 27 | hook_add = ''' 28 | let g:indent_guides_default_mapping = 0 29 | let g:indent_guides_tab_guides = 0 30 | let g:indent_guides_color_change_percent = 3 31 | let g:indent_guides_guide_size = 1 32 | let g:indent_guides_exclude_filetypes = [ 33 | \ 'help', 'denite', 'denite-filter', 'startify', 34 | \ 'vista', 'vista_kind', 'tagbar', 'nerdtree', 35 | \ 'lsp-hover', 'clap_input' 36 | \ ] 37 | ''' 38 | ` 39 | 40 | DeinCaw = ` 41 | [[plugins]] 42 | repo = 'tyru/caw.vim' 43 | depends = 'context_filetype.vim' 44 | on_map = { nx = '' } 45 | ` 46 | 47 | DeinVista = ` 48 | [[plugins]] 49 | repo = 'liuchengxu/vista.vim' 50 | on_cmd = ['Vista', 'Vista!', 'Vista!!'] 51 | hook_source = ''' 52 | let g:vista#renderer#enable_icon = 1 53 | let g:vista_disable_statusline = 1 54 | let g:vista_default_executive = 'ctags' 55 | let g:vista_echo_cursor_strategy = 'floating_win' 56 | let g:vista_vimwiki_executive = 'markdown' 57 | let g:vista_executive_for = { 58 | \ 'vimwiki': 'markdown', 59 | \ 'pandoc': 'markdown', 60 | \ 'markdown': 'toc', 61 | \ 'yaml': 'coc', 62 | \ 'typescript': 'coc', 63 | \ 'typescriptreact': 'coc', 64 | \ } 65 | ''' 66 | ` 67 | 68 | DeinGuTenTags = ` 69 | [[plugins]] 70 | repo = 'ludovicchabant/vim-gutentags' 71 | if = 'executable("ctags")' 72 | on_event = ['BufReadPost', 'BufWritePost'] 73 | hook_source = ''' 74 | let g:gutentags_cache_dir = $DATA_PATH . '/tags' 75 | let g:gutentags_project_root = ['.root', '.git', '.svn', '.hg', '.project','go.mod','/usr/local'] 76 | let g:gutentags_generate_on_write = 1 77 | let g:gutentags_generate_on_missing = 1 78 | let g:gutentags_generate_on_new = 0 79 | let g:gutentags_exclude_filetypes = [ 'defx', 'denite', 'vista', 'magit' ] 80 | let g:gutentags_ctags_extra_args = ['--output-format=e-ctags'] 81 | let g:gutentags_ctags_exclude = ['*.json', '*.js', '*.ts', '*.jsx', '*.css', '*.less', '*.sass', '*.go', '*.dart', 'node_modules', 'dist', 'vendor'] 82 | ''' 83 | ` 84 | 85 | DeinQuickRun = ` 86 | [[plugins]] 87 | repo = 'thinca/vim-quickrun' 88 | on_cmd = 'QuickRun' 89 | hook_source = ''' 90 | let g:quickrun_config = { 91 | \ "_" : { 92 | \ "outputter" : "message", 93 | \ }, 94 | \} 95 | let g:quickrun_no_default_key_mappings = 1 96 | ''' 97 | ` 98 | 99 | DeinEmmet = ` 100 | [[plugins]] 101 | repo = 'mattn/emmet-vim' 102 | on_event = 'InsertEnter' 103 | on_ft = [ 'html','css','javascript','javascriptreact','vue','typescript','typescriptreact' ] 104 | hook_source = ''' 105 | let g:user_emmet_complete_tag = 0 106 | let g:user_emmet_install_global = 0 107 | let g:user_emmet_install_command = 0 108 | let g:user_emmet_mode = 'i' 109 | ''' 110 | ` 111 | PlugIndentLine = ` 112 | Plug 'Yggdroot/indentLine' 113 | ` 114 | PlugIndentGuides = ` 115 | Plug 'nathanaelkane/vim-indent-guides' 116 | ` 117 | 118 | PlugIndentLineSetting = ` 119 | let g:indentLine_enabled = 1 120 | let g:indentLine_char='┆' 121 | let g:indentLine_fileTypeExclude = ['defx', 'denite','startify','tagbar','vista_kind','vista','coc-explorer','dashboard'] 122 | let g:indentLine_concealcursor = 'niv' 123 | let g:indentLine_showFirstIndentLevel =1 124 | ` 125 | PlugIndentGuidesSetting = ` 126 | let g:indent_guides_default_mapping = 0 127 | let g:indent_guides_tab_guides = 0 128 | let g:indent_guides_color_change_percent = 3 129 | let g:indent_guides_guide_size = 1 130 | let g:indent_guides_exclude_filetypes = [ 131 | \ 'help', 'denite', 'denite-filter', 'startify', 132 | \ 'vista', 'vista_kind', 'tagbar', 'nerdtree', 133 | \ 'lsp-hover', 'clap_input' 134 | \ ] 135 | ` 136 | PlugCawvim = ` 137 | Plug 'tyru/caw.vim' 138 | ` 139 | PlugVista = ` 140 | Plug 'liuchengxu/vista.vim',{'on': ['Vista', 'Vista!', 'Vista!!']} 141 | ` 142 | PlugVistaSetting = ` 143 | let g:vista#renderer#enable_icon = 1 144 | let g:vista_disable_statusline = 1 145 | let g:vista_default_executive = 'ctags' 146 | let g:vista_echo_cursor_strategy = 'floating_win' 147 | let g:vista_vimwiki_executive = 'markdown' 148 | let g:vista_executive_for = { 149 | \ 'vimwiki': 'markdown', 150 | \ 'pandoc': 'markdown', 151 | \ 'markdown': 'toc', 152 | \ 'yaml': 'coc', 153 | \ 'typescript': 'coc', 154 | \ 'typescriptreact': 'coc', 155 | \ } 156 | ` 157 | PlugGuTenTags = ` 158 | if executable('ctags') 159 | Plug 'ludovicchabant/vim-gutentags' 160 | endif 161 | ` 162 | PlugGuTenTagsSetting = ` 163 | let g:gutentags_cache_dir = $DATA_PATH . '/tags' 164 | let g:gutentags_project_root = ['.root', '.git', '.svn', '.hg', '.project','go.mod','/usr/local'] 165 | let g:gutentags_generate_on_write = 1 166 | let g:gutentags_generate_on_missing = 1 167 | let g:gutentags_generate_on_new = 0 168 | let g:gutentags_exclude_filetypes = [ 'defx', 'denite', 'vista', 'magit' ] 169 | let g:gutentags_ctags_extra_args = ['--output-format=e-ctags'] 170 | let g:gutentags_ctags_exclude = ['*.json', '*.js', '*.ts', '*.jsx', '*.css', '*.less', '*.sass', '*.go', '*.dart', 'node_modules', 'dist', 'vendor'] 171 | ` 172 | PlugQuickRun = ` 173 | Plug 'thinca/vim-quickrun',{'on': 'QuickRun'} 174 | ` 175 | PlugQuickRunSetting = ` 176 | let g:quickrun_config = { 177 | \ "_" : { 178 | \ "outputter" : "message", 179 | \ }, 180 | \} 181 | let g:quickrun_no_default_key_mappings = 1 182 | ` 183 | PlugEditorConfig = ` 184 | Plug 'editorconfig/editorconfig-vim' 185 | ` 186 | 187 | PlugEmmet = ` 188 | Plug 'mattn/emmet-vim' ,{'for': [ 'html','css','javascript','javascriptreact','vue','typescript','typescriptreact' ]} 189 | ` 190 | 191 | PlugEmmetSetting = ` 192 | let g:user_emmet_complete_tag = 0 193 | let g:user_emmet_install_global = 0 194 | let g:user_emmet_install_command = 0 195 | let g:user_emmet_mode = 'i' 196 | ` 197 | ) 198 | -------------------------------------------------------------------------------- /internal/plugin/textobj.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinSandWich = ` 6 | [[plugins]] 7 | repo = 'machakann/vim-sandwich' 8 | on_map = { vonx = '(operator-sandwich-' } 9 | hook_add = ''' 10 | let g:sandwich_no_default_key_mappings = 1 11 | let g:operator_sandwich_no_default_key_mappings = 1 12 | let g:textobj_sandwich_no_default_key_mappings = 1 13 | ''' 14 | ` 15 | 16 | DeinTextObj = ` 17 | [[plugins]] 18 | repo = 'kana/vim-operator-user' 19 | 20 | [[plugins]] 21 | repo = 'kana/vim-operator-replace' 22 | on_map = { vnx = '' } 23 | 24 | [[plugins]] 25 | repo = 'kana/vim-textobj-user' 26 | 27 | [[plugins]] 28 | repo = 'terryma/vim-expand-region' 29 | on_map = { x = '' } 30 | 31 | [[plugins]] 32 | repo = 'AndrewRadev/splitjoin.vim' 33 | on_map = { n = 'Splitjoin' } 34 | 35 | [[plugins]] 36 | repo = 'AndrewRadev/dsf.vim' 37 | on_map = { n = 'Dsf' } 38 | hook_add = ''' 39 | let g:dsf_no_mappings = 1 40 | ''' 41 | 42 | [[plugins]] 43 | repo = 'kana/vim-niceblock' 44 | on_map = { x = '' } 45 | hook_add = ''' 46 | let g:niceblock_no_default_key_mappings = 0 47 | ''' 48 | [[plugins]] 49 | repo = 'osyo-manga/vim-textobj-multiblock' 50 | on_map = { ox = '' } 51 | hook_add = ''' 52 | let g:textobj_multiblock_no_default_key_mappings = 1 53 | ''' 54 | 55 | [[plugins]] 56 | repo = 'kana/vim-textobj-function' 57 | on_map = { ox = '' } 58 | hook_add = ''' 59 | let g:textobj_function_no_default_key_mappings = 1 60 | ''' 61 | ` 62 | PlugSandWich = ` 63 | Plug 'machakann/vim-sandwich' 64 | ` 65 | 66 | PlugSandWichSetting = ` 67 | let g:sandwich_no_default_key_mappings = 1 68 | let g:operator_sandwich_no_default_key_mappings = 1 69 | let g:textobj_sandwich_no_default_key_mappings = 1 70 | ` 71 | PlugTextObj = ` 72 | Plug 'kana/vim-operator-user' 73 | Plug 'kana/vim-operator-replace' 74 | Plug 'kana/vim-textobj-user' 75 | Plug 'terryma/vim-expand-region' 76 | Plug 'AndrewRadev/splitjoin.vim' 77 | Plug 'AndrewRadev/dsf.vim' 78 | Plug 'kana/vim-niceblock' 79 | Plug 'osyo-manga/vim-textobj-multiblock' 80 | Plug 'kana/vim-textobj-function' 81 | ` 82 | 83 | PlugTextObjSetting = ` 84 | let g:dsf_no_mappings = 1 85 | let g:niceblock_no_default_key_mappings = 0 86 | let g:textobj_multiblock_no_default_key_mappings = 1 87 | let g:textobj_function_no_default_key_mappings = 1 88 | ` 89 | ) 90 | -------------------------------------------------------------------------------- /internal/plugin/theme.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const Theme = ` 5 | " Theme 6 | 7 | function! theme#theme_init() 8 | " Load cached colorscheme or hybrid by default 9 | let l:default = 'oceanic_material' 10 | let l:cache = s:theme_cache_file() 11 | if ! exists('g:colors_name') 12 | set background=dark 13 | let l:scheme = filereadable(l:cache) ? readfile(l:cache)[0] : l:default 14 | silent! execute 'colorscheme' l:scheme 15 | endif 16 | endfunction 17 | 18 | function! s:theme_autoload() 19 | if exists('g:colors_name') 20 | " Persist theme 21 | call writefile([g:colors_name], s:theme_cache_file()) 22 | endif 23 | endfunction 24 | 25 | function! s:theme_cache_file() 26 | return $DATA_PATH . '/theme.txt' 27 | endfunction 28 | 29 | function! s:theme_cached_scheme(default) 30 | let l:cache_file = s:theme_cache_file() 31 | return filereadable(l:cache_file) ? readfile(l:cache_file)[0] : a:default 32 | endfunction 33 | 34 | function! s:theme_cleanup() 35 | if ! exists('g:colors_name') 36 | return 37 | endif 38 | highlight clear 39 | endfunction 40 | 41 | augroup user_theme 42 | autocmd! 43 | autocmd ColorScheme * call s:theme_autoload() 44 | if has('patch-8.0.1781') || has('nvim-0.3.2') 45 | autocmd ColorSchemePre * call s:theme_cleanup() 46 | endif 47 | augroup END 48 | 49 | ` 50 | -------------------------------------------------------------------------------- /internal/plugin/versioncontrol.go: -------------------------------------------------------------------------------- 1 | // Package plugin provides ... 2 | package plugin 3 | 4 | const ( 5 | DeinVimagt = ` 6 | [[plugins]] 7 | repo = 'jreybert/vimagit' 8 | on_cmd = 'Magit' 9 | hook_source = ''' 10 | autocmd User VimagitEnterCommit startinsert 11 | ''' 12 | ` 13 | DeinCommita = ` 14 | [[plugins]] 15 | repo = 'rhysd/committia.vim' 16 | on_path = [ 'COMMIT_EDITMSG', 'MERGE_MSG' ] 17 | hook_source = ''' 18 | let g:committia_min_window_width = 7 19 | ''' 20 | ` 21 | 22 | DeinFugiTive = ` 23 | [[plugins]] 24 | repo = 'tpope/vim-fugitive' 25 | on_cmd = [ 'G', 'Git', 'Gfetch', 'Gpush', 'Glog', 'Gclog', 'Gdiffsplit' ] 26 | hook_source = ''' 27 | augroup user_fugitive_plugin 28 | autocmd! 29 | autocmd FileType fugitiveblame normal A 30 | augroup END 31 | ''' 32 | ` 33 | 34 | DeinGina = ` 35 | [[plugins]] 36 | repo = 'lambdalisue/gina.vim' 37 | on_cmd = 'Gina' 38 | ` 39 | 40 | PlugVimagit = ` 41 | Plug 'jreybert/vimagit' 42 | ` 43 | 44 | PlugVimagitSetting = ` 45 | autocmd User VimagitEnterCommit startinsert 46 | ` 47 | 48 | PlugCommita = ` 49 | Plug 'rhysd/committia.vim' 50 | ` 51 | 52 | PlugFugTive = ` 53 | Plug 'tpope/vim-fugitive',{'on': [ 'G', 'Git', 'Gfetch', 'Gpush', 'Glog', 'Gclog', 'Gdiffsplit' ]} 54 | ` 55 | 56 | PlugFugTiveSetting = ` 57 | augroup user_fugitive_plugin 58 | autocmd! 59 | autocmd FileType fugitiveblame normal A 60 | augroup END 61 | ` 62 | 63 | PlugGina = ` 64 | Plug 'lambdalisue/gina.vim',{'on': 'Gina'} 65 | ` 66 | 67 | PlugCommitaSetting = ` 68 | let g:committia_min_window_width = 7 69 | ` 70 | ) 71 | -------------------------------------------------------------------------------- /internal/render/dein/dein.go: -------------------------------------------------------------------------------- 1 | // Package render provides ... 2 | package dein 3 | 4 | import ( 5 | "strings" 6 | "sync" 7 | 8 | "github.com/glepnir/jarvim/internal/plugin" 9 | "github.com/glepnir/jarvim/internal/render" 10 | "github.com/glepnir/jarvim/internal/vim" 11 | "github.com/glepnir/jarvim/pkg/color" 12 | "github.com/glepnir/jarvim/template" 13 | ) 14 | 15 | // Dein plugin management 16 | type Dein struct{} 17 | 18 | // Ensure dein struct implement Render interface 19 | var _ render.Render = (*Dein)(nil) 20 | 21 | // GenerateInit generate init.vim 22 | func (d *Dein) GenerateInit() { 23 | render.WithConfirm(true, vim.ConfPath+"/init.vim", "init.vim", plugin.InitVim) 24 | } 25 | 26 | // GenerateCore will generate core/core.vim 27 | func (d *Dein) GenerateCore(LeaderKey, LocalLeaderKey string, leaderkeymap map[string]string) { 28 | render.ParseTemplate(vim.ConfCore+"core.vim", "core/core.vim", plugin.Core, []string{leaderkeymap[LeaderKey], leaderkeymap[LocalLeaderKey]}) 29 | } 30 | 31 | // GeneratePlugMan 32 | func (d *Dein) GeneratePlugMan() { 33 | render.WithConfirm(true, vim.ConfCore+"dein.vim", "dein.vim", plugin.Dein) 34 | } 35 | 36 | // GenerateGeneral will generate core/general.vim 37 | func (d *Dein) GenerateGeneral() { 38 | render.WithConfirm(true, vim.ConfCore+"general.vim", "core/general.vim", plugin.General) 39 | render.WithConfirm(true, vim.ConfCore+"event.vim", "core/event.vim", plugin.Event) 40 | } 41 | 42 | // GenerateAutoloadFunc generate autoload/initself.vim 43 | func (d *Dein) GenerateAutoloadFunc() { 44 | render.WithConfirm(true, vim.ConfAutoload+"initself.vim", "autoload/initself.vim", plugin.AutoloadSourceFile) 45 | render.WithConfirm(true, vim.ConfAutoload+"initself.vim", "autoload/initself.vim", plugin.AutoloadMkdir) 46 | } 47 | 48 | // GenerateTheme will generate autoload/theme.vim 49 | // theme.vim read or write the theme.txt from $CACHE/.vim/theme.txt 50 | func (d *Dein) GenerateTheme() { 51 | render.WithConfirm(true, vim.ConfAutoload+"theme.vim", "autoload/theme.vim", plugin.Theme) 52 | } 53 | 54 | // GenerateCacheTheme write the colorscheme into .cache/vim/theme.txt 55 | func (d *Dein) GenerateCacheTheme(usercolors []string, colorschememap map[string]string) { 56 | colors := colorschememap[usercolors[0]] 57 | render.WriteTemplate(vim.CachePath+"theme.txt", "theme.txt", colors) 58 | } 59 | 60 | // GenerateColorscheme generate modules/appearance.toml 61 | func (d *Dein) GenerateColorscheme(usercolors []string) { 62 | render.ParseTemplate(vim.ConfModules+"appearance.toml", "Colorscheme", plugin.DeinColorscheme, usercolors) 63 | } 64 | 65 | // GenerateDevIcons generate modules/appearance.toml 66 | func (d *Dein) GenerateDevIcons() { 67 | render.WriteTemplate(vim.ConfModules+"appearance.toml", "Vim-Devicons", plugin.DeinDevicons) 68 | } 69 | 70 | // GenerateDashboard generate modules/appearance.toml 71 | func (d *Dein) GenerateDashboard(dashboard bool) { 72 | render.WithConfirm(dashboard, vim.ConfModules+"appearance.toml", "dashboard-nvim", plugin.DeinDashboard) 73 | } 74 | 75 | // GenerateBufferLine 76 | func (d *Dein) GenerateBufferLine(bufferline bool) { 77 | render.WithConfirm(bufferline, vim.ConfModules+"appearance.toml", "Vim-Buffer", plugin.DeinBufferLine) 78 | render.WithConfirm(bufferline, vim.ConfCore+"pmap.vim", "vim-buffer keymap", plugin.BuffetKeyMap) 79 | } 80 | 81 | // GenerateStatusLine 82 | func (d *Dein) GenerateStatusLine(spaceline bool) { 83 | render.WithConfirm(spaceline, vim.ConfModules+"appearance.toml", "Statusline", plugin.DeinStatusline) 84 | } 85 | 86 | // GenerateExplorer 87 | func (d *Dein) GenerateExplorer(explorer string) { 88 | if explorer == "coc-explorer" { 89 | vim.CocExtensions = append(vim.CocExtensions, "coc-explorer") 90 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "coc-explorer keymap", plugin.CocExplorerKeyMap) 91 | } else if explorer == "defx.nvim" { 92 | render.WriteTemplate(vim.ConfModules+"appearance.toml", "Defx.nvim", plugin.DeinDefx) 93 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "defx keymap", plugin.DefxKeyMap) 94 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "defx keymap", plugin.DefxFindKeyMap) 95 | } else { 96 | render.WriteTemplate(vim.ConfModules+"appearance.toml", "Nerdtree", plugin.DeinNerdTree) 97 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "nerdtree keymap", plugin.NerdTreeKeyMap) 98 | } 99 | } 100 | 101 | // GenerateDatabase 102 | func (d *Dein) GenerateDatabase(database bool) { 103 | if database { 104 | render.WriteTemplate(vim.ConfAutoload+"initself.vim", "LoadEnv function", plugin.AutoloadLoadEnv) 105 | render.WriteTemplate(vim.ConfModules+"database.toml", "Database", plugin.DeinDatabase) 106 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "database keymap", plugin.DataBaseKeyMap) 107 | } else { 108 | color.PrintWarn("Skip Generate Datbase") 109 | } 110 | } 111 | 112 | // GenerateFuzzyFind 113 | func (d *Dein) GenerateFuzzyFind(fuzzyfind bool) { 114 | render.WithConfirm(fuzzyfind, vim.ConfModules+"fuzzyfind.toml", "vim-clap", plugin.DeinClap) 115 | render.WithConfirm(fuzzyfind, vim.ConfCore+"pmap.vim", "vim-clap keymap", plugin.ClapKeyMap) 116 | render.WithConfirm(fuzzyfind, vim.ConfCore+"pmap.vim", "coc-clap keymap", plugin.CocClapKeyMap) 117 | } 118 | 119 | // GenerateEditorConfig 120 | func (d *Dein) GenerateEditorConfig(editorconfig bool) { 121 | render.WithConfirm(editorconfig, vim.ConfModules+"program.toml", "editorconfig", plugin.DeinEditorConfig) 122 | } 123 | 124 | // GenerateIndentLine 125 | func (d *Dein) GenerateIndentLine(indentplugin string) { 126 | if indentplugin == "Yggdroot/indentLine" { 127 | render.WriteTemplate(vim.ConfModules+"program.toml", indentplugin, plugin.DeinIndentLine) 128 | } else { 129 | render.WriteTemplate(vim.ConfModules+"program.toml", indentplugin, plugin.DeinIndenGuides) 130 | } 131 | } 132 | 133 | // GenerateComment 134 | func (d *Dein) GenerateComment(comment bool) { 135 | if comment { 136 | render.WriteTemplate(vim.ConfModules+"filetype.toml", "context_filetype.vim", plugin.DeinContextFileType) 137 | render.WriteTemplate(vim.ConfModules+"program.toml", "Caw.vim", plugin.DeinCaw) 138 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "caw.vim keymap", plugin.CawKeyMap) 139 | } else { 140 | color.PrintWarn("Skip generate caw.vim config") 141 | } 142 | } 143 | 144 | // GenerateOutLine 145 | func (d *Dein) GenerateOutLine(outline bool) { 146 | render.WithConfirm(outline, vim.ConfModules+"program.toml", "Vista.vim", plugin.DeinVista) 147 | render.WithConfirm(outline, vim.ConfCore+"pmap.vim", "vista.vim keymap", plugin.VistaKeyMap) 148 | } 149 | 150 | // GenerateTags 151 | func (d *Dein) GenerateTags(tagsplugin bool) { 152 | render.WithConfirm(tagsplugin, vim.ConfModules+"program.toml", "vim-gutentags", plugin.DeinGuTenTags) 153 | } 154 | 155 | // GenerateQuickRun 156 | func (d *Dein) GenerateQuickRun(quickrun bool) { 157 | render.WithConfirm(quickrun, vim.ConfModules+"program.toml", "vim-quickrun", plugin.DeinQuickRun) 158 | render.WithConfirm(quickrun, vim.ConfCore+"pmap.vim", "quickrun keymap", plugin.QuickRunKeyMap) 159 | } 160 | 161 | // GenerateDataTypeFile 162 | func (d *Dein) GenerateDataTypeFile(datafile []string, datafilemap map[string]string) { 163 | for _, f := range datafile { 164 | _, ok := datafilemap[f] 165 | if ok { 166 | render.WriteTemplate(vim.ConfModules+"filetype.toml", f, datafilemap[f]) 167 | } 168 | } 169 | } 170 | 171 | // GenerateEnhanceplugin 172 | func (d *Dein) GenerateEnhanceplugin(plugins []string, enhancepluginmap map[string]string) { 173 | var enhancekeymap = map[string]string{ 174 | "vim-mundo": plugin.MundoKeyMap, 175 | "vim-easymotion": plugin.EasyMotionKeyMap, 176 | "vim-floterm": plugin.FloatermKeyMap, 177 | } 178 | render.WriteTemplate(vim.ConfModules+"enhance.toml", "dein.vim", plugin.DeinDein) 179 | for _, v := range plugins { 180 | pluginname := strings.Split(v, " ")[0] 181 | i, ok := enhancepluginmap[v] 182 | if ok { 183 | render.WriteTemplate(vim.ConfModules+"enhance.toml", pluginname, i) 184 | } 185 | j, ok := enhancekeymap[pluginname] 186 | if ok { 187 | render.WriteTemplate(vim.ConfCore+"pmap.vim", pluginname+"keymap", j) 188 | } 189 | } 190 | } 191 | 192 | // GenerateSandWich 193 | func (d *Dein) GenerateSandWich(sandwich bool) { 194 | render.WithConfirm(sandwich, vim.ConfModules+"textobj.toml", "vim-sandwich", plugin.DeinSandWich) 195 | render.WithConfirm(sandwich, vim.ConfCore+"pmap.vim", "vim-sandwich keymap", plugin.SandWichKeyMap) 196 | } 197 | 198 | // GenerateTextObj 199 | func (d *Dein) GenerateTextObj() { 200 | render.WithConfirm(true, vim.ConfModules+"textobj.toml", "textobj plugins", plugin.DeinTextObj) 201 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.NiceBlockKeyMap) 202 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.VimExpandRegionKeyMap) 203 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.DsfKeyMap) 204 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.SplitJoinKeyMap) 205 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.OperatorReplaceKeyMap) 206 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.MultiBlockKeyMap) 207 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "textobj vim", plugin.TextObjFunctionKeyMap) 208 | } 209 | 210 | // GenerateVersionControl 211 | func (d *Dein) GenerateVersionControl(userversion []string, versionmap map[string]string) { 212 | versionkeymap := map[string]string{ 213 | "jreybert/vimagit": plugin.VimagitKeyMap, 214 | "tpope/vim-fugitive": plugin.FugiTiveKeyMap, 215 | } 216 | 217 | for i, v := range userversion { 218 | _, ok := versionmap[v] 219 | if ok { 220 | render.WriteTemplate(vim.ConfModules+"version.toml", userversion[i], versionmap[v]) 221 | } 222 | _, ok = versionkeymap[v] 223 | if ok { 224 | render.WriteTemplate(vim.ConfCore+"pmap.vim", v+"keymap", versionkeymap[v]) 225 | } 226 | } 227 | render.WriteTemplate(vim.ConfModules+"version.toml", "committia.vim", plugin.DeinCommita) 228 | } 229 | 230 | // GeneratePluginFolder 231 | func (d *Dein) GeneratePluginFolder() { 232 | render.WriteTemplate(vim.ConfPlugin+"bufkill.vim", "bufkill.vim", template.Bufkill) 233 | render.WriteTemplate(vim.ConfPlugin+"difftools.vim", "difftools.vim", template.Difftools) 234 | render.WriteTemplate(vim.ConfPlugin+"hlsearch.vim", "hlsearch.vim", template.Hlsearchvim) 235 | render.WriteTemplate(vim.ConfPlugin+"nicefold.vim", "nicefold.vim", template.Nicefold) 236 | render.WriteTemplate(vim.ConfPlugin+"whitespace.vim", "whitespace.vim", template.Whitespace) 237 | color.PrintSuccess("Generate plugin folder success") 238 | 239 | } 240 | 241 | // GenerateLanguagePlugin 242 | func (d *Dein) GenerateLanguagePlugin(UserLanguages []string, LanguagesPluginMap map[string]string) { 243 | extensionmap := map[string]interface{}{ 244 | plugin.DeinR: plugin.DeinRExtension, 245 | plugin.DeinVue: plugin.DeinVueExtension, 246 | plugin.DeinRust: plugin.DeinRustExtension, 247 | plugin.DeinRuby: plugin.DeinRubyExtension, 248 | plugin.DeinScala: plugin.DeinScalaExtension, 249 | plugin.DeinPython: plugin.DeinPythonExtension, 250 | plugin.DeinHtml: plugin.DeinHtmlExtension, 251 | plugin.DeinCss: plugin.DeinCssExtension, 252 | plugin.DeinJavascript: plugin.JsTsExtensions, 253 | plugin.DeinTypescript: plugin.JsTsExtensions, 254 | plugin.DeinReact: plugin.ReactExtensions, 255 | } 256 | var once sync.Once 257 | needemmet := []string{"React", "Vue", "Html"} 258 | for i, k := range UserLanguages { 259 | v, ok := LanguagesPluginMap[k] 260 | if ok { 261 | render.WriteTemplate(vim.ConfModules+"languages.toml", UserLanguages[i], v) 262 | } 263 | extensions, ok := extensionmap[v] 264 | if ok { 265 | switch item := extensions.(type) { 266 | case string: 267 | vim.CocExtensions = append(vim.CocExtensions, item) 268 | case []string: 269 | if k == "Typescript" || k == "Javascript" { 270 | once.Do(func() { 271 | vim.CocExtensions = append(vim.CocExtensions, item...) 272 | }) 273 | } else { 274 | vim.CocExtensions = append(vim.CocExtensions, item...) 275 | } 276 | } 277 | } 278 | for _, j := range needemmet { 279 | if j == k { 280 | once.Do(func() { 281 | render.WriteTemplate(vim.ConfModules+"program.toml", "emmet plugins", plugin.DeinEmmet) 282 | }) 283 | } 284 | } 285 | } 286 | render.WriteTemplate(vim.ConfAutoload+"initself.vim", "autoload coc function", plugin.AutoloadCoc) 287 | render.ParseTemplate(vim.ConfModules+"completion.toml", "coc.nvim", plugin.DeinCoC, vim.CocExtensions) 288 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "coc.nvim keymap", plugin.CocKeyMap) 289 | } 290 | 291 | // GenerateCocJson 292 | func (d *Dein) GenerateCocJson() { 293 | render.WriteTemplate(vim.ConfPath+"/coc-settings.json", "coc-settings.json file", plugin.CocJson) 294 | } 295 | 296 | // GenerateVimMap 297 | func (d *Dein) GenerateVimMap() { 298 | render.WriteTemplate(vim.ConfCore+"vmap.vim", "vim map", plugin.VimKeyMap) 299 | } 300 | 301 | // GenerateInstallScripts 302 | func (d *Dein) GenerateInstallScripts() { 303 | render.WriteTemplate(vim.ConfPath+"/Makefile", "Makefile", plugin.DeinMakeFile) 304 | render.WriteTemplate(vim.ConfPath+"/install.sh", "install.sh", plugin.DeinInstallShell) 305 | } 306 | -------------------------------------------------------------------------------- /internal/render/render.go: -------------------------------------------------------------------------------- 1 | // Package render provides ... 2 | package render 3 | 4 | import ( 5 | "fmt" 6 | "os" 7 | "text/template" 8 | 9 | "github.com/glepnir/jarvim/internal/vim" 10 | "github.com/glepnir/jarvim/pkg/color" 11 | ) 12 | 13 | // Render interface 14 | type Render interface { 15 | GenerateInit() 16 | GenerateCore(Leader, LocalLeaderKey string, leaderkeymap map[string]string) 17 | GeneratePlugMan() 18 | GenerateGeneral() 19 | GenerateAutoloadFunc() 20 | GenerateTheme() 21 | GenerateCacheTheme(usercolors []string, colorschememap map[string]string) 22 | GenerateColorscheme(colorschemes []string) 23 | GenerateDevIcons() 24 | GenerateDashboard(dashboard bool) 25 | GenerateBufferLine(bufferline bool) 26 | GenerateStatusLine(statusline bool) 27 | GenerateExplorer(explorer string) 28 | GenerateDatabase(database bool) 29 | GenerateFuzzyFind(fuzzfind bool) 30 | GenerateEditorConfig(editorconfig bool) 31 | GenerateIndentLine(indentplugin string) 32 | GenerateComment(comment bool) 33 | GenerateOutLine(outline bool) 34 | GenerateTags(tagsplugin bool) 35 | GenerateQuickRun(quickrun bool) 36 | GenerateDataTypeFile(datafile []string, datafilemap map[string]string) 37 | GenerateEnhanceplugin(plugins []string, enhancepluginmap map[string]string) 38 | GenerateSandWich(sandwich bool) 39 | GenerateTextObj() 40 | GenerateVersionControl(userversion []string, versionmap map[string]string) 41 | GeneratePluginFolder() 42 | GenerateLanguagePlugin(UserLanguages []string, LanguagesPluginMap map[string]string) 43 | GenerateCocJson() 44 | GenerateVimMap() 45 | GenerateInstallScripts() 46 | } 47 | 48 | // RollBack will remove the config folder when 49 | // some errors disappear 50 | func RollBack(err error) { 51 | color.PrintError(err.Error()) 52 | color.PrintWarn("Rolling back...") 53 | os.RemoveAll(vim.ConfPath) 54 | os.Exit(0) 55 | } 56 | 57 | // ParseTemplate 58 | func ParseTemplate(targetfile, name string, plugintemplate string, data interface{}) { 59 | f, err := os.OpenFile(targetfile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) 60 | defer f.Close() 61 | if err != nil { 62 | RollBack(err) 63 | } 64 | tpl := template.Must(template.New("").Parse(plugintemplate)) 65 | err = tpl.Execute(f, data) 66 | if err != nil { 67 | RollBack(err) 68 | } 69 | color.PrintSuccess(fmt.Sprintf("Generate %v success", name)) 70 | } 71 | 72 | // WriteTemplate 73 | func WriteTemplate(targetfile string, name, plugintemplate string) { 74 | f, err := os.OpenFile(targetfile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) 75 | defer f.Close() 76 | if err != nil { 77 | RollBack(err) 78 | } 79 | _, err = f.WriteString(plugintemplate) 80 | if err != nil { 81 | RollBack(err) 82 | } 83 | color.PrintSuccess(fmt.Sprintf("Generate %v success", name)) 84 | } 85 | 86 | // WithConfirm 87 | func WithConfirm(confirm bool, targetfile, name, plugintemplate string) { 88 | if confirm { 89 | WriteTemplate(targetfile, name, plugintemplate) 90 | return 91 | } 92 | color.PrintWarn(fmt.Sprintf("Skip generate %v cofnig", name)) 93 | } 94 | -------------------------------------------------------------------------------- /internal/render/vimplug/vimplug.go: -------------------------------------------------------------------------------- 1 | // Package plug provides ... 2 | package vimplug 3 | 4 | import ( 5 | "os" 6 | "strings" 7 | "sync" 8 | 9 | "github.com/glepnir/jarvim/internal/plugin" 10 | "github.com/glepnir/jarvim/internal/render" 11 | "github.com/glepnir/jarvim/internal/vim" 12 | "github.com/glepnir/jarvim/pkg/color" 13 | "github.com/glepnir/jarvim/template" 14 | ) 15 | 16 | // VimPlug struct 17 | type VimPlug struct{} 18 | 19 | // Ensure VimPlug struct implement Render interface 20 | var _ render.Render = (*VimPlug)(nil) 21 | 22 | // GenerateInit generate init.vim 23 | func (v *VimPlug) GenerateInit() { 24 | render.WithConfirm(true, vim.ConfPath+"/init.vim", "init.vim", plugin.InitVim) 25 | os.MkdirAll(vim.ConfModules+"appearance", 0700) 26 | os.MkdirAll(vim.ConfModules+"program", 0700) 27 | os.MkdirAll(vim.ConfModules+"enhance", 0700) 28 | os.MkdirAll(vim.ConfModules+"textobj", 0700) 29 | os.MkdirAll(vim.ConfModules+"filetype", 0700) 30 | os.MkdirAll(vim.ConfModules+"languages", 0700) 31 | os.MkdirAll(vim.ConfModules+"fuzzyfind", 0700) 32 | os.MkdirAll(vim.ConfModules+"version", 0700) 33 | os.MkdirAll(vim.ConfModules+"completion", 0700) 34 | } 35 | 36 | // GenerateCore will generate core/core.vim 37 | func (v *VimPlug) GenerateCore(LeaderKey, LocalLeaderKey string, leaderkeymap map[string]string) { 38 | render.ParseTemplate(vim.ConfCore+"core.vim", "core/core.vim", plugin.PlugCore, []string{leaderkeymap[LeaderKey], leaderkeymap[LocalLeaderKey]}) 39 | } 40 | 41 | // GeneratePlugMan 42 | func (v *VimPlug) GeneratePlugMan() { 43 | render.WithConfirm(true, vim.ConfCore+"plug.vim", "plug.vim", plugin.VimPlug) 44 | } 45 | 46 | // GenerateGeneral will generate core/general.vim 47 | func (v *VimPlug) GenerateGeneral() { 48 | render.WithConfirm(true, vim.ConfCore+"general.vim", "core/general.vim", plugin.General) 49 | render.WithConfirm(true, vim.ConfCore+"event.vim", "core/event.vim", plugin.Event) 50 | } 51 | 52 | // GenerateAutoloadFunc generate autoload/initself.vim 53 | func (v *VimPlug) GenerateAutoloadFunc() { 54 | render.WithConfirm(true, vim.ConfAutoload+"initself.vim", "autoload/initself.vim", plugin.AutoloadSourceFile) 55 | render.WithConfirm(true, vim.ConfAutoload+"initself.vim", "autoload/initself.vim", plugin.AutoloadMkdir) 56 | } 57 | 58 | // GenerateTheme will generate autoload/theme.vim 59 | // theme.vim read or write the theme.txt from $CACHE/.vim/theme.txt 60 | func (v *VimPlug) GenerateTheme() { 61 | render.WithConfirm(true, vim.ConfAutoload+"theme.vim", "autoload/theme.vim", plugin.Theme) 62 | } 63 | 64 | // GenerateCacheTheme write the colorscheme into .cache/vim/theme.txt 65 | func (v *VimPlug) GenerateCacheTheme(usercolors []string, colorschememap map[string]string) { 66 | colors := colorschememap[usercolors[0]] 67 | render.WriteTemplate(vim.CachePath+"theme.txt", "theme.txt", colors) 68 | } 69 | 70 | // GenerateColorscheme generate modules/appearance.toml 71 | func (v *VimPlug) GenerateColorscheme(usercolors []string) { 72 | render.ParseTemplate(vim.ConfModules+"appearance/plugins.vim", "Colorscheme", plugin.PlugColorscheme, usercolors) 73 | } 74 | 75 | // GenerateDevIcons 76 | func (v *VimPlug) GenerateDevIcons() { 77 | render.WriteTemplate(vim.ConfModules+"appearance/plugins.vim", "Vim-Devicons", plugin.PlugDevicons) 78 | } 79 | 80 | // GenerateDashboard 81 | func (v *VimPlug) GenerateDashboard(dashboard bool) { 82 | render.WithConfirm(dashboard, vim.ConfModules+"appearance/plugins.vim", "dashboard-nvim", plugin.PlugDashboard) 83 | } 84 | 85 | // GenerateBufferLine 86 | func (v *VimPlug) GenerateBufferLine(bufferline bool) { 87 | render.WithConfirm(bufferline, vim.ConfModules+"appearance/plugins.vim", "Vim-Buffer", plugin.PlugBufferLine) 88 | render.WithConfirm(bufferline, vim.ConfModules+"appearance/config.vim", "vim-buffer keymap", plugin.BuffetKeyMap) 89 | } 90 | 91 | // GenerateStatusLine 92 | func (v *VimPlug) GenerateStatusLine(spaceline bool) { 93 | render.WithConfirm(spaceline, vim.ConfModules+"appearance/plugins.vim", "spacelinev.vim", plugin.PlugStatusline) 94 | render.WithConfirm(spaceline, vim.ConfModules+"appearance/config.vim", "spacelinev.vim", plugin.PlugStatuslineSetting) 95 | } 96 | 97 | // GenerateExplorer 98 | func (v *VimPlug) GenerateExplorer(explorer string) { 99 | if explorer == "coc-explorer" { 100 | plugin.PlugCocExplorer = true 101 | render.WriteTemplate(vim.ConfCore+"pmap.vim", "coc-explorer keymap", plugin.CocExplorerKeyMap) 102 | } else if explorer == "defx.nvim" { 103 | render.WriteTemplate(vim.ConfModules+"appearance/plugins.vim", "Defx.nvim", plugin.PlugDefx) 104 | render.WriteTemplate(vim.ConfModules+"appearance/config.vim", "defx settings", plugin.PlugDefxSetting) 105 | render.WriteTemplate(vim.ConfModules+"appearance/config.vim", "defx keymap", plugin.DefxKeyMap) 106 | render.WriteTemplate(vim.ConfModules+"appearance/config.vim", "defx keymap", plugin.DefxFindKeyMap) 107 | } else { 108 | render.WriteTemplate(vim.ConfModules+"appearance/plugins.vim", "Nerdtree", plugin.PlugNerdTree) 109 | render.WriteTemplate(vim.ConfModules+"appearance/config.vim", "nerdtree config", plugin.PlugNerdTreeSetting) 110 | render.WriteTemplate(vim.ConfModules+"appearance/config.vim", "nerdtree keymap", plugin.NerdTreeKeyMap) 111 | } 112 | } 113 | 114 | // GenerateDatabase 115 | func (v *VimPlug) GenerateDatabase(database bool) { 116 | if database { 117 | render.WriteTemplate(vim.ConfAutoload+"initself.vim", "LoadEnv function", plugin.AutoloadLoadEnv) 118 | render.WriteTemplate(vim.ConfModules+"program/plugins.vim", "Database", plugin.PlugDatabase) 119 | render.WriteTemplate(vim.ConfModules+"program/config.vim", "database settings", plugin.PlugDatabaseUiSetting) 120 | render.WriteTemplate(vim.ConfModules+"program/config.vim", "database keymap", plugin.DataBaseKeyMap) 121 | } else { 122 | color.PrintWarn("Skip Generate Datbase") 123 | } 124 | } 125 | 126 | // GenerateFuzzyFind 127 | func (v *VimPlug) GenerateFuzzyFind(fuzzyfind bool) { 128 | render.WithConfirm(fuzzyfind, vim.ConfModules+"fuzzyfind/plugins.vim", "vim-clap", plugin.PlugClap) 129 | render.WithConfirm(fuzzyfind, vim.ConfModules+"fuzzyfind/config.vim", "vim-clap setting", plugin.PlugClapSetting) 130 | render.WithConfirm(fuzzyfind, vim.ConfModules+"fuzzyfind/config.vim", "vim-clap keymap", plugin.ClapKeyMap) 131 | render.WithConfirm(fuzzyfind, vim.ConfModules+"fuzzyfind/config.vim", "coc-clap keymap", plugin.CocClapKeyMap) 132 | } 133 | 134 | // GenerateIndentLine 135 | func (v *VimPlug) GenerateIndentLine(indentplugin string) { 136 | if indentplugin == "Yggdroot/indentLine" { 137 | render.WriteTemplate(vim.ConfModules+"program/plugins.vim", indentplugin, plugin.PlugIndentLine) 138 | render.WriteTemplate(vim.ConfModules+"program/config.vim", indentplugin, plugin.PlugIndentLineSetting) 139 | } else { 140 | render.WriteTemplate(vim.ConfModules+"program/plugins.vim", indentplugin, plugin.PlugIndentGuides) 141 | render.WriteTemplate(vim.ConfModules+"program/config.vim", indentplugin, plugin.PlugIndentGuidesSetting) 142 | } 143 | } 144 | 145 | // GenerateComment 146 | func (v *VimPlug) GenerateComment(comment bool) { 147 | if comment { 148 | render.WriteTemplate(vim.ConfModules+"filetype/plugins.vim", "context_filetype.vim", plugin.PlugContextFileType) 149 | render.WriteTemplate(vim.ConfModules+"program/plugins.vim", "Caw.vim", plugin.PlugCawvim) 150 | } else { 151 | color.PrintWarn("Skip generate caw.vim config") 152 | } 153 | } 154 | 155 | // GenerateOutLine 156 | func (v *VimPlug) GenerateOutLine(outline bool) { 157 | render.WithConfirm(outline, vim.ConfModules+"program/plugins.vim", "Vista.vim", plugin.PlugVista) 158 | render.WithConfirm(outline, vim.ConfModules+"program/config.vim", "Vista.vim", plugin.PlugVistaSetting) 159 | render.WithConfirm(outline, vim.ConfModules+"program/config.vim", "vista.vim keymap", plugin.VistaKeyMap) 160 | } 161 | 162 | // GenerateTags 163 | func (v *VimPlug) GenerateTags(tagsplugin bool) { 164 | render.WithConfirm(tagsplugin, vim.ConfModules+"program/plugins.vim", "vim-gutentags", plugin.PlugGuTenTags) 165 | render.WithConfirm(tagsplugin, vim.ConfModules+"program/config.vim", "vim-gutentags", plugin.PlugGuTenTagsSetting) 166 | } 167 | 168 | // GenerateQuickRun 169 | func (v *VimPlug) GenerateQuickRun(quickrun bool) { 170 | render.WithConfirm(quickrun, vim.ConfModules+"program/plugins.vim", "vim-quickrun", plugin.PlugQuickRun) 171 | render.WithConfirm(quickrun, vim.ConfModules+"program/config.vim", "vim-quickrun", plugin.PlugQuickRunSetting) 172 | render.WithConfirm(quickrun, vim.ConfModules+"program/config.vim", "quickrun keymap", plugin.QuickRunKeyMap) 173 | } 174 | 175 | // GenerateEditorConfig 176 | func (v *VimPlug) GenerateEditorConfig(editorconfig bool) { 177 | render.WithConfirm(editorconfig, vim.ConfModules+"program/plugins.vim", "editorconfig", plugin.PlugEditorConfig) 178 | } 179 | 180 | // GenerateDataTypeFile 181 | func (v *VimPlug) GenerateDataTypeFile(datafile []string, datafilemap map[string]string) { 182 | for _, f := range datafile { 183 | _, ok := datafilemap[f] 184 | if ok { 185 | render.WriteTemplate(vim.ConfModules+"filetype/plugins.vim", f, datafilemap[f]) 186 | } 187 | if f == "MarkDown" { 188 | render.WriteTemplate(vim.ConfModules+"filetype/config.vim", "Markdwon settings", plugin.PlugMarkDownSetting) 189 | } 190 | } 191 | } 192 | 193 | // GenerateEnhanceplugin 194 | func (v *VimPlug) GenerateEnhanceplugin(plugins []string, enhancepluginmap map[string]string) { 195 | var enhancekeymap = map[string]string{ 196 | "vim-mundo": plugin.MundoKeyMap, 197 | "vim-easymotion": plugin.EasyMotionKeyMap, 198 | "vim-floterm": plugin.FloatermKeyMap, 199 | } 200 | var enhancesetting = map[string]string{ 201 | "vim-floaterm": plugin.PlugFloatermSetting, 202 | "rainbow": plugin.PlugRainbowSetting, 203 | "vim-easymotion": plugin.PlugEasyMotionSetting, 204 | "accelerated-jk": plugin.PlugFastJKSetting, 205 | } 206 | for _, v := range plugins { 207 | pluginname := strings.Split(v, " ")[0] 208 | i, ok := enhancepluginmap[v] 209 | if ok { 210 | render.WriteTemplate(vim.ConfModules+"enhance/plugins.vim", pluginname, i) 211 | } 212 | k, ok := enhancesetting[pluginname] 213 | if ok { 214 | render.WriteTemplate(vim.ConfModules+"enhance/config.vim", pluginname, k) 215 | } 216 | j, ok := enhancekeymap[pluginname] 217 | if ok { 218 | render.WriteTemplate(vim.ConfModules+"enhance/config.vim", pluginname+"keymap", j) 219 | } 220 | } 221 | } 222 | 223 | // GenerateSandWich 224 | func (v *VimPlug) GenerateSandWich(sandwich bool) { 225 | render.WithConfirm(sandwich, vim.ConfModules+"textobj/plugins.vim", "vim-sandwich", plugin.PlugSandWich) 226 | render.WithConfirm(sandwich, vim.ConfModules+"textobj/config.vim", "vim-sandwich", plugin.PlugSandWichSetting) 227 | } 228 | 229 | // GenerateTextObj 230 | func (v *VimPlug) GenerateTextObj() { 231 | render.WithConfirm(true, vim.ConfModules+"textobj/plugins.vim", "textobj plugins", plugin.PlugTextObj) 232 | render.WithConfirm(true, vim.ConfModules+"textobj/config.vim", "textobj plugins setting", plugin.PlugTextObjSetting) 233 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.NiceBlockKeyMap) 234 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.VimExpandRegionKeyMap) 235 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.DsfKeyMap) 236 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.SplitJoinKeyMap) 237 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.OperatorReplaceKeyMap) 238 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.MultiBlockKeyMap) 239 | render.WriteTemplate(vim.ConfModules+"textobj/config.vim", "textobj vim keymap", plugin.TextObjFunctionKeyMap) 240 | } 241 | 242 | // GenerateVersionControl 243 | func (v *VimPlug) GenerateVersionControl(userversion []string, versionmap map[string]string) { 244 | versionkeymap := map[string]string{ 245 | "jreybert/vimagit": plugin.VimagitKeyMap, 246 | "tpope/vim-fugitive": plugin.FugiTiveKeyMap, 247 | } 248 | 249 | for i, v := range userversion { 250 | _, ok := versionmap[v] 251 | if ok { 252 | render.WriteTemplate(vim.ConfModules+"version/plugins.vim", userversion[i], versionmap[v]) 253 | if v == "vim-fugitive" { 254 | render.WriteTemplate(vim.ConfModules+"version/config.vim", "vim-fugtive setting", plugin.PlugFugTiveSetting) 255 | } else { 256 | render.WriteTemplate(vim.ConfModules+"version/config.vim", "vim-fugtive setting", plugin.PlugVimagitSetting) 257 | } 258 | } 259 | _, ok = versionkeymap[v] 260 | if ok { 261 | render.WriteTemplate(vim.ConfModules+"version/config.vim", v+"keymap", versionkeymap[v]) 262 | } 263 | } 264 | render.WriteTemplate(vim.ConfModules+"version/plugins.vim", "committia.vim", plugin.PlugCommita) 265 | render.WriteTemplate(vim.ConfModules+"version/plugins.vim", "committia.vim", plugin.PlugCommitaSetting) 266 | 267 | } 268 | 269 | // GeneratePluginFolder 270 | func (v *VimPlug) GeneratePluginFolder() { 271 | render.WriteTemplate(vim.ConfPlugin+"bufkill.vim", "bufkill.vim", template.Bufkill) 272 | render.WriteTemplate(vim.ConfPlugin+"difftools.vim", "difftools.vim", template.Difftools) 273 | render.WriteTemplate(vim.ConfPlugin+"hlsearch.vim", "hlsearch.vim", template.Hlsearchvim) 274 | render.WriteTemplate(vim.ConfPlugin+"nicefold.vim", "nicefold.vim", template.Nicefold) 275 | render.WriteTemplate(vim.ConfPlugin+"whitespace.vim", "whitespace.vim", template.Whitespace) 276 | color.PrintSuccess("Generate plugin folder success") 277 | } 278 | 279 | // GenerateLanguagePlugin 280 | func (v *VimPlug) GenerateLanguagePlugin(UserLanguages []string, LanguagesPluginMap map[string]string) { 281 | pluglsp := map[string]string{ 282 | plugin.PlugCFamily: plugin.PlugCFamilyLsp, 283 | plugin.PlugR: plugin.PlugRLsp, 284 | plugin.PlugJavascript: plugin.PlugJavascriptLsp, 285 | plugin.PlugTypescript: plugin.PlugTypescriptLsp, 286 | plugin.PlugDart: plugin.PlugDartLsp, 287 | plugin.PlugVue: plugin.PlugVueLsp, 288 | plugin.PlugGo: plugin.PlugGoLsp, 289 | plugin.PlugRust: plugin.PlugRustLsp, 290 | plugin.PlugHaskell: plugin.PlugHaskellLsp, 291 | plugin.PlugPhp: plugin.PlugPhpLsp, 292 | plugin.PlugRuby: plugin.PlugRubyLsp, 293 | plugin.PlugScala: plugin.PlugScalaLsp, 294 | plugin.PlugShell: plugin.PlugShellLsp, 295 | plugin.PlugLua: plugin.PlugLuaLsp, 296 | plugin.PlugPython: plugin.PlugPythonLsp, 297 | plugin.PlugHtml: plugin.PlugHtmlLsp, 298 | plugin.PlugCss: plugin.PlugCssLsp, 299 | plugin.PlugReact: plugin.PlugReactLsp, 300 | } 301 | 302 | var once sync.Once 303 | needemmet := []string{"React", "Vue", "Html"} 304 | data := []interface{}{plugin.DeinCoC, plugin.PlugCocExplorer} 305 | for i, k := range UserLanguages { 306 | v, ok := LanguagesPluginMap[k] 307 | if ok { 308 | render.WriteTemplate(vim.ConfModules+"languages/plugins.vim", UserLanguages[i], v) 309 | } 310 | l, ok := pluglsp[v] 311 | if ok { 312 | if k == "Typescript" || k == "Javascript" { 313 | once.Do(func() { 314 | render.WriteTemplate(vim.ConfModules+"languages/config.vim", "Js Ts lsp setting", plugin.PlugTypescriptLsp) 315 | }) 316 | 317 | } else { 318 | render.WriteTemplate(vim.ConfModules+"languages/config.vim", UserLanguages[i]+"lsp setting", l) 319 | } 320 | } 321 | for _, j := range needemmet { 322 | once.Do(func() { 323 | if j == k { 324 | render.WriteTemplate(vim.ConfModules+"program/plugins.vim", "emmet plugins", plugin.PlugEmmet) 325 | render.WriteTemplate(vim.ConfModules+"program/config.vim", "emmet plugins setting", plugin.PlugEmmetSetting) 326 | } 327 | }) 328 | } 329 | } 330 | render.WriteTemplate(vim.ConfAutoload+"initself.vim", "autoload coc function", plugin.AutoloadCoc) 331 | render.WriteTemplate(vim.ConfModules+"completion/plugins.vim", "completion plugins", plugin.PlugCoc) 332 | render.ParseTemplate(vim.ConfModules+"completion/config.vim", "coc.nvim", plugin.PlugCocSetting, data) 333 | render.WriteTemplate(vim.ConfModules+"completion/config.vim", "coc.nvim keymap", plugin.CocKeyMap) 334 | } 335 | 336 | // GenerateCocJson 337 | func (v *VimPlug) GenerateCocJson() { 338 | render.WriteTemplate(vim.ConfPath+"/coc-settings.json", "coc-settings.json file", plugin.CocJson) 339 | } 340 | 341 | // GenerateVimMap 342 | func (v *VimPlug) GenerateVimMap() { 343 | render.WriteTemplate(vim.ConfCore+"vmap.vim", "vim map", plugin.VimKeyMap) 344 | } 345 | 346 | // GenerateInstallScripts 347 | func (v *VimPlug) GenerateInstallScripts() { 348 | render.WriteTemplate(vim.ConfPath+"/Makefile", "Makefile", plugin.PlugMakefile) 349 | render.WriteTemplate(vim.ConfPath+"/install.sh", "install.sh", plugin.PlugInstallShell) 350 | } 351 | -------------------------------------------------------------------------------- /internal/vim/vim.go: -------------------------------------------------------------------------------- 1 | // Package vim provides ... 2 | package vim 3 | 4 | import ( 5 | "os" 6 | ) 7 | 8 | var ( 9 | ConfPath = os.ExpandEnv("$HOME/.config/nvim") 10 | CachePath = os.ExpandEnv("$HOME/.cache/vim/") 11 | ConfCore = ConfPath + "/core/" 12 | ConfAutoload = ConfPath + "/autoload/" 13 | ConfModules = ConfPath + "/modules/" 14 | ConfPlugin = ConfPath + "/plugin/" 15 | PluginManage string 16 | Leaderkey string 17 | LocalLeaderKey string 18 | Colorscheme []string 19 | StartScreenPlugin bool 20 | StatusLine bool 21 | BufferLine bool 22 | Explorer string 23 | Database bool 24 | Fuzzyfind bool 25 | EditorConfig bool 26 | IndentPlugin string 27 | CommentPlugin bool 28 | OutLinePlugin bool 29 | TagsPlugin bool 30 | QuickRun bool 31 | DataTypeFile []string 32 | EnhancePlugins []string 33 | SandwichPlugin bool 34 | VersionControlPlugin []string 35 | UserLanguages []string 36 | CocExtensions = make([]string, 0) 37 | 38 | LeaderKeyMap = map[string]string{ 39 | "Space": "\\", 40 | "Comma(,)": ",", 41 | "Semicolon(;)": ";", 42 | } 43 | 44 | ColorschemeMap = map[string]string{ 45 | "glepnir/oceanic-material": "oceanic_materail", 46 | "drewtempelmeyer/palenight.vim": "palenight", 47 | "gruvbox-community/gruvbox": "gruvbox", 48 | "ayu-theme/ayu-vim": "ayu", 49 | "NLKNguyen/papercolor-theme": "PaperColor", 50 | "lifepillar/vim-gruvbox8": "gruvbox8", 51 | "lifepillar/vim-solarized8": "solarized8", 52 | "joshdick/onedark.vim": "onedark", 53 | "arcticicestudio/nord-vim": "nord", 54 | "rakr/vim-one": "one", 55 | "mhartington/oceanic-next": "OceanicNext", 56 | "dracula/vim": "dracula", 57 | "chriskempson/base16-vim": "base16-default-dark", 58 | "kristijanhusak/vim-hybrid-material": "hybrid_material", 59 | "nanotech/jellybeans.vim": "jellybeans", 60 | } 61 | ) 62 | -------------------------------------------------------------------------------- /pkg/cli/cli.go: -------------------------------------------------------------------------------- 1 | // Package cli provides ... 2 | package cli 3 | 4 | import ( 5 | "fmt" 6 | "os" 7 | 8 | "github.com/AlecAivazis/survey/v2" 9 | "github.com/AlecAivazis/survey/v2/terminal" 10 | ) 11 | 12 | func ConfirmTemplate(message string) bool { 13 | confirm := false 14 | prompt := &survey.Confirm{ 15 | Message: message, 16 | } 17 | err := survey.AskOne(prompt, &confirm) 18 | if err == terminal.InterruptErr { 19 | fmt.Println("interrupted") 20 | os.Exit(0) 21 | } else if err != nil { 22 | panic(err) 23 | } 24 | return confirm 25 | } 26 | 27 | func MultiSelectTemplate(questionname, message string, options []string, pagesize int) []string { 28 | answers := []string{} 29 | var question = []*survey.Question{ 30 | { 31 | Name: questionname, 32 | Prompt: &survey.MultiSelect{ 33 | Message: message, 34 | Options: options, 35 | }, 36 | }, 37 | } 38 | err := survey.Ask(question, &answers, survey.WithIcons(func(icons *survey.IconSet) { 39 | icons.UnmarkedOption.Text = "○" 40 | icons.MarkedOption.Text = "◉" 41 | }), survey.WithPageSize(pagesize)) 42 | if err == terminal.InterruptErr { 43 | fmt.Println("interrupted") 44 | os.Exit(0) 45 | } else if err != nil { 46 | panic(err) 47 | } 48 | return answers 49 | } 50 | 51 | func SingleSelectTemplate(message string, options []string) string { 52 | var answer string 53 | prompt := &survey.Select{ 54 | Message: message, 55 | Options: options, 56 | } 57 | err := survey.AskOne(prompt, &answer) 58 | if err == terminal.InterruptErr { 59 | fmt.Println("interrupted") 60 | os.Exit(0) 61 | } else if err != nil { 62 | panic(err) 63 | } 64 | return answer 65 | } 66 | -------------------------------------------------------------------------------- /pkg/color/color.go: -------------------------------------------------------------------------------- 1 | package color 2 | 3 | import "fmt" 4 | 5 | var ( 6 | Reset = "\033[0m" 7 | Red = "\033[31m" 8 | Green = "\033[32m" 9 | Yellow = "\033[33m" 10 | Blue = "\033[34m" 11 | Purple = "\033[35m" 12 | Cyan = "\033[36m" 13 | Gray = "\033[37m" 14 | White = "\033[97m" 15 | ) 16 | 17 | // PrintError Message use red color 18 | func PrintError(message string) { 19 | fmt.Println(Red + "✘ " + message + Reset) 20 | } 21 | 22 | // PrintWarn Message use yellow color 23 | func PrintWarn(message string) { 24 | fmt.Println(Yellow + "⚠ " + message + Reset) 25 | } 26 | 27 | // PrintSuccess Message use green color 28 | func PrintSuccess(message string) { 29 | fmt.Println(Green + "✔ " + message + Reset) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/util/util.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "io/ioutil" 7 | "os" 8 | "path/filepath" 9 | 10 | "github.com/glepnir/jarvim/pkg/color" 11 | ) 12 | 13 | // Exist to check the file or folder exists 14 | // If the file or folder exist return true otherwise return false 15 | func Exist(filename string) bool { 16 | _, err := os.Stat(filename) 17 | return err == nil || os.IsExist(err) 18 | } 19 | 20 | // Ensure our necessary folders exists 21 | func EnsureFoldersExist(rootpath string, paths ...string) { 22 | if Exist(rootpath) { 23 | os.Rename(rootpath, rootpath+"-bak") 24 | color.PrintWarn(fmt.Sprintf("Backup %v to %v-bak folder", rootpath, rootpath)) 25 | } 26 | if len(paths) > 0 { 27 | for _, path := range paths { 28 | os.MkdirAll(path, 0700) 29 | } 30 | } 31 | } 32 | 33 | // CopyFile copies the contents of the file named src to the file named 34 | // by dst. The file will be created if it does not already exist. If the 35 | // destination file exists, all it's contents will be replaced by the contents 36 | // of the source file. The file mode will be copied from the source and 37 | // the copied data is synced/flushed to stable storage. 38 | func CopyFile(src, dst string) (err error) { 39 | in, err := os.Open(src) 40 | if err != nil { 41 | return 42 | } 43 | defer in.Close() 44 | 45 | out, err := os.Create(dst) 46 | if err != nil { 47 | return 48 | } 49 | defer func() { 50 | if e := out.Close(); e != nil { 51 | err = e 52 | } 53 | }() 54 | 55 | _, err = io.Copy(out, in) 56 | if err != nil { 57 | return 58 | } 59 | 60 | err = out.Sync() 61 | if err != nil { 62 | return 63 | } 64 | 65 | si, err := os.Stat(src) 66 | if err != nil { 67 | return 68 | } 69 | err = os.Chmod(dst, si.Mode()) 70 | if err != nil { 71 | return 72 | } 73 | 74 | return 75 | } 76 | 77 | // CopyDir recursively copies a directory tree, attempting to preserve permissions. 78 | // Source directory must exist, destination directory must *not* exist. 79 | // Symlinks are ignored and skipped. 80 | func CopyDir(src string, dst string) (err error) { 81 | src = filepath.Clean(src) 82 | dst = filepath.Clean(dst) 83 | 84 | si, err := os.Stat(src) 85 | if err != nil { 86 | return err 87 | } 88 | if !si.IsDir() { 89 | return fmt.Errorf("source is not a directory") 90 | } 91 | 92 | _, err = os.Stat(dst) 93 | if err != nil && !os.IsNotExist(err) { 94 | return 95 | } 96 | if err == nil { 97 | return fmt.Errorf("destination already exists") 98 | } 99 | 100 | err = os.MkdirAll(dst, si.Mode()) 101 | if err != nil { 102 | return 103 | } 104 | 105 | entries, err := ioutil.ReadDir(src) 106 | if err != nil { 107 | return 108 | } 109 | 110 | for _, entry := range entries { 111 | srcPath := filepath.Join(src, entry.Name()) 112 | dstPath := filepath.Join(dst, entry.Name()) 113 | 114 | if entry.IsDir() { 115 | err = CopyDir(srcPath, dstPath) 116 | if err != nil { 117 | return 118 | } 119 | } else { 120 | // Skip symlinks. 121 | if entry.Mode()&os.ModeSymlink != 0 { 122 | continue 123 | } 124 | 125 | err = CopyFile(srcPath, dstPath) 126 | if err != nil { 127 | return 128 | } 129 | } 130 | } 131 | 132 | return 133 | } 134 | -------------------------------------------------------------------------------- /template/bufkill.go: -------------------------------------------------------------------------------- 1 | package template 2 | 3 | const Bufkill = ` 4 | " Reload guard and 'compatible' handling {{{1 5 | let s:save_cpo = &cpo 6 | set cpo&vim 7 | 8 | if v:version < 700 9 | echoe "bufkill.vim requires vim version 7.00 or greater (mainly because it uses the new lists functionality)" 10 | finish 11 | endif 12 | 13 | if exists("loaded_bufkill") 14 | if !exists('g:Debug') 15 | finish 16 | endif " Debug 17 | endif 18 | let loaded_bufkill = 1 19 | 20 | function! s:Debug(level, ...) "{{{1 21 | " Arguments: First argument is always a level value (Debug) 22 | " Subsequent arguments can be any type. (Debug) 23 | " If they are a string, and that string represents the name of a global (Debug) 24 | " variable, the variable name, and it's value, will be printed. (Debug) 25 | " Lists and dictionaries should be handled. (Debug) 26 | if !exists('g:Debug') || g:Debug < a:level " (Debug) 27 | return " (Debug) " 28 | endif " (Debug) 29 | " (Debug) 30 | let s = '' " (Debug) 31 | let i = 1 " (Debug) 32 | while i <= a:0 " (Debug) 33 | if exists('DebugArg') " (Debug) 34 | unlet DebugArg " (Debug) 35 | endif " (Debug) 36 | exec "let DebugArg = a:" . i 37 | let argType = type(DebugArg) " (Debug) 38 | if argType == 1 " String (Debug) 39 | " String may be a variable name, in which case we print the name first (Debug) 40 | if exists(DebugArg) " (Debug) 41 | " The string is indeed the name of a variable (Debug) 42 | " Get the name of the variable, then set DebugArg to the value of that variable 43 | let s = s . DebugArg . " = " " (Debug) 44 | exec 'let arg2 = ' . DebugArg 45 | unlet DebugArg " (Debug) 46 | let DebugArg = arg2 " Necessary to change the type of DebugArg (Debug) 47 | endif " (Debug) 48 | endif " (Debug) 49 | " Now print the value itself (Debug) 50 | let s = s . string(DebugArg) " (Debug) 51 | if i < a:0 " (Debug) 52 | let s = s . ', ' " (Debug) 53 | endif " (Debug) 54 | let i = i + 1 " (Debug) 55 | endwhile " (Debug) 56 | autocmd! CursorHold * echom '--------- Debug ---------' 57 | let g:DebugEcho = 'echom' 58 | exec g:DebugEcho . ' s' 59 | endfunction " (Debug) 60 | 61 | " User configurable variables {{{1 62 | " The following variables can be set in your .vimrc/_vimrc file to override 63 | " those in this file, such that upgrades to the script won't require you to 64 | " re-edit these variables. 65 | 66 | " g:BufKillActionWhenBufferDisplayedInAnotherWindow {{{2 67 | " If the buffer you are attempting to kill in one window is also displayed 68 | " in another, you may not want to kill it afterall. This option lets you 69 | " decide how this situation should be handled, and can take one of the following 70 | " values: 71 | " 'kill' - kill the buffer regardless, always 72 | " 'confirm' - ask for confirmation before removing it 73 | " 'cancel' - don't kill it 74 | " Regardless of the setting of this variable, the buffer will always be 75 | " killed if you add an exclamation mark to the command, eg :BD! 76 | if !exists('g:BufKillActionWhenBufferDisplayedInAnotherWindow') 77 | let g:BufKillActionWhenBufferDisplayedInAnotherWindow = 'confirm' 78 | endif 79 | call s:Debug(2, 'g:BufKillActionWhenBufferDisplayedInAnotherWindow') 80 | 81 | " g:BufKillFunctionSelectingValidBuffersToDisplay {{{2 82 | " When a buffer is removed from a window, the script finds the previous 83 | " buffer displayed in the window. However, that buffer may have been 84 | " unloaded/deleted/wiped by some other mechanism, so it may not be a 85 | " valid choice. For some people, an unloaded buffer may be a valid choice, 86 | " for others, no. 87 | " - If unloaded buffers should be displayed, set this 88 | " variable to 'bufexists'. 89 | " - If unloaded buffers should not be displayed, set this 90 | " variable to 'buflisted' (default). 91 | " - Setting this variable to 'auto' means that the command :BW will use 92 | " 'bufexists' to decide if a buffer is valid to display, whilst using 93 | " :BD or :BUN will use 'buflisted' 94 | if !exists('g:BufKillFunctionSelectingValidBuffersToDisplay') 95 | let g:BufKillFunctionSelectingValidBuffersToDisplay = 'buflisted' 96 | endif 97 | call s:Debug(2, 'g:BufKillFunctionSelectingValidBuffersToDisplay') 98 | 99 | " g:BufKillActionWhenModifiedFileToBeKilled {{{2 100 | " When a request is made to kill (wipe, delete, or unload) a modified buffer 101 | " and the "bang" (!) wasn't included in the commend, two possibilities exist: 102 | " 1) Fail in the same way as :bw or :bd would, or 103 | " 2) Prompt the user to save, not save, or cancel the request. 104 | " Possible values are 'fail' (for options 1), and 'confirm' for option 2 105 | " This is similar to the vim 'confirm' option. Thus, if this variable 106 | " isn't defined, the 'confirm' setting will be adopted. Since we want 107 | " the most current value of 'confirm', no default value need be set 108 | " for this variable, and it needn't exist. 109 | 110 | " g:BufKillOverrideCtrlCaret {{{2 111 | " The standard vim functionality for Ctrl-^ or Ctrl-6 (swap to alternate 112 | " buffer) swaps to the alternate file, and preserves the line within that file, 113 | " but does not preserve the column within the line - instead it goes to the 114 | " start of the line. If you prefer to go to the same column as well, 115 | " set this variable to 1. 116 | if !exists('g:BufKillOverrideCtrlCaret') 117 | let g:BufKillOverrideCtrlCaret = 0 118 | endif 119 | call s:Debug(2, 'g:BufKillOverrideCtrlCaret') 120 | 121 | " g:BufKillVerbose {{{2 122 | " If set to 1, prints extra info about what's being done, why, and how to 123 | " change it 124 | if !exists('g:BufKillVerbose') 125 | let g:BufKillVerbose = 1 126 | endif 127 | call s:Debug(2, 'g:BufKillVerbose') 128 | 129 | " g:BufKillCreateMappings {{{2 130 | " If set to 1, creates the various mapleader-based mappings. By default this 131 | " is set to 1 ('true') but users may want to set to 0 ('false') in order to 132 | " define their own mappings or to fix a mapping conflict with another plugin. 133 | let s:BufKillCreateMappings = get(g:,'BufKillCreateMappings',0) 134 | 135 | call s:Debug(2, 'g:BufKillCreateMappings') 136 | 137 | " g:BufKillCommandPrefix {{{2 138 | " A string that will act as the prefix to all BufKill user commands. The 139 | " string must adhere to the user command guidelines established in the vim 140 | " help (see :help user-commands). By default this is set to 'B' but users 141 | " may want to change this in order to define their own commands or to fix 142 | " a command conflict with another plugin. 143 | if !exists('g:BufKillCommandPrefix') 144 | let g:BufKillCommandPrefix = 'B' 145 | endif 146 | call s:Debug(2, 'g:BufKillCommandPrefix') 147 | 148 | " Commands {{{1 149 | " 150 | function! CreateUniqueCommand(lhs, rhs) 151 | let command = g:BufKillCommandPrefix.a:lhs 152 | if exists(':'.command) < 2 153 | exe 'command -bang '.command.' '.a:rhs 154 | endif 155 | endfunction 156 | call CreateUniqueCommand('A' , ':call GotoBuffer(''#'',"")') 157 | call CreateUniqueCommand('B' , ':call GotoBuffer(''bufback'',"")') 158 | call CreateUniqueCommand('F' , ':call GotoBuffer(''bufforward'',"")') 159 | call CreateUniqueCommand('D' , ':call BufKill(''bd'',"")') 160 | call CreateUniqueCommand('UN' , ':call BufKill(''bun'',"")') 161 | call CreateUniqueCommand('D' , ':call BufKill(''bd'',"")') 162 | call CreateUniqueCommand('W' , ':call BufKill(''bw'',"")') 163 | call CreateUniqueCommand('UNDO', ':call UndoKill()') 164 | 165 | " Keyboard mappings {{{1 166 | " 167 | 168 | noremap BufKillAlt :call GotoBuffer('#', '') 169 | noremap BufKillBangAlt :call GotoBuffer('#', '!') 170 | noremap BufKillBack :call GotoBuffer('bufback', '') 171 | noremap BufKillBangBack :call GotoBuffer('bufback', '!') 172 | noremap BufKillForward :call GotoBuffer('bufforward', '') 173 | noremap BufKillBangForward :call GotoBuffer('bufforward', '!') 174 | noremap BufKillBun :call BufKill('bun', '') 175 | noremap BufKillBangBun :call BufKill('bun', '!') 176 | noremap BufKillBd :call BufKill('bd', '') 177 | noremap BufKillBangBd :call BufKill('bd', '!') 178 | noremap BufKillBw :call BufKill('bw', '') 179 | noremap BufKillBangBw :call BufKill('bw', '!') 180 | noremap BufKillUndo :call UndoKill() 181 | 182 | if s:BufKillCreateMappings == 1 183 | 184 | function! CreateUniqueMapping(lhs, rhs, ...) 185 | if hasmapto(a:rhs) && !(a:0 == 1 && a:1 == 'AllowDuplicate') 186 | " The user appears to have defined an alternate mapping for this command 187 | return 188 | elseif maparg(a:lhs, 'n') != "" 189 | " The user appears to have defined a mapping for a:lhs already 190 | return 191 | endif 192 | exec 'nmap '.a:lhs.' '.a:rhs 193 | endfunction 194 | 195 | call CreateUniqueMapping('bb', 'BufKillBack') 196 | call CreateUniqueMapping('bf', 'BufKillForward') 197 | call CreateUniqueMapping('bun', 'BufKillBun') 198 | call CreateUniqueMapping('!bun', 'BufKillBangBun') 199 | call CreateUniqueMapping('bd', 'BufKillBd') 200 | call CreateUniqueMapping('!bd', 'BufKillBangBd') 201 | call CreateUniqueMapping('bw', 'BufKillBw') 202 | call CreateUniqueMapping('!bw', 'BufKillBangBw') 203 | call CreateUniqueMapping('bundo','BufKillUndo') 204 | call CreateUniqueMapping('ba', 'BufKillAlt') 205 | if g:BufKillOverrideCtrlCaret == 1 206 | call CreateUniqueMapping('', 'BufKillAlt', 'AllowDuplicate') 207 | endif 208 | endif 209 | 210 | function! BufKill(cmd, bang) "{{{1 211 | " The main function that sparks the buffer change/removal 212 | let DebugF = 'BufKill' 213 | call s:Debug(1, DebugF, a:cmd, a:bang) 214 | if !exists('w:BufKillList') 215 | echoe "BufKill Error: array w:BufKillList does not exist!" 216 | echoe "Restart vim and retry, and if problems persist, notify the author!" 217 | return 218 | endif 219 | call s:Debug(2, DebugF, 'w:BufKillList') 220 | 221 | call SaveWindowPos() 222 | 223 | " Get the buffer to delete - the current one obviously 224 | let s:BufKillBufferToKill = bufnr('%') 225 | let s:BufKillBufferToKillPath = expand('%:p') 226 | call s:Debug(2, DebugF, 's:BufKillBufferToKill') 227 | 228 | " Just to make sure, check that this matches the buffer currently pointer to 229 | " by w:BufKillIndex - else I've stuffed up 230 | if s:BufKillBufferToKill != w:BufKillList[w:BufKillIndex] 231 | echom "BufKill Warning: bufferToKill = ".s:BufKillBufferToKill." != element ".w:BufKillIndex." in the list: (".string(w:BufKillList).")" 232 | echom "Please notify the author of the circumstances of this message!" 233 | endif 234 | 235 | " If the buffer is modified, and a:bang is not set, give the same kind of 236 | " error (or confirmation) as normal bun/bw/bd 237 | if &modified && strlen(a:bang) == 0 238 | if exists('g:BufKillActionWhenModifiedFileToBeKilled') 239 | let s:BufKillActionWhenModifiedFileToBeKilled = g:BufKillActionWhenModifiedFileToBeKilled 240 | else 241 | if &confirm 242 | let s:BufKillActionWhenModifiedFileToBeKilled = 'confirm' 243 | else 244 | let s:BufKillActionWhenModifiedFileToBeKilled = 'fail' 245 | endif 246 | endif 247 | if s:BufKillActionWhenModifiedFileToBeKilled =~ '[Ff][Aa][Ii][Ll]' 248 | echohl ErrorMsg 249 | echo "No write since last change for buffer '" . bufname(s:BufKillBufferToKill) . "' (add ! to override)" 250 | echohl None 251 | return 252 | elseif s:BufKillActionWhenModifiedFileToBeKilled =~ '[Cc][Oo][Nn][Ff][Ii][Rr][Mm]' 253 | let options = "&Yes\n&No\n&Cancel" 254 | let actionAdjustment = 0 255 | let bufname = bufname(winbufnr(winnr())) 256 | if bufname == '' 257 | let bufname = '[No File]' 258 | let options = "&No\n&Cancel" 259 | let actionAdjustment = 1 260 | endif 261 | let action=confirm("Save Changes in " . bufname . " before removing it?", options) 262 | if action + actionAdjustment == 1 263 | " Yes - try to save - if there is an error, cancel 264 | let v:errmsg = "" 265 | silent w 266 | if v:errmsg != "" 267 | echoerr "Unable to write buffer!" 268 | return 269 | endif 270 | elseif action + actionAdjustment == 2 271 | " No, abandon changes 272 | set nomodified 273 | else 274 | " Cancel (or any other result), don't do the open 275 | return 276 | endif 277 | else 278 | echoe "Illegal value (' . s:BufKillActionWhenModifiedFileToBeKilled . ') stored in variable s:BufKillActionWhenModifiedFileToBeKilled, please notify the author" 279 | endif 280 | endif 281 | 282 | " Get a list of all windows which have this buffer loaded 283 | let s:BufKillWindowListWithBufferLoaded = [] 284 | let i = 1 285 | let buf = winbufnr(i) 286 | while buf != -1 287 | if buf == s:BufKillBufferToKill 288 | let s:BufKillWindowListWithBufferLoaded += [i] 289 | call s:Debug(2, DebugF, 'Added window ' . i . ' to', 's:BufKillWindowListWithBufferLoaded') 290 | endif 291 | let i = i + 1 292 | let buf = winbufnr(i) 293 | endwhile 294 | call s:Debug(2, DebugF, 's:BufKillWindowListWithBufferLoaded') 295 | 296 | " Handle the case where the buffer is displayed in multiple windows 297 | if len(s:BufKillWindowListWithBufferLoaded) > 1 && strlen(a:bang) == 0 298 | if g:BufKillActionWhenBufferDisplayedInAnotherWindow =~ '[Cc][Aa][Nn][Cc][Ee][Ll]' 299 | if g:BufKillVerbose 300 | echom "Buffer '" . bufname(s:BufKillBufferToKill) . "' displayed in multiple windows - " . a:cmd . " cancelled (add ! to kill anywawy, or set g:BufKillActionWhenBufferDisplayedInAnotherWindow to 'confirm' or 'kill')" 301 | endif 302 | return 303 | elseif g:BufKillActionWhenBufferDisplayedInAnotherWindow =~ '[Cc][Oo][Nn][Ff][Ii][Rr][Mm]' 304 | let choice = confirm("Buffer '" . bufname(s:BufKillBufferToKill) . "' displayed in multiple windows - " . a:cmd . " it anyway?", "&Yes\n&No", 1) 305 | if choice != 1 306 | return 307 | endif 308 | elseif g:BufKillActionWhenBufferDisplayedInAnotherWindow =~ '[Rr][Ee][Mm][Oo][Vv][Ee]' 309 | if g:BufKillVerbose 310 | echom "Buffer '" . bufname(s:BufKillBufferToKill) . "' displayed in multiple windows - executing " . a:cmd . " anyway." 311 | endif 312 | " Fall through and continue 313 | endif 314 | endif 315 | 316 | " For each window that the file is loaded in, go to the previous buffer from its list 317 | let i = 0 318 | while i < len(s:BufKillWindowListWithBufferLoaded) 319 | let win = s:BufKillWindowListWithBufferLoaded[i] 320 | call s:Debug(2, DebugF, 'Got window ' . win . ' from', 's:BufKillWindowListWithBufferLoaded', 'position ' . i) 321 | 322 | " Go to the right window in which to perform the action 323 | if win > 0 324 | call s:Debug(2, DebugF, 'Goto window ' . win) 325 | exec 'normal! ' . win . 'w' 326 | call s:Debug(2, DebugF, 'Current window ' . winnr()) 327 | endif 328 | 329 | " Go to the previous buffer for this window 330 | call GotoBuffer(a:cmd, a:bang) 331 | 332 | let i = i + 1 333 | endwhile 334 | 335 | " Restore the cursor to the correct window _before_ removing the buffer, 336 | " since the buffer removal could have side effects on the windows (eg 337 | " minibuffer disappearing due to not enough buffers) 338 | call RestoreWindowPos() 339 | 340 | " Kill the old buffer, but save info about it for undo purposes 341 | let s:BufKillLastWindowListWithBufferLoaded = s:BufKillWindowListWithBufferLoaded 342 | let s:BufKillLastBufferKilledPath = s:BufKillBufferToKillPath 343 | let s:BufKillLastBufferKilledNum = s:BufKillBufferToKill 344 | " In some cases (eg when deleting the quickfix buffer) the buffer will 345 | " already have been deleted by the switching to another buffer in its 346 | " window. Thus we must check before deleting. 347 | if bufexists(s:BufKillBufferToKill) 348 | let killCmd = a:cmd . a:bang . s:BufKillBufferToKill 349 | call s:Debug(2, DebugF, 'killCmd = ' . killCmd) 350 | exec killCmd 351 | else " Debug 352 | call s:Debug(2, DebugF, 'buffer #'.s:BufKillBufferToKill.' removed during GotoBuffer step') 353 | endif 354 | 355 | " Restore position if saved. Needed on console vim, at least, to restore correct column 356 | call RestoreView() 357 | 358 | call s:Debug(2, DebugF, 'Exiting') 359 | endfunction 360 | 361 | function! IsBufferNew(buf) "{{{1 362 | return (bufname(a:buf) == '') && !getbufvar(a:buf, '&modified') 363 | endfunction 364 | 365 | function! SwitchToNewBuffer(bang) "{{1 366 | let old_bufnum = bufnr('%') 367 | 368 | " if we already have a "new" buffer, switch to it 369 | for bufnum in range(1, bufnr('$')) 370 | if bufexists(bufnum) && IsBufferNew(bufnum) && (bufnum != old_bufnum) 371 | exec 'b' . a:bang . bufnum 372 | return 373 | endif 374 | endfor 375 | 376 | " try to create a new buffer 377 | exec 'enew' . a:bang 378 | if bufnr('%') != old_bufnum 379 | return 380 | endif 381 | 382 | " sometimes vim doesn't bother creating a new buffer, eg if you do two enews 383 | " in a row. it's possible to workaround this by modifying the current buffer 384 | " before doing the enew... 385 | let &modifiable = 1 386 | normal! iforce enew to create a new buffer 387 | enew! 388 | let new_bufnum = bufnr('%') 389 | exec 'b' . old_bufnum 390 | silent normal! u 391 | exec 'b' . new_bufnum 392 | endfunction 393 | 394 | function! GotoBuffer(cmd, bang) "{{{1 395 | "Function to display the previous buffer for the specified window 396 | " a:cmd is one of 397 | " bun - Unloading the current buffer 398 | " bd - Deleting the current buffer 399 | " bw - Wiping the current buffer 400 | " bufback - stepping back through the list 401 | " bufforward - stepping forward through the list 402 | " # - swap to alternate buffer, if one exists. Use this instead of 403 | " Ctrl-^, in order to swap to the previous column of the alternate 404 | " file, which does not happen with regular Ctrl-^. 405 | let DebugF = 'GotoBuffer' 406 | call s:Debug(1, DebugF, a:cmd) 407 | call s:Debug(2, DebugF, 'w:BufKillList') 408 | call s:Debug(2, DebugF, 'w:BufKillColumnList') 409 | call s:Debug(2, DebugF, 'w:BufKillIndex') 410 | 411 | if (a:cmd=='bun' || a:cmd=='bd' || a:cmd=='bw') 412 | let killing = 1 413 | else 414 | let killing = 0 415 | endif 416 | 417 | if killing 418 | " Handle the 'auto' setting for 419 | " g:BufKillFunctionSelectingValidBuffersToDisplay 420 | let validityFunction = g:BufKillFunctionSelectingValidBuffersToDisplay 421 | if validityFunction == 'auto' 422 | " The theory here is that if a person usually uses bd, then buffers 423 | " they've intended to delete will still exist, but not be listed. Hence 424 | " we use buflisted to check if they've deleted the buffer already, so as 425 | " not to show the ones they've deleted. If instead they use bw, 426 | " then the assumption is that to really delete buffers they use bw, so 427 | " if they've used bd, they were meaning to hide the file from view - but 428 | " keep it around - hence we should find it if it's only been deleted, 429 | " hence we use bufexists to look for it. Yes, it's weak logic - but you 430 | " can always override it! ;) 431 | if a:cmd == 'bw' 432 | let validityFunction = 'bufexists' 433 | else 434 | let validityFunction = 'buflisted' 435 | endif 436 | endif 437 | let w:BufKillIndex -= 1 438 | else 439 | " Should only be used with undeleted (and unwiped) buffers 440 | let validityFunction = 'buflisted' 441 | 442 | if a:cmd == 'bufforward' 443 | let w:BufKillIndex += 1 444 | elseif a:cmd == 'bufback' 445 | let w:BufKillIndex -= 1 446 | elseif a:cmd == '#' 447 | let bufnum = bufnr('#') 448 | if bufnum == -1 449 | echom "E23: No alternate file (error simulated by bufkill.vim)" 450 | return 451 | endif 452 | if bufnum == bufnr('%') 453 | " If the alternate buffer is also the current buffer, do nothing 454 | return 455 | elseif !buflisted(bufnum) 456 | " Vim just ignores the command in this case, so we'll do likewise 457 | " Update: it seems it no longer ignores the command in this case 458 | " but in my experience, I don't want to jump to an unlisted 459 | " buffer via this command - so I'll continue to ignore it - but notify 460 | " the user... 461 | echom "bufkill: Alternate buffer is unlisted buffer ".bufnum." (" 462 | \ .bufname(bufnum).") - ignoring request" 463 | return 464 | endif 465 | " Find this buffer number in the w:BufKillList 466 | let w:BufKillIndex = index(w:BufKillList, bufnum) 467 | endif 468 | endif 469 | 470 | while 1 471 | if w:BufKillIndex < 0 472 | let w:BufKillIndex = 0 473 | elseif w:BufKillIndex > (len(w:BufKillList) - 1) 474 | let w:BufKillIndex = len(w:BufKillList) - 1 475 | endif 476 | 477 | if w:BufKillList[w:BufKillIndex] == bufnr('%') 478 | if !killing 479 | echom 'BufKill: already at the limit of the BufKill list' 480 | return 481 | endif 482 | 483 | " we're going to kill the current buffer -- we want to switch to a 484 | " different one... 485 | if w:BufKillIndex == 0 486 | if len(w:BufKillList) == 1 487 | " there are no other buffers in our list. switch to a "new" one 488 | call SwitchToNewBuffer(a:bang) 489 | call SaveView() 490 | return 491 | endif 492 | let w:BufKillIndex += 1 493 | else 494 | let w:BufKillIndex -= 1 495 | endif 496 | endif 497 | 498 | let newBuffer = w:BufKillList[w:BufKillIndex] 499 | let newColumn = w:BufKillColumnList[w:BufKillIndex] 500 | 501 | call s:Debug(2, DebugF, 'newBuffer = ' . newBuffer . ', newColumn = ' . newColumn) 502 | exec 'let validityResult = '.validityFunction.'(newBuffer)' 503 | if validityResult 504 | " buffer is valid: switch to it... 505 | exec 'b' . a:bang . newBuffer . "|call cursor(line('.')," . newColumn . ')' 506 | call SaveView() 507 | return 508 | endif 509 | 510 | " buffer isn't valid: remove it from the list 511 | call remove(w:BufKillList, w:BufKillIndex) 512 | call remove(w:BufKillColumnList, w:BufKillIndex) 513 | if a:cmd != 'bufforward' 514 | let w:BufKillIndex -= 1 515 | " No change needed for bufforward since we just deleted the element 516 | " being pointed to, so effectively, we moved forward one spot 517 | endif 518 | endwhile 519 | 520 | call s:Debug(2, DebugF, 'w:BufKillList') 521 | call s:Debug(2, DebugF, 'w:BufKillColumnList') 522 | call s:Debug(2, DebugF, 'w:BufKillIndex') 523 | call s:Debug(2, DebugF, 'Exiting') 524 | " redraw " To hide call Debug messages for now! 525 | endfunction " GotoBuffer 526 | 527 | function! UpdateList(event) "{{{1 528 | " Function to update the window list with info about the current buffer 529 | let DebugF = 'UpdateList' 530 | call s:Debug(1, DebugF, 'Entering(' . a:event . '): win = ' . winnr() . ', buf = ' . bufnr('%') . ' (' . bufname('%') . ')') 531 | if !exists('w:BufKillList') 532 | let w:BufKillList = [] 533 | endif 534 | if !exists('w:BufKillColumnList') 535 | let w:BufKillColumnList = [] 536 | endif 537 | if !exists('w:BufKillIndex') 538 | let w:BufKillIndex = -1 539 | endif 540 | call s:Debug(2, DebugF, 'w:BufKillList') 541 | call s:Debug(2, DebugF, 'w:BufKillColumnList') 542 | call s:Debug(2, DebugF, 'w:BufKillIndex') 543 | let bufferNum = bufnr('%') 544 | 545 | if (w:BufKillIndex == -1) || (w:BufKillList[w:BufKillIndex] != bufferNum) 546 | " Increment index 547 | let w:BufKillIndex += 1 548 | if w:BufKillIndex < len(w:BufKillList) 549 | " The branch is diverging, remove the end of the list 550 | call remove(w:BufKillList, w:BufKillIndex, -1) 551 | " Same for column list 552 | if w:BufKillIndex < len(w:BufKillColumnList) 553 | call remove(w:BufKillColumnList, w:BufKillIndex, -1) 554 | endif 555 | endif 556 | " Now remove any pre-existing instances of the buffer in the list 557 | let existingIndex = index(w:BufKillList, bufferNum) 558 | if existingIndex != -1 559 | call remove(w:BufKillList, existingIndex) 560 | let w:BufKillIndex -= 1 561 | if existingIndex < len(w:BufKillColumnList) 562 | call remove(w:BufKillColumnList, existingIndex) 563 | endif 564 | endif 565 | " Now add the buffer to the list, at the end 566 | let w:BufKillList += [bufferNum] 567 | endif 568 | 569 | call s:Debug(2, DebugF, 'w:BufKillList') 570 | call s:Debug(2, DebugF, 'w:BufKillColumnList') 571 | call s:Debug(2, DebugF, 'w:BufKillIndex') 572 | call s:Debug(1, DebugF, 'Exiting (' . a:event . '): ', 'w:BufKillList') 573 | " redraw " To hide call Debug messages for now! 574 | endfunction " UpdateList 575 | 576 | function! UpdateLastColumn(event) "{{{1 577 | " Function to save the current column and buffer and window numbers, 578 | let DebugF = 'UpdateColumnList' 579 | call s:Debug(1, DebugF, 'Entering(' . a:event . '): win = ' . winnr() . ', buf = ' . bufnr('%') . ' (' . bufname('%') . ')') 580 | call s:Debug(2, DebugF, 'w:BufKillList') 581 | call s:Debug(2, DebugF, 'w:BufKillColumnList') 582 | call s:Debug(2, DebugF, 'w:BufKillIndex') 583 | if !exists('w:BufKillList') 584 | " Just give up for now. 585 | return 586 | endif 587 | let index = index(w:BufKillList, bufnr('%')) 588 | if index != -1 589 | " Extend list if required, then set the value 590 | let w:BufKillColumnList += repeat([0], index - len(w:BufKillColumnList) + 1) 591 | let w:BufKillColumnList[index] = col('.') 592 | else 593 | call s:Debug(2, DebugF, 'UpdateLastColumn failed to find bufnr ' . bufnr('%') . ' in w:BufKillList') 594 | endif 595 | call s:Debug(2, DebugF, 'w:BufKillList') 596 | call s:Debug(2, DebugF, 'w:BufKillColumnList') 597 | call s:Debug(2, DebugF, 'w:BufKillIndex') 598 | call s:Debug(1, DebugF, 'Exiting (' . a:event . ')') 599 | " redraw " To hide call Debug messages for now! 600 | endfunction 601 | 602 | function! UndoKill() "{{{1 603 | let DebugF = 'UndoKill' 604 | call s:Debug(1, DebugF) 605 | 606 | if !exists('s:BufKillLastBufferKilledNum') || !exists('s:BufKillLastBufferKilledPath') || s:BufKillLastBufferKilledNum == -1 || s:BufKillLastBufferKilledPath == '' 607 | echoe 'BufKill: nothing to undo (only one level of undo is supported)' 608 | else 609 | if bufexists(s:BufKillLastBufferKilledNum) 610 | let cmd = 'b' . s:BufKillLastBufferKilledNum 611 | elseif filereadable(s:BufKillLastBufferKilledPath) 612 | let cmd = 'e ' . s:BufKillLastBufferKilledPath 613 | else 614 | unlet s:BufKillLastBufferKilledNum 615 | unlet s:BufKillLastBufferKilledPath 616 | unlet s:BufKillLastWindowListWithBufferLoaded 617 | echoe 'BufKill: unable to undo. Neither buffer (' . s:BufKillLastBufferKilledNum . ') nor file (' . s:BufKillLastBufferKilledPath . ') could be found.' 618 | endif 619 | 620 | " For each window the buffer was removed from, show it again 621 | call SaveWindowPos() 622 | let i = 0 623 | while i < len(s:BufKillLastWindowListWithBufferLoaded) 624 | let win = s:BufKillLastWindowListWithBufferLoaded[i] 625 | call s:Debug(2, DebugF, 'Got window ' . win . ' from', 's:BufKillLastWindowListWithBufferLoaded', 'position ' . i) 626 | call s:Debug(2, DebugF, 'Goto window ' . win) 627 | exec 'normal! ' . win . 'w' 628 | call s:Debug(2, DebugF, 'Current window ' . winnr()) 629 | exec cmd 630 | let i = i + 1 631 | endwhile 632 | call RestoreWindowPos() 633 | 634 | unlet s:BufKillLastBufferKilledNum 635 | unlet s:BufKillLastBufferKilledPath 636 | unlet s:BufKillLastWindowListWithBufferLoaded 637 | endif 638 | call s:Debug(2, DebugF, 'Exiting') 639 | endfunction 640 | 641 | function! SaveWindowPos() "{{{1 642 | " Save the current window, to be able to come back to it after doing things 643 | " in other windows 644 | let DebugF = 'SaveWindowPos' 645 | let s:BufKillWindowPos = winnr() 646 | call s:Debug(2, DebugF, 'Saving with winnr = ', 's:BufKillWindowPos') 647 | endfunction 648 | 649 | function! RestoreWindowPos() "{{{1 650 | " Restore the window from it's saved config variable 651 | let DebugF = 'RestoreWindowPos' 652 | call s:Debug(2, DebugF, 'Restoring to = ', 's:BufKillWindowPos') 653 | exec 'normal! ' . s:BufKillWindowPos . 'w' 654 | endfunction 655 | 656 | function! SaveView() "{{{1 657 | " Function to save the current view to w:BufKillSavedView. This has been 658 | " found necessary on console vim in particular, in order return to the 659 | " correct column when killing a file. 660 | let DebugF = 'SaveView' 661 | if exists("*winsaveview") 662 | let w:BufKillSavedView = winsaveview() 663 | call s:Debug(2, DebugF, 'SavedView = ', 'w:BufKillSavedView') 664 | else 665 | call s:Debug(1, DebugF, 'winsaveview not in this version of Vim, column not reliably saved.') 666 | endif 667 | endfunction " SaveView 668 | 669 | function! RestoreView() "{{{1 670 | " Matching restore function to SaveView 671 | let DebugF = 'RestoreView' 672 | if exists("*winrestview") && exists('w:BufKillSavedView') 673 | call winrestview(w:BufKillSavedView) 674 | call s:Debug(2, DebugF, 'Restoring to = ', 'w:BufKillSavedView') 675 | unlet w:BufKillSavedView 676 | endif 677 | endfunction " RestoreView 678 | 679 | " Autocommands {{{1 680 | " 681 | augroup BufKill 682 | autocmd! 683 | autocmd BufKill WinEnter * call UpdateList('WinEnter') 684 | autocmd BufKill BufEnter * call UpdateList('BufEnter') 685 | autocmd BufKill BufAdd * call UpdateList('BufAdd') 686 | autocmd BufKill WinLeave * call UpdateLastColumn('WinLeave') 687 | autocmd BufKill BufLeave * call UpdateLastColumn('BufLeave') 688 | augroup END 689 | 690 | " Cleanup and modelines {{{1 691 | let &cpo = s:save_cpo 692 | ` 693 | -------------------------------------------------------------------------------- /template/difftools.go: -------------------------------------------------------------------------------- 1 | package template 2 | 3 | const Difftools = ` 4 | " Improve diff behavior 5 | " --- 6 | " 7 | " Behaviors: 8 | " - Update diff comparison once leaving insert mode 9 | " 10 | " Commands: 11 | " - DiffOrig: Show diff of unsaved changes 12 | 13 | if exists('g:loaded_difftools') 14 | finish 15 | endif 16 | let g:loaded_difftools = 1 17 | 18 | augroup plugin_difftools 19 | autocmd! 20 | autocmd InsertLeave * if &l:diff | diffupdate | endif 21 | autocmd BufWinLeave __diff call s:close_diff() 22 | augroup END 23 | 24 | function! s:open_diff() 25 | " Open diff window and start comparison 26 | let l:bnr = bufnr('%') 27 | call setwinvar(winnr(), 'diff_origin', l:bnr) 28 | vertical new __diff 29 | let l:diff_bnr = bufnr('%') 30 | nnoremap q :quit 31 | setlocal buftype=nofile bufhidden=wipe 32 | r ++edit # 33 | 0d_ 34 | diffthis 35 | setlocal readonly 36 | wincmd p 37 | let b:diff_bnr = l:diff_bnr 38 | nnoremap q :execute bufwinnr(b:diff_bnr) . 'q' 39 | diffthis 40 | endfunction 41 | 42 | function! s:close_diff() 43 | " Close diff window, switch to original window and disable diff 44 | " Credits: https://github.com/chemzqm/vim-easygit 45 | let wnr = +bufwinnr(+expand('')) 46 | let val = getwinvar(wnr, 'diff_origin') 47 | if ! len(val) | return | endif 48 | for i in range(1, winnr('$')) 49 | if i == wnr | continue | endif 50 | if len(getwinvar(i, 'diff_origin')) 51 | return 52 | endif 53 | endfor 54 | let wnr = bufwinnr(val) 55 | if wnr > 0 56 | execute wnr . 'wincmd w' 57 | diffoff 58 | endif 59 | endfunction 60 | 61 | " Display diff of unsaved changes 62 | command! -nargs=0 DiffOrig call s:open_diff() 63 | 64 | " vim: set ts=2 sw=2 tw=80 noet : 65 | ` 66 | -------------------------------------------------------------------------------- /template/hlsearch.go: -------------------------------------------------------------------------------- 1 | // Package template provides ... 2 | package template 3 | 4 | const Hlsearchvim = ` 5 | let s:save_cpo = &cpoptions 6 | set cpoptions&vim 7 | 8 | augroup hlsearch 9 | autocmd! 10 | " trigger when hlsearch is toggled 11 | autocmd OptionSet hlsearch call toggle(v:option_old, v:option_new) 12 | augroup END 13 | 14 | function! s:StartHL() 15 | silent! if v:hlsearch && !search('\%#\zs'.@/,'cnW') 16 | call StopHL() 17 | endif 18 | endfunction 19 | 20 | function! s:StopHL() 21 | if ! v:hlsearch || mode() !=? 'n' 22 | return 23 | else 24 | silent call feedkeys("\(StopHL)", 'm') 25 | endif 26 | endfunction 27 | 28 | function! s:toggle(old, new) 29 | if a:old == 0 && a:new == 1 30 | " nohls --> hls 31 | " set up 32 | noremap (StopHL) execute('nohlsearch')[-1] 33 | noremap! (StopHL) execute('nohlsearch')[-1] 34 | 35 | autocmd hlsearch CursorMoved * call StartHL() 36 | autocmd hlsearch InsertEnter * call StopHL() 37 | elseif a:old == 1 && a:new == 0 38 | " hls --> nohls 39 | " tear down 40 | nunmap (StopHL) 41 | unmap! (StopHL) 42 | 43 | autocmd! hlsearch CursorMoved 44 | autocmd! hlsearch InsertEnter 45 | else 46 | " nohls --> nohls 47 | " do nothing 48 | return 49 | endif 50 | endfunction 51 | 52 | call toggle(0, &hlsearch) 53 | 54 | let &cpoptions = s:save_cpo 55 | ` 56 | -------------------------------------------------------------------------------- /template/nicefold.go: -------------------------------------------------------------------------------- 1 | // Package tempalte provides ... 2 | package template 3 | 4 | const Nicefold = ` 5 | " Nice Fold 6 | " --- 7 | " 8 | " Behaviors: 9 | " - Improve folds performance after modification 10 | " - Set a nice pattern for collapsed folds 11 | 12 | if exists('g:loaded_nicefold') 13 | finish 14 | endif 15 | let g:loaded_nicefold = 1 16 | 17 | " Fast fold 18 | " Credits: https://github.com/Shougo/shougo-s-github 19 | augroup plugin_fastfold 20 | autocmd! 21 | autocmd TextChangedI,TextChanged * 22 | \ if &l:foldenable && &l:foldmethod !=# 'manual' 23 | \| let b:foldmethod_save = &l:foldmethod 24 | \| let &l:foldmethod = 'manual' 25 | \| endif 26 | 27 | autocmd BufWritePost * 28 | \ if &l:foldmethod ==# 'manual' && exists('b:foldmethod_save') 29 | \| let &l:foldmethod = b:foldmethod_save 30 | \| execute 'normal! zx' 31 | \| endif 32 | augroup END 33 | 34 | if has('folding') 35 | set foldtext=FoldText() 36 | endif 37 | 38 | " Improved Vim fold-text 39 | " See: http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/ 40 | function! FoldText() 41 | " Get first non-blank line 42 | let fs = v:foldstart 43 | while getline(fs) =~? '^\s*$' | let fs = nextnonblank(fs + 1) 44 | endwhile 45 | if fs > v:foldend 46 | let line = getline(v:foldstart) 47 | else 48 | let line = substitute(getline(fs), '\t', repeat(' ', &tabstop), 'g') 49 | endif 50 | 51 | let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0) 52 | let foldSize = 1 + v:foldend - v:foldstart 53 | let foldSizeStr = ' ' . foldSize . ' lines ' 54 | let foldLevelStr = repeat('+--', v:foldlevel) 55 | let lineCount = line('$') 56 | let foldPercentage = printf('[%.1f', (foldSize*1.0)/lineCount*100) . '%] ' 57 | let expansionString = repeat('.', w - strwidth(foldSizeStr.line.foldLevelStr.foldPercentage)) 58 | return line . expansionString . foldSizeStr . foldPercentage . foldLevelStr 59 | endfunction 60 | ` 61 | -------------------------------------------------------------------------------- /template/whitespace.go: -------------------------------------------------------------------------------- 1 | // Package template provides ... 2 | package template 3 | 4 | const Whitespace = ` 5 | " Whitespace utilities 6 | " --- 7 | " 8 | " Behaviors: 9 | " - Display special highlight for trailing whitespace and space preceding tabs 10 | " 11 | " Commands: 12 | " - WhitespaceErase: Strips trailing whitespace from buffer 13 | " - WhitespaceNext: Cursor jump to next whitespace issue 14 | " - WhitespacePrev: Cursor jump to next whitespace issue 15 | " 16 | " Options: 17 | " - g:whitespace_filetype_blacklist override default whitespace blacklist 18 | " - g:whitespace_characters overrides default whitespace chars (default: \s) 19 | " - g:whitespace_pattern overrides pattern (default: chars . \+$) 20 | " - g:whitespace_pattern_normal overrides normal mode pattern 21 | " - g:whitespace_pattern_insert overrides insert mode pattern 22 | 23 | if exists('g:loaded_pluginwhitespace') 24 | finish 25 | endif 26 | let g:loaded_pluginwhitespace = 1 27 | 28 | " Remove end of line white space 29 | command! -range=% WhitespaceErase call WhitespaceErase(, ) 30 | 31 | " Search for trailing white space forwards 32 | command! -range=% WhitespaceNext call WhitespaceJump(1, , ) 33 | 34 | " Search for trailing white space backwards 35 | command! -range=% WhitespacePrev call WhitespaceJump(-1, , ) 36 | 37 | " Whitespace events 38 | if v:version >= 702 39 | augroup plugin_whitespace 40 | autocmd! 41 | autocmd InsertEnter * call ToggleWhitespace('i') 42 | autocmd InsertLeave * call ToggleWhitespace('n') 43 | augroup END 44 | endif 45 | 46 | let s:ws_chars = get(g:, 'whitespace_characters', '\s') 47 | let s:ws_pattern = get(g:, 'whitespace_pattern', s:ws_chars . '\+$') 48 | let s:normal_pattern = get(g:, 'whitespace_pattern_normal', 49 | \ s:ws_pattern . '\| \+\ze\t') 50 | let s:insert_pattern = get(g:, 'whitespace_pattern_insert', 51 | \ s:ws_chars . '\+\%#\@ -1 58 | return 59 | elseif a:mode ==? '' 60 | call matchdelete(w:whitespace_match_id) 61 | return 62 | else 63 | let l:pattern = (a:mode ==# 'i') ? s:insert_pattern : s:normal_pattern 64 | if exists('w:whitespace_match_id') 65 | call matchdelete(w:whitespace_match_id) 66 | call matchadd('ExtraWhitespace', l:pattern, 10, w:whitespace_match_id) 67 | else 68 | highlight! link ExtraWhitespace SpellBad 69 | let w:whitespace_match_id = matchadd('ExtraWhitespace', l:pattern) 70 | endif 71 | endif 72 | endfunction 73 | 74 | function! s:WhitespaceErase(line1, line2) 75 | let l:save_cursor = getpos('.') 76 | silent! execute ':' . a:line1 . ',' . a:line2 . 's/' . s:ws_pattern . '//' 77 | call setpos('.', l:save_cursor) 78 | endfunction 79 | 80 | " Search for trailing whitespace 81 | function! s:WhitespaceJump(direction, from, to) 82 | let l:opts = 'wz' 83 | let l:until = a:to 84 | if a:direction < 1 85 | let l:opts .= 'b' 86 | let l:until = a:from 87 | endif 88 | 89 | " Full file, allow wrapping 90 | if a:from == 1 && a:to == line('$') 91 | let l:until = 0 92 | endif 93 | 94 | " Go to pattern 95 | let l:found = search(s:normal_pattern, l:opts, l:until) 96 | endfunction 97 | 98 | " vim: set ts=2 sw=2 tw=80 noet : 99 | ` 100 | --------------------------------------------------------------------------------