From 6955e90e0733fffb6d8623d93ecc5e40d34fb778 Mon Sep 17 00:00:00 2001 From: captain Date: Mon, 7 Oct 2024 15:29:32 +0800 Subject: [PATCH] first commit --- UltiSnips/README.md | 1 + UltiSnips/all.snippets | 7 + UltiSnips/c.snippets | 13 + UltiSnips/cs.snippets | 11 + UltiSnips/dart.snippets | 571 +++++++++++++++++++++++++++ UltiSnips/go.snippets | 84 ++++ UltiSnips/java.snippets | 4 + UltiSnips/javascript.snippets | 444 +++++++++++++++++++++ UltiSnips/lua.snippets | 11 + UltiSnips/markdown.snippets | 10 + UltiSnips/python.snippets | 8 + UltiSnips/racket.snippets | 9 + UltiSnips/swift.snippets | 4 + UltiSnips/tex.snippets | 9 + UltiSnips/typescriptreact.snippets | 38 ++ UltiSnips/vim.snippets | 7 + init.lua | 26 ++ lua/core/cursor.lua | 419 ++++++++++++++++++++ lua/core/init.lua | 81 ++++ lua/core/keymap.lua | 191 +++++++++ lua/core/markdown_table_format.lua | 197 +++++++++ lua/core/md-snippets.lua | 25 ++ lua/lazy/index.lua | 80 ++++ lua/lazy/plugins/autocomplete.lua | 203 ++++++++++ lua/lazy/plugins/bufferline.lua | 25 ++ lua/lazy/plugins/closebuffer.lua | 23 ++ lua/lazy/plugins/color.lua | 7 + lua/lazy/plugins/comment.lua | 21 + lua/lazy/plugins/filemanager.lua | 62 +++ lua/lazy/plugins/flutter.lua | 17 + lua/lazy/plugins/fold.lua | 28 ++ lua/lazy/plugins/fun.lua | 7 + lua/lazy/plugins/gitstatus.lua | 11 + lua/lazy/plugins/image.lua | 43 ++ lua/lazy/plugins/imgclip.lua | 30 ++ lua/lazy/plugins/indent.lua | 29 ++ lua/lazy/plugins/indentrainbow.lua | 43 ++ lua/lazy/plugins/jump.lua | 19 + lua/lazy/plugins/lspconfig.lua | 89 +++++ lua/lazy/plugins/markdownpreview.lua | 16 + lua/lazy/plugins/minifiles.lua | 21 + lua/lazy/plugins/outline.lua | 30 ++ lua/lazy/plugins/pairs.lua | 19 + lua/lazy/plugins/rainbow.lua | 21 + lua/lazy/plugins/stickyScroll.lua | 23 ++ lua/lazy/plugins/suda.lua | 4 + lua/lazy/plugins/surround.lua | 21 + lua/lazy/plugins/tabular.lua | 5 + lua/lazy/plugins/telescope.lua | 52 +++ lua/lazy/plugins/themes.lua | 253 ++++++++++++ lua/lazy/plugins/translate.lua | 13 + lua/lazy/plugins/treesitter.lua | 40 ++ lua/lazy/plugins/whichkey.lua | 17 + lua/lazy/plugins/winbar.lua | 73 ++++ root_init.lua | 18 + snippets/dart.snippets | 31 ++ snippets/go.snippets | 27 ++ snippets/gomod.snippets | 5 + snippets/lua.snippets | 18 + snippets/markdown.snippets | 20 + snippets/python.snippets | 7 + 61 files changed, 3641 insertions(+) create mode 100644 UltiSnips/README.md create mode 100644 UltiSnips/all.snippets create mode 100644 UltiSnips/c.snippets create mode 100644 UltiSnips/cs.snippets create mode 100644 UltiSnips/dart.snippets create mode 100644 UltiSnips/go.snippets create mode 100644 UltiSnips/java.snippets create mode 100644 UltiSnips/javascript.snippets create mode 100644 UltiSnips/lua.snippets create mode 100644 UltiSnips/markdown.snippets create mode 100644 UltiSnips/python.snippets create mode 100644 UltiSnips/racket.snippets create mode 100644 UltiSnips/swift.snippets create mode 100644 UltiSnips/tex.snippets create mode 100644 UltiSnips/typescriptreact.snippets create mode 100644 UltiSnips/vim.snippets create mode 100644 init.lua create mode 100644 lua/core/cursor.lua create mode 100644 lua/core/init.lua create mode 100644 lua/core/keymap.lua create mode 100644 lua/core/markdown_table_format.lua create mode 100644 lua/core/md-snippets.lua create mode 100644 lua/lazy/index.lua create mode 100644 lua/lazy/plugins/autocomplete.lua create mode 100644 lua/lazy/plugins/bufferline.lua create mode 100644 lua/lazy/plugins/closebuffer.lua create mode 100644 lua/lazy/plugins/color.lua create mode 100644 lua/lazy/plugins/comment.lua create mode 100644 lua/lazy/plugins/filemanager.lua create mode 100644 lua/lazy/plugins/flutter.lua create mode 100644 lua/lazy/plugins/fold.lua create mode 100644 lua/lazy/plugins/fun.lua create mode 100644 lua/lazy/plugins/gitstatus.lua create mode 100644 lua/lazy/plugins/image.lua create mode 100644 lua/lazy/plugins/imgclip.lua create mode 100644 lua/lazy/plugins/indent.lua create mode 100644 lua/lazy/plugins/indentrainbow.lua create mode 100644 lua/lazy/plugins/jump.lua create mode 100644 lua/lazy/plugins/lspconfig.lua create mode 100644 lua/lazy/plugins/markdownpreview.lua create mode 100644 lua/lazy/plugins/minifiles.lua create mode 100644 lua/lazy/plugins/outline.lua create mode 100644 lua/lazy/plugins/pairs.lua create mode 100644 lua/lazy/plugins/rainbow.lua create mode 100644 lua/lazy/plugins/stickyScroll.lua create mode 100644 lua/lazy/plugins/suda.lua create mode 100644 lua/lazy/plugins/surround.lua create mode 100644 lua/lazy/plugins/tabular.lua create mode 100644 lua/lazy/plugins/telescope.lua create mode 100644 lua/lazy/plugins/themes.lua create mode 100644 lua/lazy/plugins/translate.lua create mode 100644 lua/lazy/plugins/treesitter.lua create mode 100644 lua/lazy/plugins/whichkey.lua create mode 100644 lua/lazy/plugins/winbar.lua create mode 100644 root_init.lua create mode 100644 snippets/dart.snippets create mode 100644 snippets/go.snippets create mode 100644 snippets/gomod.snippets create mode 100644 snippets/lua.snippets create mode 100644 snippets/markdown.snippets create mode 100644 snippets/python.snippets diff --git a/UltiSnips/README.md b/UltiSnips/README.md new file mode 100644 index 0000000..05101bf --- /dev/null +++ b/UltiSnips/README.md @@ -0,0 +1 @@ +# These are custom snippets that suit my needs diff --git a/UltiSnips/all.snippets b/UltiSnips/all.snippets new file mode 100644 index 0000000..f16483c --- /dev/null +++ b/UltiSnips/all.snippets @@ -0,0 +1,7 @@ +global !p +from vimsnippets import get_comment_format +endglobal + +snippet todo "TODO comment" bw +`!p snip.rv=get_comment_format()[0]` TODO: ${2:Something} $0${3: <${4:`!v strftime('%m/%d, %Y')`}${5:, `!v g:snips_author`}>} `!p snip.rv=get_comment_format()[2]` +endsnippet diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets new file mode 100644 index 0000000..fd516a4 --- /dev/null +++ b/UltiSnips/c.snippets @@ -0,0 +1,13 @@ +snippet cm "Comment Section" +/* ${0} */ +endsnippet + +snippet st "printf" +printf(${0}); +endsnippet + +snippet inc "Includes" +#include +#include + +endsnippet diff --git a/UltiSnips/cs.snippets b/UltiSnips/cs.snippets new file mode 100644 index 0000000..b270afb --- /dev/null +++ b/UltiSnips/cs.snippets @@ -0,0 +1,11 @@ +snippet main "Public main class" +public static void Main() +{ + System.Console.WriteLine("Hello"); +} + +endsnippet + +snippet st "println" +System.Console.WriteLine(${0}); +endsnippet diff --git a/UltiSnips/dart.snippets b/UltiSnips/dart.snippets new file mode 100644 index 0000000..c2b7fd7 --- /dev/null +++ b/UltiSnips/dart.snippets @@ -0,0 +1,571 @@ +snippet imat "Import Material" +import 'package:flutter/material.dart'; + +endsnippet + +snippet context "BuildContext" i +BuildContext context +endsnippet + +snippet fn "Async Function" +void ${1:func}() { + ${0} +} + +endsnippet + +snippet afn "Async Function" +Future ${1:func}() async { + ${0} +} +endsnippet + +snippet wfunc "Widget Function" +Widget build${1:Widget}() { + return ${0:Container()}; +} +endsnippet + +snippet el "} else {" +} else { +endsnippet + +snippet elif "} else if () {" +} else if (${0}) { +endsnippet + +snippet msa "MaterialStateProperty.all" +MaterialStateProperty.all(${0}), +endsnippet + +snippet msr "MaterialStateProperty.resolveWith" +MaterialStateProperty.resolveWith<${1}>((states) => states.contains(MaterialState.pressed) ? null : null), +endsnippet + +snippet wh "Width and height" +width: ${1}, +height: ${0}, +endsnippet + +snippet iwh "Infinity Width and height" +width: double.infinity, +height: double.infinity, +endsnippet + +snippet oprs "onPressed" +final void Function() onPressed; +endsnippet + +snippet pa "Padding" +padding: EdgeInsets.only(${1:left: ${2:0}}${3:, right: ${4:0}}${5:, top: ${6:0}}${7:, bottom: ${8:0}}), +endsnippet + +snippet paa "Padding All" +padding: EdgeInsets.all(${1:8.0}), +endsnippet + +snippet pah "Padding Horizontal" +padding: EdgeInsets.symmetric(horizontal: ${0:0}), +endsnippet + +snippet pav "Padding Vertical" +padding: EdgeInsets.symmetric(vertical: ${0:0}), +endsnippet + +snippet pat "Padding Top" +padding: EdgeInsets.only(top: ${0:0}), +endsnippet + +snippet pab "Padding Bottom" +padding: EdgeInsets.only(bottom: ${0:0}), +endsnippet + +snippet pal "Padding Left" +padding: EdgeInsets.only(left: ${0:0}), +endsnippet + +snippet par "Padding Right" +padding: EdgeInsets.only(right: ${0:0}), +endsnippet + +snippet mar "Margin" +margin: EdgeInsets.only(${1:left: ${2:0}}${3:, right: ${4:0}}${5:, top: ${6:0}}${7:, bottom: ${8:0}}), +endsnippet + +snippet mara "Margin All" +margin: EdgeInsets.all(${1:8.0}), +endsnippet + +snippet marh "Margin Horizontal" +margin: EdgeInsets.symmetric(horizontal: ${0:0}), +endsnippet + +snippet marv "Margin Vertical" +margin: EdgeInsets.symmetric(vertical: ${0:0}), +endsnippet + +snippet mart "Margin Top" +margin: EdgeInsets.only(top: ${0:0}), +endsnippet + +snippet marb "Margin Bottom" +margin: EdgeInsets.only(bottom: ${0:0}), +endsnippet + +snippet marl "Margin Left" +margin: EdgeInsets.only(left: ${0:0}), +endsnippet + +snippet marr "Margin Right" +margin: EdgeInsets.only(right: ${0:0}), +endsnippet + +snippet marv "Margin Vertical" +margin: EdgeInsets.only(top: ${1:0}, bottom: ${1}),${0} +endsnippet + +snippet br "BorderRadius" +borderRadius: BorderRadius.all(Radius.circular(${0})), +endsnippet + +snippet sbr "Shape with BorderRadius" +shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(${0})), +), +endsnippet + +snippet dur "Duration" +duration: const Duration(milliseconds: ${0}), +endsnippet + +snippet dec "BoxDecoration" +decoration: BoxDecoration( + color: ${1}, +),${0} +endsnippet + +snippet ba "BorderRadius" +border: Border.all( + width: ${1}, + color: ${2}, +), +endsnippet + +snippet mai "MainAxis" +mainAxisAlignment: MainAxisAlignment.${0} +endsnippet + +snippet crs "CrossAxis" +crossAxisAlignment: CrossAxisAlignment.${0} +endsnippet + +snippet mainmin "MainAxisSize.min" +mainAxisSize: MainAxisSize.min +endsnippet + +snippet row "Row" +Row(children: [ + ${0} +]), +endsnippet + +snippet rowa "Row with alignment" +Row( + mainAxisAlignment: MainAxisAlignment.${1:start}, + crossAxisAlignment: CrossAxisAlignment.${2:start}, + children: [ + ${0} + ], +), +endsnippet + +snippet col "Column" +Column(children: [ + ${0} +]), +endsnippet + +snippet cola "Column with alignment" +Column( + mainAxisAlignment: MainAxisAlignment.${1:start}, + crossAxisAlignment: CrossAxisAlignment.${2:start}, + children: [ + ${0} + ], +), +endsnippet + +snippet sta "Stack" +Stack(children: [ + ${0} +]), +endsnippet + +snippet cs "const SizedBox()" +const SizedBox()${0} +endsnippet + +snippet co "Container" +Container()${0} +endsnippet + +snippet con "Container" +Container( + child: ${0}, +) +endsnippet + +snippet exp "Expanded" +Expanded( + child: ${0}, +), +endsnippet + +snippet flx "Flexible" +Flexible( + child: ${0}, +), +endsnippet + +snippet cons "Container Sized" +Container( + width: ${1}, + height: ${2}, + child: ${0}, +) +endsnippet + +snippet cen "Center" +Center(child: ${0}) +endsnippet + +snippet t "Text" +Text("${1}"),${0} +endsnippet + +snippet ts "Text with text style" +Text(${1}, style: ${2}),${0} +endsnippet + +snippet rts "Rich Text with text style" +RichText( + text: TextSpan(children: [ + TextSpan(text: ${1}, style: ${2}),${0} + ]), +), +endsnippet + +snippet ss "TextStyle" +TStyle(c: ${1}, s: ${2:14}, w: F.w${3:5})${0} +endsnippet + + +snippet nbuilder "NotifierBuilder" +NotifierBuilder( + notifier: null, + builder: (context) { + return Container(); + }, +) +endsnippet + +snippet sw "SizedBox with width" +const SizedBox(width: ${1}),${0} +endsnippet + +snippet sh "SizedBox with height" +const SizedBox(height: ${1}),${0} +endsnippet + +snippet swh "SizedBox with width and height" +SizedBox(width: ${1}, height: ${2}),${0} +endsnippet + +snippet scaf "Scaffold" +Scaffold( + appBar: AppBar( + title: Text('${1:Title}'), + ), + body: ${2:Container()}${0}, +); +endsnippet + +# snippet sf "New Stateful Widget" b +# class ${1:name} extends StatefulWidget { +# ${1:name}({super.key}); +# @override +# _${1/([A-Za-z_]+).*/$1/}State createState() => _${1/([A-Za-z_]+).*/$1/}State(); +# } +# class _${1/([A-Za-z_]+).*/$1/}State extends State<${1/([A-Za-z_]+).*/$1/}> { +# @override +# Widget build(context) { +# return ${2:Container()}; +# } +# } +# endsnippet + +snippet sf "New Stateful Widget" b +class ${1:MyState} extends StatefulWidget { + $1({super.key}); + @override + _$1State createState() => _$1State(); +} +class _$1State extends State<$1> { + @override + Widget build(context) { + return ${2:Container()}; + } +} +endsnippet + +snippet sl "New Stateless Widget" b +class ${1:name} extends StatelessWidget { + ${1:name}({super.key}); + @override + Widget build(context) { + return ${2:Container()}; + } +} +endsnippet + +snippet wt "Colors.white" +color: colorWhite, +endsnippet + +snippet inits "initState" +@override +void initState() { + ${0} + super.initState(); +} +endsnippet + +snippet dispose "dispose" +@override +void dispose() { + ${0:} + super.dispose(); +} +endsnippet + +snippet listv "ListView.builder" +ListView.builder( + itemCount: ${1:1}, + itemBuilder: (context, index) { + return ${2:Container()}; + }, +) +endsnippet + +snippet future "Future Builder" +FutureBuilder( + future: ${1:Future}, + initialData: ${2:InitialData}, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) + return ${3:Container();} + return ${4:Container();} + }, +) +endsnippet + +snippet stream "Stream Builder" +StreamBuilder<${1:dynamic}>( + stream: ${2:yourStream}, + builder: (context, snapshot) { + if (snapshot.hasData) { + // TODO: do something with the data + return ${3:Container()}; + } else if (snapshot.hasError) { + // TODO: do something with the error + return ${4:Text(snapshot.error.toString())}; + } + // TODO: the data is not ready, show a loading indicator + return ${5:Center(child: CircularProgressIndicator())}; + }, +), +endsnippet + +snippet try "try catch" +try { + ${0} +} catch (e, stack) { + print(e); + print(stack); +} +endsnippet + +snippet for "standard for loop without brackets" +for (var ${1:i} = 0; ${1:i} < ${2:n}; ++${1:i}) + ${3:// TODO} +endsnippet + +snippet forr "standard for loop" +for (var ${1:i} = 0; ${1:i} < ${2:n}; ++${1:i}) { + ${3:// TODO} +} +endsnippet + +snippet fori "For in loop" +for (var ${1:item} in ${2:object}) { + ${3:// TODO} +} +endsnippet + +snippet ssm "Multi-line Set State" +setState(() { + ${1:// TODO} +}); +endsnippet + +snippet sss "Single-line Set State" +setState(() => ${1:/* TODO */} ); +endsnippet + +snippet sst "Empty Set State" +setState(() {})${0} +endsnippet + +snippet rf "Request focus" +FocusScope.of(context).requestFocus(${1:FocusNode()})${0} +endsnippet + +snippet rfn "Request focusnode (new)" +FocusScope.of(context).requestFocus(FocusNode()); +endsnippet + +snippet push "Navigator push" +Navigator.of(context).push( + MaterialPageRoute(builder: (context) => ${1:Page()}), +)${0} +endsnippet + +snippet pop "Navigator pop" +Navigator.of(context).pop(${1})${0} +endsnippet + +snippet rmb "RawMaterialButton" +RawMaterialButton( + elevation: ${1:0}, + onPressed: () {}, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(${2:5})), + ), + fillColor: ${3:Colors.transparent}, + child: ${5:Container()}, +), +endsnippet + +snippet mo "Get MediaQuery" +MediaQuery.of(context)${0} +endsnippet + +snippet st "print();" +print(${0}); +endsnippet + +snippet sbj "Behavior subject" +Stream<${1:int}> get ${2:my}Stream => _${2:my}Subject.stream; +BehaviorSubject<${1}> _${2:my}Subject; +_${2:my}Subject = BehaviorSubject<${1}>(); +endsnippet + +snippet f "Function" +() => +endsnippet + +snippet adelay "await Future.delayed" +await Future.delayed(const Duration(milliseconds: ${1:300})); +endsnippet + +snippet delay "Future.delayed" +Future.delayed(const Duration(milliseconds: ${1:300})).then((_) { + ${2} +}); +endsnippet + +snippet now "DateTime.now()" +DateTime.now() +endsnippet + +snippet rt "required this." +required this.${1}, ${0} +endsnippet + +snippet posr "Positioned right" +Positioned( + top: ${1:0}, + right: ${2:0}, + bottom: ${3:0}, + child: ${0:Container()}, +), +endsnippet + +snippet posl "Positioned left" +Positioned( + top: ${1:0}, + left: ${2:0}, + bottom: ${3:0}, + child: ${0:Container()}, +), +endsnippet + +snippet post "Positioned top" +Positioned( + top: ${1:0}, + left: ${2:0}, + right: ${3:0}, + child: ${0:Container()}, +), +endsnippet + +snippet posb "Positioned bottom" +Positioned( + bottom: ${1:0}, + left: ${2:0}, + right: ${3:0}, + child: ${0:Container()}, +), +endsnippet + +snippet postr "Positioned top right" +Positioned( + top: ${1:0}, + right: ${2:0}, + child: ${3:Container()}, +), +endsnippet + +snippet posbl "Positioned bottom left" +Positioned( + bottom: ${1:0}, + left: ${2:0}, + child: ${3:Container()}, +), +endsnippet + +snippet posbr "Positioned bottom right" +Positioned( + bottom: ${1:0}, + right: ${2:0}, + child: ${3:Container()}, +), +endsnippet + +snippet postl "Positioned top left" +Positioned( + top: ${1:0}, + left: ${2:0}, + child: ${3:Container()}, +), +endsnippet + +snippet fa "fix add type" +// TYPEADD +endsnippet + +snippet .f "fix add type" i +.forEach((${1:item}) { + ${0:// TODO} +}); +endsnippet diff --git a/UltiSnips/go.snippets b/UltiSnips/go.snippets new file mode 100644 index 0000000..2f9f2f7 --- /dev/null +++ b/UltiSnips/go.snippets @@ -0,0 +1,84 @@ +snippet checke "Check Error" +if err != nil { + return err +} +${0} +endsnippet + +snippet no "utils.NoError" +if utils.NoError(err) { + ${0} +} +endsnippet + +snippet forr "For loop range" +for _, ${1:thing} := range ${2:things} { + ${3://TODO} +} +endsnippet + +snippet fori "For loop i" +for i := 0; i < n; i++ { + ${1://TODO} +} +endsnippet + +snippet re "Return Error if any" +if err != nil { + return err +} +${0} +endsnippet + +snippet ie "Check Error" +if err != nil { + panic(err) +} +${0} +endsnippet + +snippet st "Println" +fmt.Println(${1})${0} +endsnippet + +snippet lt "Log Println" +log.Println(${1})${0} +endsnippet + +snippet sf "Printf" +fmt.Printf("${1}\n")${0} +endsnippet + +snippet lf "Log Printf" +log.Printf("${1}\n")${0} +endsnippet + +snippet fn "Function" +func ${1:function}() { + ${0: // todo} +} +endsnippet + +snippet lt "Log Println" +log.Println(${1})${0} +endsnippet + +snippet start "Starting code" +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("hello") +} +endsnippet + +snippet cq "Current Question" +app.result.questions[app.curResultIndex]${0} +endsnippet + +snippet fa "fix add type" +// TYPEADD +endsnippet diff --git a/UltiSnips/java.snippets b/UltiSnips/java.snippets new file mode 100644 index 0000000..7b79451 --- /dev/null +++ b/UltiSnips/java.snippets @@ -0,0 +1,4 @@ +snippet st "System.out.Println();" +System.out.println(${0}); +endsnippet + diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets new file mode 100644 index 0000000..b46e209 --- /dev/null +++ b/UltiSnips/javascript.snippets @@ -0,0 +1,444 @@ +snippet st "console.log" +console.log(${0}); +endsnippet + +snippet fl "Firebase Function Log" +/*LOG*/ functions.logger.log(${0}); +endsnippet + +snippet f "Arrow Function" +(${1:arg}) => { + ${0} +} +endsnippet + +snippet fn "Empty Function" +function ${1:functionName}() { + ${0} +} +endsnippet + +snippet cf "Constant Function" +const ${1:funcName} = () => { + ${0} +} +endsnippet + +snippet ef "Export Function" +export function ${1:functionName}() { + ${0} +} +endsnippet + +snippet eaf "Export Async Function" +export async function ${1:functionName}() { + ${0} +} +endsnippet + +snippet eafa "Export Async Function With Args" +const ${1}DefaultArgs = { + ${2} +}; +export async function ${1:functionName}(options = ${1}DefaultArgs) { + options = { ...${1}DefaultArgs, ...options }; + ${0:// todo} +} +endsnippet + +snippet ssr "NextJS ServerSide Rendering" +export async function getServerSideProps() { + return { + props: { + // + }, + }; +} +endsnippet + +snippet ssg "NextJS ServerSide Generation" +export async function getStaticProps() { + return { + props: { + // + }, + }; +} +endsnippet + +snippet rs "res.status" +res.status(${1:200}).send("${2:text}")${0} +endsnippet + +snippet af "Async Arrow Function" +async (${1}) => { + ${0} +} +endsnippet + +snippet afn "Async Function" +async function ${1:FunctionName}() { + ${0} +} +endsnippet + +snippet try "Try Catch" +try { + // +} catch (e) { + console.error(e); +} +endsnippet + +snippet eh "Error Handler" +return await errorHandler(async () => { + ${0:// Todo} +}); +endsnippet + +snippet c "Comment Block" +/* + * ${0} +*/ +endsnippet + +snippet pm "@param" +@param ${1:parameter}: ${0:description} +endsnippet + +# React & JSX + +snippet t "Tag" +<${1:div}> + ${2} + +${0} +endsnippet + +snippet ta "Tag with Attributes" +<${1:div} ${2:className=""}> + ${3} + +${0} +endsnippet + +snippet ti "Tag Inline" +<${1} /> +${0} +endsnippet + +snippet br "
" +
+endsnippet + + +snippet rrcc "React Redux Class Component" b +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import styles from './${2:$1}.css'; + +class ${1:`!v expand('%:t:r')`} extends Component { + static propTypes = { + children: PropTypes.node, + className: PropTypes.string, + dispatch: PropTypes.func.isRequired, + }; + + constructor(props) { + super(props); + } + + render() { + return ( +
+ $3 +
+ ); + } +} + +function mapStateToProps(state) { + return {}; +} + +export default connect(mapStateToProps)($1); +endsnippet + +snippet rcc "React Class Component" b +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import styles from './${2:$1}.css'; + +class ${1:`!v expand('%:t:r')`} extends Component { + static propTypes = { + ${2:children: PropTypes.node, + className: PropTypes.string,} + }; + + constructor(props) { + super(props); + } + + render() { + return ( + <${3:div} className={styles.base}> + $0 + + ); + } +} + +export default $1; +endsnippet + +snippet rfc "React Functional Component" b +import React from 'react'; +import PropTypes from 'prop-types'; +import styles from './${2:$1}.css'; + +function ${1:`!v expand('%:t:r')`}({ $3 }) { + return ( + <${5:div} className={styles.base}> + $0 + + ); +} + +$1.defaultProps = {$4}; + +$1.propTypes = {`!p +props = t[3] +if props: + snip >> 1 + for prop in props.split(', '): + snip += prop + ': PropTypes.any,' +` +}; + +export default $1; +endsnippet + +snippet rsc "React Styled Component" b +import styled from 'styled-components'; + +const ${1:`!v expand('%:t:r')`} = styled.${2:div}\` + $3 +\`; + +export default $1; +endsnippet + +snippet rsci "React Styled Component Interpolation" b +import styled, { css } from 'styled-components'; + +const ${1:`!v expand('%:t:r')`} = styled.${2:div}\`${props => css\` + ${3:${props.$4 && \` + $5 + \`}} +\`}\`; + +export default $1; +endsnippet + +snippet pp "Get Props" +${props => props.${1}}; +endsnippet + +snippet cn "className" +className="$1" +endsnippet + +snippet dp "Default Props" b +${1:`!v expand('%:t:r')`.}defaultProps = { + $2 +}; +endsnippet + +snippet set "Set State" +this.setState({ + ${1}: ${2} +}); +endsnippet + +snippet props "Get Property" i +this.props.${1} +endsnippet + +snippet state "Get State" i +this.state.${1} +endsnippet + +snippet ref "Ref" i +ref={${1:ref} => { this.${2:name} = $1; }} +endsnippet + + +# Component Lifecycle +snippet cwm "Component Will Mount" b +componentWillMount() { + $1 +} +endsnippet + +snippet cdm "Component Did Mount" b +componentDidMount() { + $1 +} +endsnippet + +snippet cwrp "Component Will Receive Props" b +componentWillReceiveProps(nextProps) { + $1 +} +endsnippet + +snippet scup "Should Component Update" b +shouldComponentUpdate(nextProps, nextState) { + $1 +} +endsnippet + +snippet cwup "Component Will Update" b +componentWillUpdate(nextProps, nextState) { + $1 +} +endsnippet + +snippet cdup "Component Did Update" b +componentDidUpdate(prevProps, prevState) { + $1 +} +endsnippet + +snippet cwu "Component Will Unmount" b +componentWillUnmount() { + $1 +} +endsnippet + +snippet ren "Render" +render() { + return ${1:( + ${2:
${3}
} + );} +} +endsnippet + + +# PropTypes +snippet pt "PropTypes Definition" b +${1:`!v expand('%:t:r')`.}propTypes = { + ${2:className}: ${3:PropTypes.string}, +}; +endsnippet + +snippet pt.a "PropTypes Array" w +PropTypes.array${1:,} +endsnippet + +snippet pt.b "PropTypes Boolean" w +PropTypes.bool${1:,} +endsnippet + +snippet pt.f "PropTypes Function" w +PropTypes.func${1:,} +endsnippet + +snippet pt.n "PropTypes Number" w +PropTypes.number${1:,} +endsnippet + +snippet pt.o "PropTypes Object" w +PropTypes.object${1:,} +endsnippet + +snippet pt.s "PropType String" w +PropTypes.string${1:,} +endsnippet + +snippet pt.no "PropTypes Node" w +PropTypes.node${1:,} +endsnippet + +snippet pt.e "PropTypes Element" w +PropTypes.element${1:,} +endsnippet + +snippet pt.io "PropTypes instanceOf" w +PropTypes.instanceOf(${2:PropTypes.string})${1:,} +endsnippet + +snippet pt.one "PropTypes oneOf" w +PropTypes.oneOf(['$2'$3])${1:,} +endsnippet + +snippet pt.onet "PropTypes oneOfType" w +PropTypes.oneOfType([ + $2 +])${1:,} +endsnippet + +snippet pt.ao "PropTypes arrayOf" w +PropTypes.arrayOf(${2:PropTypes.string})${1:,} +endsnippet + +snippet pt.oo "PropTypes objectOf" w +PropTypes.objectOf(${2:PropTypes.string})${1:,} +endsnippet + +snippet pt.sh "PropTyes Shape" w +PropTypes.shape({ + $2 +})${1:,} +endsnippet + +snippet ir "isRequired" w +isRequired, +endsnippet + +snippet rs "React useState" +const [$1, set${1}] = useState(${0:''}) +endsnippet + +snippet test "Test" +test("${1:test}", ${2:async}() => { + ${3:// ...} +}); +endsnippet + +snippet ex "Expect" +expect(${1:1+1}).toBe(${2:2}); +endsnippet + + +snippet route "New Route" +import express from "express"; + +const ${1:some}Routes = express.Router(); + +${0:// TODO} + +export default ${1:some}Routes; +endsnippet + +snippet l "log" +log(${0}); +endsnippet + +snippet ehs "errorHandlers.silent" +await errorHandlers.silent(async () => { + ${0:// todo} +}); +endsnippet + +snippet eha "errorHandlers.safe" +await errorHandlers.safe({ + action: async () => { + ${0:// todo} + }, + teardown: async () => { + // todo + }, +}); +endsnippet diff --git a/UltiSnips/lua.snippets b/UltiSnips/lua.snippets new file mode 100644 index 0000000..33ce63d --- /dev/null +++ b/UltiSnips/lua.snippets @@ -0,0 +1,11 @@ +snippet f "Empty function" +function () + ${0} +end +endsnippet + +snippet conf "Config function" +config = function () + ${0} +end +endsnippet diff --git a/UltiSnips/markdown.snippets b/UltiSnips/markdown.snippets new file mode 100644 index 0000000..13b1f74 --- /dev/null +++ b/UltiSnips/markdown.snippets @@ -0,0 +1,10 @@ +snippet th "Table Heading" +| ${1:Key} | ${2:Value} | +|-|-| +${0} +endsnippet + +snippet tr "Table Row" +| ${1:Term} | ${2:Definition} | +${0} +endsnippet diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets new file mode 100644 index 0000000..05c5799 --- /dev/null +++ b/UltiSnips/python.snippets @@ -0,0 +1,8 @@ +snippet pri "print" +print(${0}) +endsnippet + +snippet main "__main__" +if __name__ == '__main__': + ${0} +endsnippet diff --git a/UltiSnips/racket.snippets b/UltiSnips/racket.snippets new file mode 100644 index 0000000..c8542e6 --- /dev/null +++ b/UltiSnips/racket.snippets @@ -0,0 +1,9 @@ +snippet fn "Function" +(define (${1:name} [${2:arg : Real}]) : Real + ${0:(+ 1 1)}) +endsnippet + +snippet st "print();" +(displayln ${0}) +endsnippet + diff --git a/UltiSnips/swift.snippets b/UltiSnips/swift.snippets new file mode 100644 index 0000000..7ee7b69 --- /dev/null +++ b/UltiSnips/swift.snippets @@ -0,0 +1,4 @@ +snippet st "print" +print(${0}) +endsnippet + diff --git a/UltiSnips/tex.snippets b/UltiSnips/tex.snippets new file mode 100644 index 0000000..884d236 --- /dev/null +++ b/UltiSnips/tex.snippets @@ -0,0 +1,9 @@ +# snip +snippet mid "\mid \mid" + \\mid ${1} \\mid ${0} +endsnippet + +snippet srt "\sqrt{}" + \\sqrt{${1}} ${0} +endsnippet + diff --git a/UltiSnips/typescriptreact.snippets b/UltiSnips/typescriptreact.snippets new file mode 100644 index 0000000..778db64 --- /dev/null +++ b/UltiSnips/typescriptreact.snippets @@ -0,0 +1,38 @@ +snippet ssg "NextJS ServerSide Generation" +export async function getStaticProps() { + return { + props: { + // + }, + }; +} +endsnippet + +snippet t "Tag" +<${1:div}> + ${2} + +${0} +endsnippet + +snippet ta "Tag with Attributes" +<${1:div} ${2:className=""}> + ${3} + +${0} +endsnippet + +snippet tn "Tag with class Names" +<${1:div} className="${2}"> + ${0} + +endsnippet + +snippet ti "Tag Inline" +<${1} /> +${0} +endsnippet + +snippet br "
" +
+endsnippet diff --git a/UltiSnips/vim.snippets b/UltiSnips/vim.snippets new file mode 100644 index 0000000..8ad7f02 --- /dev/null +++ b/UltiSnips/vim.snippets @@ -0,0 +1,7 @@ +snippet sec "Comment Section" +" === +" === ${1:New Section} +" === +${0} +endsnippet + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..0108993 --- /dev/null +++ b/init.lua @@ -0,0 +1,26 @@ + +-- 基本配置 +require("core.init") + +-- 基本键盘映射 +require("core.keymap") + +-- vim综合症 +require("core.cursor") + +-- markdown snippets +require("core.md-snippets") + +-- markdown table fromat +require("core.markdown_table_format") + +-- 安装的插件 +require("lazy.index") + +-- 本地备份配置方式如下 +-- # required +-- mv ~/.config/nvim{,.bak} +-- # optional but recommended +-- mv ~/.local/share/nvim{,.bak} +-- mv ~/.local/state/nvim{,.bak} +-- mv ~/.cache/nvim{,.bak} diff --git a/lua/core/cursor.lua b/lua/core/cursor.lua new file mode 100644 index 0000000..b7b54c9 --- /dev/null +++ b/lua/core/cursor.lua @@ -0,0 +1,419 @@ +-- === +-- === 光标移动neovide +-- === +if vim.g.neovide then + -- Put anything you want to happen only in Neovide here + vim.o.guifont = "Source Code Pro:h16" -- text below applies for VimScript + vim.g.neovide_transparency = 0.75 + -- 全屏,在i3和sway的配置中设置了并且速度更快 + vim.g.neovide_fullscreen = true +end + +-- === +-- === map function +-- === +local function mapkey(mode, lhs, rhs) + vim.api.nvim_set_keymap(mode, lhs, rhs, {noremap=true}) +end +-- interestind stess +mapkey('','[a','1k') +mapkey('','[r','2k') +mapkey('','[s','3k') +mapkey('','[t','4k') +mapkey('','[d','5k') +mapkey('','[h','6k') +mapkey('','[n','7k') +mapkey('','[e','8k') +mapkey('','[i','9k') +mapkey('','[ao','10k') +mapkey('','[aa','11k') +mapkey('','[ar','12k') +mapkey('','[as','13k') +mapkey('','[at','14k') +mapkey('','[ad','15k') +mapkey('','[ah','16k') +mapkey('','[an','17k') +mapkey('','[ae','18k') +mapkey('','[ai','19k') +mapkey('','[ro','20k') +mapkey('','[ra','21k') +mapkey('','[rr','22k') +mapkey('','[rs','23k') +mapkey('','[rt','24k') +mapkey('','[rd','25k') +mapkey('','[rh','26k') +mapkey('','[rn','27k') +mapkey('','[re','28k') +mapkey('','[ri','29k') +mapkey('','[so','30k') +mapkey('','[sa','31k') +mapkey('','[sr','32k') +mapkey('','[ss','33k') +mapkey('','[st','34k') +mapkey('','[sd','35k') +mapkey('','[sh','36k') +mapkey('','[sn','37k') +mapkey('','[se','38k') +mapkey('','[si','39k') +mapkey('','[to','40k') +mapkey('','[ta','41k') +mapkey('','[tr','42k') +mapkey('','[ts','43k') +mapkey('','[tt','44k') +mapkey('','[td','45k') +mapkey('','[th','46k') +mapkey('','[tn','47k') +mapkey('','[te','48k') +mapkey('','[ti','49k') +mapkey('','[do','50k') +mapkey('','[da','51k') +mapkey('','[dr','52k') +mapkey('','[ds','53k') +mapkey('','[dt','54k') +mapkey('','[dd','55k') +mapkey('','[dh','56k') +mapkey('','[dn','57k') +mapkey('','[de','58k') +mapkey('','[di','59k') +mapkey('','[ho','60k') +mapkey('','[ha','61k') +mapkey('','[hr','62k') +mapkey('','[hs','63k') +mapkey('','[ht','64k') +mapkey('','[hd','65k') +mapkey('','[hh','66k') +mapkey('','[hn','67k') +mapkey('','[he','68k') +mapkey('','[hi','69k') +mapkey('','[no','70k') +mapkey('','[na','71k') +mapkey('','[nr','72k') +mapkey('','[ns','73k') +mapkey('','[nt','74k') +mapkey('','[nd','75k') +mapkey('','[nh','76k') +mapkey('','[nn','77k') +mapkey('','[ne','78k') +mapkey('','[ni','79k') +mapkey('','[eo','80k') +mapkey('','[ea','81k') +mapkey('','[er','82k') +mapkey('','[es','83k') +mapkey('','[et','84k') +mapkey('','[ed','85k') +mapkey('','[eh','86k') +mapkey('','[en','87k') +mapkey('','[ee','88k') +mapkey('','[ei','89k') +mapkey('','[io','90k') +mapkey('','[ia','91k') +mapkey('','[ir','92k') +mapkey('','[is','93k') +mapkey('','[it','94k') +mapkey('','[id','95k') +mapkey('','[ih','96k') +mapkey('','[in','97k') +mapkey('','[ie','98k') +mapkey('','[ii','99k') +mapkey('','[aoo','100k') +mapkey('','[aoa','101k') +mapkey('','[aor','102k') +mapkey('','[aos','103k') +mapkey('','[aot','104k') +mapkey('','[aod','105k') +mapkey('','[aoh','106k') +mapkey('','[aon','107k') +mapkey('','[aoe','108k') +mapkey('','[aoi','109k') +mapkey('','[aao','110k') +mapkey('','[aaa','111k') +mapkey('','[aar','112k') +mapkey('','[aas','113k') +mapkey('','[aat','114k') +mapkey('','[aad','115k') +mapkey('','[aah','116k') +mapkey('','[aan','117k') +mapkey('','[aae','118k') +mapkey('','[aai','119k') +mapkey('','[aro','120k') +mapkey('','[ara','121k') +mapkey('','[arr','122k') +mapkey('','[ars','123k') +mapkey('','[art','124k') +mapkey('','[ard','125k') +mapkey('','[arh','126k') +mapkey('','[arn','127k') +mapkey('','[are','128k') +mapkey('','[ari','129k') +mapkey('','[aso','130k') +mapkey('','[asa','131k') +mapkey('','[asr','132k') +mapkey('','[ass','133k') +mapkey('','[ast','134k') +mapkey('','[asd','135k') +mapkey('','[ash','136k') +mapkey('','[asn','137k') +mapkey('','[ase','138k') +mapkey('','[asi','139k') +mapkey('','[ato','140k') +mapkey('','[ata','141k') +mapkey('','[atr','142k') +mapkey('','[ats','143k') +mapkey('','[att','144k') +mapkey('','[atd','145k') +mapkey('','[ath','146k') +mapkey('','[atn','147k') +mapkey('','[ate','148k') +mapkey('','[ati','149k') +mapkey('','[ado','150k') +mapkey('','[ada','151k') +mapkey('','[adr','152k') +mapkey('','[ads','153k') +mapkey('','[adt','154k') +mapkey('','[add','155k') +mapkey('','[adh','156k') +mapkey('','[adn','157k') +mapkey('','[ade','158k') +mapkey('','[adi','159k') +mapkey('','[aho','160k') +mapkey('','[aha','161k') +mapkey('','[ahr','162k') +mapkey('','[ahs','163k') +mapkey('','[aht','164k') +mapkey('','[ahd','165k') +mapkey('','[ahh','166k') +mapkey('','[ahn','167k') +mapkey('','[ahe','168k') +mapkey('','[ahi','169k') +mapkey('','[ano','170k') +mapkey('','[ana','171k') +mapkey('','[anr','172k') +mapkey('','[ans','173k') +mapkey('','[ant','174k') +mapkey('','[and','175k') +mapkey('','[anh','176k') +mapkey('','[ann','177k') +mapkey('','[ane','178k') +mapkey('','[ani','179k') +mapkey('','[aeo','180k') +mapkey('','[aea','181k') +mapkey('','[aer','182k') +mapkey('','[aes','183k') +mapkey('','[aet','184k') +mapkey('','[aed','185k') +mapkey('','[aeh','186k') +mapkey('','[aen','187k') +mapkey('','[aee','188k') +mapkey('','[aei','189k') +mapkey('','[aio','190k') +mapkey('','[aia','191k') +mapkey('','[air','192k') +mapkey('','[ais','193k') +mapkey('','[ait','194k') +mapkey('','[aid','195k') +mapkey('','[aih','196k') +mapkey('','[ain','197k') +mapkey('','[aie','198k') +mapkey('','[aii','199k') + + +mapkey("","'a","1j") +mapkey("","'r","2j") +mapkey("","'s","3j") +mapkey("","'t","4j") +mapkey("","'d","5j") +mapkey("","'h","6j") +mapkey("","'n","7j") +mapkey("","'e","8j") +mapkey("","'i","9j") +mapkey("","'ao","10j") +mapkey("","'aa","11j") +mapkey("","'ar","12j") +mapkey("","'as","13j") +mapkey("","'at","14j") +mapkey("","'ad","15j") +mapkey("","'ah","16j") +mapkey("","'an","17j") +mapkey("","'ae","18j") +mapkey("","'ai","19j") +mapkey("","'ro","20j") +mapkey("","'ra","21j") +mapkey("","'rr","22j") +mapkey("","'rs","23j") +mapkey("","'rt","24j") +mapkey("","'rd","25j") +mapkey("","'rh","26j") +mapkey("","'rn","27j") +mapkey("","'re","28j") +mapkey("","'ri","29j") +mapkey("","'so","30j") +mapkey("","'sa","31j") +mapkey("","'sr","32j") +mapkey("","'ss","33j") +mapkey("","'st","34j") +mapkey("","'sd","35j") +mapkey("","'sh","36j") +mapkey("","'sn","37j") +mapkey("","'se","38j") +mapkey("","'si","39j") +mapkey("","'to","40j") +mapkey("","'ta","41j") +mapkey("","'tr","42j") +mapkey("","'ts","43j") +mapkey("","'tt","44j") +mapkey("","'td","45j") +mapkey("","'th","46j") +mapkey("","'tn","47j") +mapkey("","'te","48j") +mapkey("","'ti","49j") +mapkey("","'do","50j") +mapkey("","'da","51j") +mapkey("","'dr","52j") +mapkey("","'ds","53j") +mapkey("","'dt","54j") +mapkey("","'dd","55j") +mapkey("","'dh","56j") +mapkey("","'dn","57j") +mapkey("","'de","58j") +mapkey("","'di","59j") +mapkey("","'ho","60j") +mapkey("","'ha","61j") +mapkey("","'hr","62j") +mapkey("","'hs","63j") +mapkey("","'ht","64j") +mapkey("","'hd","65j") +mapkey("","'hh","66j") +mapkey("","'hn","67j") +mapkey("","'he","68j") +mapkey("","'hi","69j") +mapkey("","'no","70j") +mapkey("","'na","71j") +mapkey("","'nr","72j") +mapkey("","'ns","73j") +mapkey("","'nt","74j") +mapkey("","'nd","75j") +mapkey("","'nh","76j") +mapkey("","'nn","77j") +mapkey("","'ne","78j") +mapkey("","'ni","79j") +mapkey("","'eo","80j") +mapkey("","'ea","81j") +mapkey("","'er","82j") +mapkey("","'es","83j") +mapkey("","'et","84j") +mapkey("","'ed","85j") +mapkey("","'eh","86j") +mapkey("","'en","87j") +mapkey("","'ee","88j") +mapkey("","'ei","89j") +mapkey("","'io","90j") +mapkey("","'ia","91j") +mapkey("","'ir","92j") +mapkey("","'is","93j") +mapkey("","'it","94j") +mapkey("","'id","95j") +mapkey("","'ih","96j") +mapkey("","'in","97j") +mapkey("","'ie","98j") +mapkey("","'ii","99j") +mapkey("","'aoo","100j") +mapkey("","'aoa","101j") +mapkey("","'aor","102j") +mapkey("","'aos","103j") +mapkey("","'aot","104j") +mapkey("","'aod","105j") +mapkey("","'aoh","106j") +mapkey("","'aon","107j") +mapkey("","'aoe","108j") +mapkey("","'aoi","109j") +mapkey("","'aao","110j") +mapkey("","'aaa","111j") +mapkey("","'aar","112j") +mapkey("","'aas","113j") +mapkey("","'aat","114j") +mapkey("","'aad","115j") +mapkey("","'aah","116j") +mapkey("","'aan","117j") +mapkey("","'aae","118j") +mapkey("","'aai","119j") +mapkey("","'aro","120j") +mapkey("","'ara","121j") +mapkey("","'arr","122j") +mapkey("","'ars","123j") +mapkey("","'art","124j") +mapkey("","'ard","125j") +mapkey("","'arh","126j") +mapkey("","'arn","127j") +mapkey("","'are","128j") +mapkey("","'ari","129j") +mapkey("","'aso","130j") +mapkey("","'asa","131j") +mapkey("","'asr","132j") +mapkey("","'ass","133j") +mapkey("","'ast","134j") +mapkey("","'asd","135j") +mapkey("","'ash","136j") +mapkey("","'asn","137j") +mapkey("","'ase","138j") +mapkey("","'asi","139j") +mapkey("","'ato","140j") +mapkey("","'ata","141j") +mapkey("","'atr","142j") +mapkey("","'ats","143j") +mapkey("","'att","144j") +mapkey("","'atd","145j") +mapkey("","'ath","146j") +mapkey("","'atn","147j") +mapkey("","'ate","148j") +mapkey("","'ati","149j") +mapkey("","'ado","150j") +mapkey("","'ada","151j") +mapkey("","'adr","152j") +mapkey("","'ads","153j") +mapkey("","'adt","154j") +mapkey("","'add","155j") +mapkey("","'adh","156j") +mapkey("","'adn","157j") +mapkey("","'ade","158j") +mapkey("","'adi","159j") +mapkey("","'aho","160j") +mapkey("","'aha","161j") +mapkey("","'ahr","162j") +mapkey("","'ahs","163j") +mapkey("","'aht","164j") +mapkey("","'ahd","165j") +mapkey("","'ahh","166j") +mapkey("","'ahn","167j") +mapkey("","'ahe","168j") +mapkey("","'ahi","169j") +mapkey("","'ano","170j") +mapkey("","'ana","171j") +mapkey("","'anr","172j") +mapkey("","'ans","173j") +mapkey("","'ant","174j") +mapkey("","'and","175j") +mapkey("","'anh","176j") +mapkey("","'ann","177j") +mapkey("","'ane","178j") +mapkey("","'ani","179j") +mapkey("","'aeo","180j") +mapkey("","'aea","181j") +mapkey("","'aer","182j") +mapkey("","'aes","183j") +mapkey("","'aet","184j") +mapkey("","'aed","185j") +mapkey("","'aeh","186j") +mapkey("","'aen","187j") +mapkey("","'aee","188j") +mapkey("","'aei","189j") +mapkey("","'aio","190j") +mapkey("","'aia","191j") +mapkey("","'air","192j") +mapkey("","'ais","193j") +mapkey("","'ait","194j") +mapkey("","'aid","195j") +mapkey("","'aih","196j") +mapkey("","'ain","197j") +mapkey("","'aie","198j") +mapkey("","'aii","199j") + diff --git a/lua/core/init.lua b/lua/core/init.lua new file mode 100644 index 0000000..ddc8f25 --- /dev/null +++ b/lua/core/init.lua @@ -0,0 +1,81 @@ +-- === +-- === Editor behavior +-- === + +-- 开启左侧数字 +vim.o.number = true +-- 始终隐藏字符(不依赖语法高亮),在 Markdown 文件中,粗体、斜体等标记字符可能会被隐藏 +vim.opt.conceallevel = 2 +-- 使用相对数 +vim.o.relativenumber = true +-- 高亮当前行 +vim.o.cursorline = true +-- 一行不能完全显示时自动换行 +vim.o.wrap = true +-- 在最后一行显示一些内容 +vim.o.showcmd = true +-- 命令模式显示补全菜单 +vim.o.wildmenu = true +-- /搜索时忽略大小写 +vim.o.ignorecase = true +-- /搜索时智能大小写 +vim.o.smartcase = true +-- 共享系统剪切 +vim.o.clipboard = 'unnamedplus' +-- 设置键 +vim.o.tabstop = 2 +vim.o.shiftwidth = 2 +vim.o.softtabstop = 2 +-- 随文件自动更改当前路径 +vim.o.autochdir = true +-- 在光标上方和下方保留的最小屏幕行数 +vim.o.scrolloff = 4 +-- 自动缩进 +vim.o.smartindent = true +-- 100毫秒没有输入文件将会自动保存交换文件 +vim.o.updatetime = 100 +-- 开启鼠标 +vim.o.mouse = 'a' +-- 开启颜色 +vim.o.termguicolors = true + +-- 设置编码格式 +vim.o.fileencodings = 'utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1' +vim.o.enc = 'utf8' + +-- 保存修改历史 +vim.o.swapfile = true +vim.o.undofile = true + +-- 保存折叠记录,在某些独立的窗口会报错 +-- vim.cmd 'au BufWinLeave * silent mkview' +-- vim.cmd 'au BufWinEnter * silent loadview' + +-- 打开文件时进入上次编辑的位置 +vim.cmd([[au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif]]) + +-- fcitx5在normal模式时自动切换为英文输入法,摘自fcitx5的archwiki +vim.cmd([[ +autocmd InsertLeave * :silent !fcitx5-remote -c +autocmd BufCreate * :silent !fcitx5-remote -c +autocmd BufEnter * :silent !fcitx5-remote -c +autocmd BufLeave * :silent !fcitx5-remote -c +]]) +-- 意为: +-- 当 进入插入模式 时 触发shell命令 fcitx-remote -c 关闭输入法,改为英文输入 +-- 当 创建Buf 时 触发shell命令 fcitx-remote -c 关闭输入法,改为英文输入 +-- 当 进入Buf 时 触发shell命令 fcitx-remote -c 关闭输入法, 改为英文输入 +-- 当 离开Buf 时 触发shell命令 fcitx-remote -c 关闭输入法, 改为英文输入 + +-- 开启高亮复制 +vim.cmd([[au TextYankPost * silent! lua vim.highlight.on_yank()]]) + + + + + + + + + + diff --git a/lua/core/keymap.lua b/lua/core/keymap.lua new file mode 100644 index 0000000..38d3bff --- /dev/null +++ b/lua/core/keymap.lua @@ -0,0 +1,191 @@ + +-- === +-- === map function +-- === + +local function mapkey(mode, lhs, rhs) + vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true }) +end + +local function mapcmd(key, cmd) + vim.api.nvim_set_keymap("n", key, ":" .. cmd .. "", { noremap = true }) +end + +local function maplua(key, txt) + vim.api.nvim_set_keymap("n", key, ":lua " .. txt .. "", { noremap = true }) +end + +-- === +-- === Basic Mappings +-- === + +-- leader键设置为空格,; as : +vim.g.mapleader = " " +mapkey("", ";", ":") + +-- 上/下一个搜索结果以及取消搜索结果高亮 +mapkey("", "=", "nzz") +mapkey("", "-", "Nzz") +mapcmd("", "nohlsearch") + +-- 保存和退出 +mapkey("", "S", ":wall") +mapkey("", "Q", ":q") + +-- 撤销与反撤销 +mapkey("", "l", "u") +mapkey("", "L", "") + +-- 插入 +mapkey("", "k", "i") +mapkey("", "K", "I") + +-- 以下两个映射默认了 +-- make Y to copy till the end of the line +-- mapkey('','Y','y$') + +-- make D to delete till the end of the line +-- mapkey('','D','d$') + +-- 折叠 +mapkey("", "o", "za") +mapkey("x", "o", "zf") +-- 读取保存的折叠 +-- mapkey("", "a", ":loadview") + +-- 打开lazygit,已用fm-nvim插件 +-- mapcmd('',':tabe:-tabmove:term lazygit') + +-- === +-- === Cursor Movement +-- === +-- New cursor movement (the default arrow keys are used for resizing windows) + +-- ^ +-- u +-- < n i > +-- e +-- v + +mapkey("", "n", "h") +mapkey("", "u", "k") +mapkey("", "e", "j") +mapkey("", "i", "l") + +-- faster navigation +mapkey("", "U", "5k") +mapkey("", "E", "5j") +mapkey("", "N", "0") +mapkey("", "I", "$") + +-- 更快的行导航 +mapkey("", "W", "5W") +mapkey("", "B", "5B") + +-- === +-- === Window management +-- === + +-- Disable the default s key +mapkey("", "s", "") + +-- 使用 + 新方向键 在分屏之间移动 +mapkey("", "w", "w") +mapkey("", "u", "k") +mapkey("", "e", "j") +mapkey("", "n", "h") +mapkey("", "i", "l") + +-- 使用s + 新方向键 进行分屏 +mapcmd("su", "set nosplitbelow:split:set splitbelow") +mapcmd("se", "set splitbelow:split") +mapcmd("sn", "set nosplitright:vsplit:set splitright") +mapcmd("si", "set splitright:vsplit") + +-- 使用方向键来调整窗口大小 +mapcmd("", "res +5") +mapcmd("", "res -5") +mapcmd("", "vertical resize-5") +mapcmd("", "vertical resize+5") + +-- 使分屏窗口上下分布 +mapkey("", "sh", "tK") +-- 使分屏窗口左右分布 +mapkey("", "sv", "tH") + +-- 按 + q 关闭当前窗口下方的窗口 +mapkey("", "q", "j:q") + +-- === +-- === Tab management +-- === + +-- tu创建新标签 +mapcmd("tu", "tabe") +-- 在标签之间移动,已用bufferline.nvim替代 +-- mapcmd('tn','-tabnext') +-- mapcmd('ti','+tabnext') + +-- 移动标签的位置 +-- mapcmd('tmn','-tabmove') +-- mapcmd('tmi','+tabmove') + +-- 关闭当前标签,已用close-buffers替代 +-- mapcmd('tq','tabc') + +-- === +-- === 批量缩进方法 +-- === +-- 操作为,esc从编辑模式退到命令模式,将光标移到需要缩进的行的行首,然后按shift+v,可以看到该行已被选中,且左下角提示为“可视” +-- 按键盘上的上下方向键,如这里按向下的箭头,选中所有需要批量缩进的行 +-- 按shift+>,是向前缩进一个tab值,按shift+<,则是缩回一个tab值 + +mapkey("x", "<", "", ">gv") +mapkey("x", "", "", ">gv") + +-- === +-- === Other useful stuff +-- === + +-- 打开一个终端窗口 +mapcmd("/", "set splitbelow:split:res +10:term") + +-- 按两下空格跳转到占位符<++>,并进入插入模式 +mapkey("", "", "/<++>:nohlsearchc4l") + +-- 拼写检查 +mapcmd("sc", "set spell!") + +-- 运行代码 + +vim.cmd([[ + au filetype dart noremap r :wall:term tmux a + au filetype python noremap r :wall:set splitbelow:sp:term python % + au filetype go noremap r :wall:set splitbelow:sp:term go run % + au filetype markdown noremap r :MarkdownPreview + au filetype rust noremap r :wall:set splitbelow:sp:term cargo run +]]) + + +-- === +-- === map function external environment +-- === + +-- 下面的函数给外部文件调用的 +-- 使用示例如下 +-- local map = require("core.keymap") +-- map:cmd('p','PasteImg') +local map = {} +function map:key(mode, lhs, rhs) + vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true }) +end +function map:cmd(key, cmd) + vim.api.nvim_set_keymap('n', key, ':' .. cmd .. '', { noremap = true }) +end +function map:lua(key, txt) + vim.api.nvim_set_keymap('n', key, ':lua ' .. txt .. '', { noremap = true }) +end + +return map diff --git a/lua/core/markdown_table_format.lua b/lua/core/markdown_table_format.lua new file mode 100644 index 0000000..e40dbb2 --- /dev/null +++ b/lua/core/markdown_table_format.lua @@ -0,0 +1,197 @@ +local table_line_char = { + { ':', ':' }, + { ':', '-' }, + { '-', ':' }, +} + +local table_line_char_insert = { + { ':', ':' }, + { ':', ' ' }, + { ' ', ':' }, +} + +---Check if the line_number is a markdown table +---@param line_number integer +---@return integer +local function check_markdown_table(line_number) + local line = vim.api.nvim_buf_get_lines(0, line_number - 1, line_number, true)[1] + return string.match(line, '^|.*|$') +end + +---Find the starting or ending line of the markdown table +---@param range integer 1 or -1 +---@return integer +local function find_markdown_table(range) + local cursor_line, end_line = vim.fn.line('.'), range == -1 and 1 or vim.fn.line('$') + + for l = cursor_line, end_line, range do + if not check_markdown_table(l) then + return l - range + end + if (range == -1 and l == 1) or (range == 1 and l == vim.fn.line('$')) then --- if in the first line or last line + return l + end + end + + return -1 +end + +---Get markdown table cells width +---@param table_contents table +---@return table integers +local function get_markdown_table_cells_width(table_contents) + local width = {} + for _ = 1, #table_contents[1], 1 do + table.insert(width, 0) + end + for i = 1, #table_contents, 1 do + if i ~= 2 then + for _, cell in ipairs(table_contents[i]) do + width[_] = math.max(width[_], cell and vim.fn.strdisplaywidth(cell) or 0) + end + end + end + return width +end + +---Update markdown table's cell contents +---@param table_contents table +---@param width table +---@return table +local function update_cell_contents(table_contents, width) + local function add_space(cell, num) -- add space at markdown table cell contents + cell = ' ' .. cell .. ' ' + cell = cell .. string.rep(' ', num) + return cell + end + + local function get_chars(cell) -- add chars at second line's left and right + local char_left = string.sub(cell, 1, 1) + local char_right = string.sub(cell, #cell) + return { char_left, char_right } + end + + local function get_table_line_char_id(chars) -- get chars at second line's left and right + for i, v in ipairs(table_line_char) do -- leave insert + if chars[1] == v[1] and chars[2] == v[2] then + return i + end + end + for i, v in ipairs(table_line_char_insert) do -- type "|" + if chars[1] == v[1] and chars[2] == v[2] then + return i + end + end + return 0 + end + + local function add_chars(cell, chars) -- update cell contents at second line's left and right + cell = chars[1] .. cell .. chars[2] + return cell + end + + for i, cells in ipairs(table_contents) do -- traversal markdown table lines and update + if i == 2 then + for j, _ in ipairs(cells) do + local chars = get_chars(table_contents[i][j]) + local id = get_table_line_char_id(chars) + table_contents[i][j] = string.rep('-', width[j]) + table_contents[i][j] = + add_chars(table_contents[i][j], id ~= 0 and table_line_char[id] or { '-', '-' }) + end + else + for j, cell in ipairs(cells) do + local change_length = width[j] - vim.fn.strdisplaywidth(cell) + table_contents[i][j] = add_space(cell, change_length) + end + end + end + + return table_contents +end + +---change every lines's tables to string +---@param table_contents table +---@return table +local function cells_to_table(table_contents) + local corner_char = '|' + for i = 1, #table_contents, 1 do + local line = corner_char + for j = 1, #table_contents[i], 1 do + line = line .. table_contents[i][j] .. corner_char + end + table_contents[i] = line + end + return table_contents +end + +local function format_markdown_table() + if not check_markdown_table(vim.fn.line('.')) then -- check if the curso is in markdown table + return + end + + -- find the staring line and ending line of markdown table + local table_start_line, table_end_line = find_markdown_table(-1), find_markdown_table(1) + local table_contents = {} + + ---change table to cells + ---@param line string + ---@param lnum integer + local function table_to_cells(line, lnum) + local table_cells = {} + for cell in line:gmatch('([^|]+)%|') do + if lnum ~= 1 then + cell = cell:match('^%s*(.-)%s*$') + end + table.insert(table_cells, cell) + end + table.insert(table_contents, table_cells) + end + + -- traversal markdown table lines + for lnum = table_start_line, table_end_line, 1 do + local line = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1] + table_to_cells(line, lnum - table_start_line) + end + + local width = get_markdown_table_cells_width(table_contents) + + table_contents = update_cell_contents(table_contents, width) + table_contents = cells_to_table(table_contents) + + vim.api.nvim_buf_set_lines(0, table_start_line - 1, table_end_line, true, table_contents) +end + +local function format_markdown_table_lines() + local current_line = vim.api.nvim_get_current_line() + local cursor_pos = vim.api.nvim_win_get_cursor(0) + local char = current_line:sub(cursor_pos[2], cursor_pos[2]) + if char == '|' and cursor_pos[2] ~= 1 then + format_markdown_table() + local length = #vim.api.nvim_get_current_line() + vim.api.nvim_win_set_cursor(0, { cursor_pos[1], length }) + end +end + +-- return { +-- format_markdown_table = format_markdown_table, +-- format_markdown_table_lines = format_markdown_table_lines, +-- } + +-- markdown_table_format +local au = vim.api.nvim_create_autocmd +local group = vim.api.nvim_create_augroup('KicamonGroup', {}) +au('InsertLeave', { + group = group, + pattern = '*.md', + callback = function() + format_markdown_table() + end, +}) +au('TextChangedI', { + group = group, + pattern = '*.md', + callback = function() + format_markdown_table_lines() + end, +}) diff --git a/lua/core/md-snippets.lua b/lua/core/md-snippets.lua new file mode 100644 index 0000000..5f5dac7 --- /dev/null +++ b/lua/core/md-snippets.lua @@ -0,0 +1,25 @@ +vim.cmd([[ +autocmd Filetype markdown inoremap ,f /<++>:nohlsearch"_c4l +autocmd Filetype markdown inoremap ,w /<++>:nohlsearch"_c5l +autocmd Filetype markdown inoremap ,n --- +autocmd Filetype markdown inoremap ,b ****<++>F*hi +autocmd Filetype markdown inoremap ,s ~~~~<++>F~hi +autocmd Filetype markdown inoremap ,i **<++>F*i +autocmd Filetype markdown inoremap ,d ``<++>F`i +autocmd Filetype markdown inoremap ,c ``````<++>3kA +autocmd Filetype markdown inoremap ,m - [ ] +autocmd Filetype markdown inoremap ,p ![](<++>) F[a +autocmd Filetype markdown inoremap ,a [](<++>) F[a +autocmd Filetype markdown inoremap ,1 # +autocmd Filetype markdown inoremap ,2 ## +autocmd Filetype markdown inoremap ,3 ### +autocmd Filetype markdown inoremap ,4 #### +autocmd Filetype markdown inoremap ,l -------- +]]) + +-- some modify +-- autocmd Filetype markdown inoremap ,c ```<++>```<++>4kA +-- autocmd Filetype markdown inoremap ,1 #<++>kA +-- autocmd Filetype markdown inoremap ,2 ##<++>kA +-- autocmd Filetype markdown inoremap ,3 ###<++>kA +-- autocmd Filetype markdown inoremap ,4 ####<++>kA diff --git a/lua/lazy/index.lua b/lua/lazy/index.lua new file mode 100644 index 0000000..2f3be26 --- /dev/null +++ b/lua/lazy/index.lua @@ -0,0 +1,80 @@ +-- delete follows if lazy install faild +-- ~/.local/share/nvim +-- ~/.local/state/nvim +-- ~/.cache/nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(vim.env.LAZY or lazypath) +-- 启动Lazy插件管理快捷键 +vim.keymap.set("n", "l", ":Lazy", { noremap = true }) +require("lazy").setup({ + -- cmp自动补全 + require("lazy.plugins.autocomplete").config, + -- lsp配置,全局的错误和警告提示,修复建议,重命名变量,格式化代码等等 + require("lazy.plugins.lspconfig"), + -- 顶部的winbar,可以鼠标点击 + require("lazy.plugins.winbar"), + -- 代码函数名称浏览时固定,`[c`可以跳转到上下文 + require("lazy.plugins.stickyScroll"), + -- fold折叠,根据treesitter来折叠,可以兼容我设置的o快捷键 + require("lazy.plugins.fold"), + -- 缩进彩虹和高亮 + require("lazy.plugins.indentrainbow"), + -- 粘贴图片 + require("lazy.plugins.imgclip"), + -- 图片预览 + require("lazy.plugins.image"), + -- 翻译插件gtranslate + require("lazy.plugins.translate"), + -- git状态 + require("lazy.plugins.gitstatus"), + -- outline大纲 + require("lazy.plugins.outline"), + -- treesitter语法高亮 + require("lazy.plugins.treesitter"), + -- rainbow彩虹括号 + require("lazy.plugins.rainbow"), + -- tabular,使用:Tab /=来格式化等号之类,特使符号要转义如:Tabularize /\/ + require("lazy.plugins.tabular"), + -- surround,各种对字符的包裹{} [] '' + require("lazy.plugins.surround"), + -- pairs对字符括号自动补全另一半 + require("lazy.plugins.pairs"), + -- flutter + require("lazy.plugins.flutter"), + -- markdown preview + require("lazy.plugins.markdownpreview"), + -- 底部状态栏+主题 themes + require("lazy.plugins.themes"), + -- 注释插件 + require("lazy.plugins.comment"), + -- 文件缓冲标签栏 + require("lazy.plugins.bufferline"), + -- explorer tree 文件列表,现在已经换成yazi fm-nvim启动joshuto ranger Lazygit + require("lazy.plugins.filemanager"), + -- minifiles也是文件管理器,功能较少 + require("lazy.plugins.minifiles"), + -- telescope模糊查找 + require("lazy.plugins.telescope"), + -- 代码雨插件 + require("lazy.plugins.fun"), + -- 呈现颜色值颜色 + require("lazy.plugins.color"), + -- sudo write + require("lazy.plugins.suda"), + -- jump使用flash.nvim插件实现,f单个字母时按f下一处,建议先esc退出再可视模式此时才可以继续使用f,斜杠粘贴整个单词查找的时候不好用 + -- require("lazy.plugins.jump"), + -- which-key使用多个字母快捷键停留时会提示 + -- require("lazy.plugins.whichkey"), + -- cw推荐的indent缩进线hlchunk,可以根据线条的款式来分辨缩进 + -- require("lazy.plugins.indent"), +}) diff --git a/lua/lazy/plugins/autocomplete.lua b/lua/lazy/plugins/autocomplete.lua new file mode 100644 index 0000000..94df626 --- /dev/null +++ b/lua/lazy/plugins/autocomplete.lua @@ -0,0 +1,203 @@ +local M = {} + +M.config = { + -- 使用nvim-cmp + 'hrsh7th/nvim-cmp', + after = "SirVer/ultisnips", + dependencies = { + { 'hrsh7th/cmp-nvim-lsp' }, + { 'hrsh7th/cmp-buffer' }, -- 缓冲区字符 + { 'hrsh7th/cmp-path' }, -- 补全路径 + { 'hrsh7th/cmp-cmdline' }, + { + "onsails/lspkind.nvim", -- 补全的图标 + lazy = false, + config = function() + require("lspkind").init() + end + }, + -- 代码片段来源 + { 'SirVer/ultisnips', dependencies = { "honza/vim-snippets" }, }, + { 'quangnguyen30192/cmp-nvim-ultisnips' }, + }, + + -- 使用coq_nvim补全 + -- 自动启动默认情况下无法运行,索性懒加载,或者见lazy.nvim中的init + -- { 'ms-jpq/coq_nvim', build = 'python3 -m coq deps', lazy = true }, + -- { 'ms-jpq/coq.artifacts' }, + -- { 'ms-jpq/coq.thirdparty' }, + + config = function() + -- Set up nvim-cmp. + local cmp = require 'cmp' + local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings") + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + -- 目录nvim/snippets/*: snippets using snipMate format + -- 目录nvim/UltiSnips/*: snippets using UltiSnips format + expand = function(args) + vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + }, + -- 和cw补全同一种风格样式 + window = { + completion = { + -- winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + col_offset = -3, + side_padding = 0, + }, + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50 })(entry, vim_item) + local strings = vim.split(kind.kind, "%s", { trimempty = true }) + kind.kind = " " .. (strings[1] or "") .. " " + kind.menu = " (" .. (strings[2] or "") .. ")" + + return kind + end, + }, + mapping = cmp.mapping.preset.insert({ + -- 召唤代码补全 + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.complete(), + -- 代码片段下一处位置 + [""] = cmp.mapping( + function() + cmp_ultisnips_mappings.compose { "expand", "jump_forwards" } (function() end) + end, + { "i", "s", --[[ "c" (to enable the mapping in command mode) ]] } + ), + -- 代码片段上一处位置 + [""] = cmp.mapping( + function(fallback) + cmp_ultisnips_mappings.jump_backwards(fallback) + end, + { "i", "s", --[[ "c" (to enable the mapping in command mode) ]] } + ), + -- 关闭代码补全,和telescope冲突 + [''] = cmp.mapping({ + i = function(fallback) + cmp.close() + fallback() + end + }), + [''] = cmp.mapping({ i = function(fallback) fallback() end }), + -- cw的回车配置不会默认补全第一个,在:输入命令的时候比较合适 + -- [''] = cmp.mapping({ + -- i = function(fallback) + -- if cmp.visible() and cmp.get_active_entry() then + -- cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + -- else + -- fallback() + -- end + -- end + -- }), + [''] = cmp.mapping({ + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + c = function(fallback) + if cmp.visible() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + else + fallback() + end + end + }), + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert }) + elseif has_words_before() then + cmp.complete() + else + cmp_ultisnips_mappings.compose { "jump_forwards" } (function() end) -- 添加跳转代码片段下一处的功能 + fallback() + end + end, + }), + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.select_prev_item({ behavior = cmp.SelectBehavior.Insert }) + else + fallback() + end + end, + }), + }), + sources = cmp.config.sources({ + { name = 'path' }, -- 本地路径补全 + { name = 'nvim_lsp' }, + { name = 'ultisnips' }, -- For ultisnips users. + }, { + { name = 'buffer' }, + }) + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + }, { + { name = 'buffer' }, + }) + }) + + -- 实现查找单词时根据上下文的补全,要输入多次回车,不太实用 + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + -- cmp.setup.cmdline({ '/', '?' }, { + -- mapping = cmp.mapping.preset.cmdline(), + -- sources = { + -- { name = 'buffer' } + -- } + -- }) + + -- cmdline模式下的补全,可以自动纠正大小写 + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + + + -- === + -- === 自动补全coq,更改跳转代码片段快捷键,和idea一样,可以使用ctrl+space召唤补全窗口 + -- === + -- 代码补全自定义片段放在~/.config/nvim/coq-user-snippets目录下面,格式和snipMate一致除了后缀名是snip结尾 + -- local lspconfig = require('lspconfig') + -- vim.g.coq_settings = { + -- auto_start = 'shut-up', + -- keymap = { + -- jump_to_mark = '', -- 跳转至代码片段的下一个占位 + -- pre_select = true -- 当有补全时预先选择第一个 + -- } + -- } + -- -- Enable some language servers with the additional completion capabilities offered by coq_nvim + -- -- 具体查看https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + -- local servers = { + -- -- 'lua_ls', + -- -- 'marksman', + -- 'dartls', + -- 'pyright', + -- 'clangd', + -- 'gopls', + -- } + -- for _, lsp in ipairs(servers) do + -- lspconfig[lsp].setup(require('coq').lsp_ensure_capabilities({ + -- -- on_attach = my_custom_on_attach, + -- })) + -- end + end +} + +return M diff --git a/lua/lazy/plugins/bufferline.lua b/lua/lazy/plugins/bufferline.lua new file mode 100644 index 0000000..d359eb1 --- /dev/null +++ b/lua/lazy/plugins/bufferline.lua @@ -0,0 +1,25 @@ +-- === +-- === 文件缓冲标签栏 +-- === + +local map = require("core.keymap") +-- 在标签之间移动 +map:cmd('tn', 'BufferLineCyclePrev') +map:cmd('ti', 'BufferLineCycleNext') + +-- 移动标签的位置 +map:cmd('tmn', 'BufferLineMovePrev') +map:cmd('tmi', 'BufferLineMoveNext') + +-- 关闭标签,貌似是neovim自带的,完整命令bdelete +map:cmd('tq', 'bd') + +return { + 'akinsho/bufferline.nvim', + version = "*",-- 安装最新的稳定版 + dependencies = 'kyazdani42/nvim-web-devicons', + config = function() + require("bufferline").setup {} + end +} + diff --git a/lua/lazy/plugins/closebuffer.lua b/lua/lazy/plugins/closebuffer.lua new file mode 100644 index 0000000..a298ae9 --- /dev/null +++ b/lua/lazy/plugins/closebuffer.lua @@ -0,0 +1,23 @@ +-- === +-- === 关闭缓冲区的标签 +-- === + +local map = require("core.keymap") +-- 关闭当前缓冲区标签 +map:cmd('tq', 'BDelete this') +-- 关闭除当前标签外的其他标签 +map:cmd('to', 'BDelete other') + +return { + 'kazhala/close-buffers.nvim', + config = function() + require('close_buffers').setup({ + filetype_ignore = {}, -- Filetype to ignore when running deletions + file_glob_ignore = {}, -- File name glob pattern to ignore when running deletions (e.g. '*.md') + file_regex_ignore = {}, -- File name regex pattern to ignore when running deletions (e.g. '.*[.]md') + preserve_window_layout = { 'this', 'nameless' }, -- Types of deletion that should preserve the window layout + next_buffer_cmd = nil, -- Custom function to retrieve the next buffer when preserving window layout + }) + end +} + diff --git a/lua/lazy/plugins/color.lua b/lua/lazy/plugins/color.lua new file mode 100644 index 0000000..8e508e4 --- /dev/null +++ b/lua/lazy/plugins/color.lua @@ -0,0 +1,7 @@ +return { + 'norcalli/nvim-colorizer.lua', + config = function() + require'colorizer'.setup() + end +} + diff --git a/lua/lazy/plugins/comment.lua b/lua/lazy/plugins/comment.lua new file mode 100644 index 0000000..4f45f76 --- /dev/null +++ b/lua/lazy/plugins/comment.lua @@ -0,0 +1,21 @@ +-- === +-- === 注释插件 +-- === + +-- 注释快捷键 +local map = require("core.keymap") +map:key("n", "cn", "kommentary_line_increase") +map:key("x", "cn", "kommentary_visual_increase") -- 选择模式下注释/反注释后退出该模式 +map:key("n", "cu", "kommentary_line_decrease") +map:key("x", "cu", "kommentary_visual_decrease") + +return { + 'b3nj5m1n/kommentary', + config = function() + -- 默认只使用单行注释 + require('kommentary.config').configure_language("default", { + prefer_single_line_comments = true, + }) + end +} + diff --git a/lua/lazy/plugins/filemanager.lua b/lua/lazy/plugins/filemanager.lua new file mode 100644 index 0000000..51b8fda --- /dev/null +++ b/lua/lazy/plugins/filemanager.lua @@ -0,0 +1,62 @@ +-- === +-- === explorer tree 文件列表 fm-nvim启动joshuto ranger Lazygit +-- === + +return { + "DreamMaoMao/yazi.nvim", -- 使用yazi替代joshuto和ranger,仍然使用fm-nvim来启动lazygit + dependencies = { + "nvim-telescope/telescope.nvim", + "nvim-lua/plenary.nvim", + 'is0n/fm-nvim',commit = 'ad7b80dc99cb8b14977f7ea233a9a299dc8879c0', -- 这个提交解决了joshuto无法启动的问题 + }, + keys = { + { "tt", "Yazi", desc = "Toggle Yazi" }, + { "", "Lazygit", desc = "Toggle Lazygit" }, + }, + config = function() + require('fm-nvim').setup{ + -- UI Options + ui = { + float = { + -- Floating window border (see ':h nvim_open_win') + border = "single", + -- Num from 0 - 1 for measurements + height = 0.9, + width = 0.8, + }, + }, + } + end +} + + +-- local map = require("core.keymap") +-- -- 打开文件树 +-- -- map:cmd('tt', "Ranger") +-- map:cmd('tt', "Joshuto") +-- -- 使用lazygit +-- map:cmd('', "Lazygit") + +-- return { +-- 'is0n/fm-nvim', +-- commit = 'ad7b80dc99cb8b14977f7ea233a9a299dc8879c0', -- 这个提交解决了joshuto无法启动的问题 +-- config = function() +-- require('fm-nvim').setup{ +-- -- UI Options +-- ui = { +-- float = { +-- -- Floating window border (see ':h nvim_open_win') +-- border = "single", +-- -- Num from 0 - 1 for measurements +-- height = 0.9, +-- width = 0.8, +-- }, +-- }, +-- -- Terminal commands used w/ file manager (have to be in your $PATH) +-- cmds = { +-- joshuto_cmd = "", +-- }, +-- } +-- end +-- } + diff --git a/lua/lazy/plugins/flutter.lua b/lua/lazy/plugins/flutter.lua new file mode 100644 index 0000000..50fd3e3 --- /dev/null +++ b/lua/lazy/plugins/flutter.lua @@ -0,0 +1,17 @@ +-- === +-- === flutter-tools +-- === + +return { + 'akinsho/flutter-tools.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + 'dart-lang/dart-vim-plugin', + }, + ft= {"dart"}, + lazy = true, + config = function() + require("flutter-tools").setup {} -- use defaults + end +} + diff --git a/lua/lazy/plugins/fold.lua b/lua/lazy/plugins/fold.lua new file mode 100644 index 0000000..cb03379 --- /dev/null +++ b/lua/lazy/plugins/fold.lua @@ -0,0 +1,28 @@ +-- ufo关于折叠的设置 +vim.o.foldcolumn = '0' -- '0' is not bad,其他的会有奇怪的数字 +vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value +vim.o.foldlevelstart = 99 +vim.o.foldenable = true +-- 设置可折叠处的样式 +vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]] + +return { + 'kevinhwang91/nvim-ufo', + dependencies = 'kevinhwang91/promise-async', + config = function() + -- Option 3: treesitter as a main provider instead + -- Only depend on `nvim-treesitter/queries/filetype/folds.scm`, + -- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()` + require('ufo').setup({ + provider_selector = function(bufnr, filetype, buftype) + return {'treesitter', 'indent'} + end + }) + -- 键盘映射,这里的按键会打开或折叠全部的可折叠位置 + vim.keymap.set('n', 'zR', require('ufo').openAllFolds) + vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) + vim.keymap.set('n', 'zr', require('ufo').openFoldsExceptKinds) + vim.keymap.set('n', 'zm', require('ufo').closeFoldsWith) -- closeAllFolds == closeFoldsWith(0) + end +} + diff --git a/lua/lazy/plugins/fun.lua b/lua/lazy/plugins/fun.lua new file mode 100644 index 0000000..8b3b556 --- /dev/null +++ b/lua/lazy/plugins/fun.lua @@ -0,0 +1,7 @@ +return { + "Eandrju/cellular-automaton.nvim", + keys = "rr", + config = function() + vim.keymap.set("n", "rr", "CellularAutomaton make_it_rain") + end, +} diff --git a/lua/lazy/plugins/gitstatus.lua b/lua/lazy/plugins/gitstatus.lua new file mode 100644 index 0000000..a7fc6f3 --- /dev/null +++ b/lua/lazy/plugins/gitstatus.lua @@ -0,0 +1,11 @@ +-- === +-- === git status/git状态 +-- === + +return { + 'lewis6991/gitsigns.nvim', + build = ':TSUpdate', + config = function() + require('gitsigns').setup() + end +} diff --git a/lua/lazy/plugins/image.lua b/lua/lazy/plugins/image.lua new file mode 100644 index 0000000..2745374 --- /dev/null +++ b/lua/lazy/plugins/image.lua @@ -0,0 +1,43 @@ +return { + "3rd/image.nvim", + dependencies = { + "vhyrro/luarocks.nvim", + priority = 1001, -- this plugin needs to run before anything else + opts = { + rocks = { "magick" }, + }, + }, + config = function() + -- default config + require("image").setup({ + backend = "kitty", + -- backend = "ueberzug", + integrations = { + markdown = { + enabled = true, + clear_in_insert_mode = false, -- 插入模式的时候隐藏 + download_remote_images = true, + only_render_image_at_cursor = false, + filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here + }, + neorg = { + enabled = true, + clear_in_insert_mode = true, + download_remote_images = true, + only_render_image_at_cursor = false, + filetypes = { "norg" }, + }, + }, + max_width = nil, + max_height = nil, + max_width_window_percentage = nil, + max_height_window_percentage = 50, + window_overlap_clear_enabled = true, -- 当打开重叠的浮动窗口时隐藏图片 + window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" }, + editor_only_render_when_focused = false, -- auto show/hide images when the editor gains/looses focus + tmux_show_only_in_active_window = false, -- auto show/hide images in the correct Tmux window (needs visual-activity off) + hijack_file_patterns = { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.avif" }, -- render image files as images when opened + }) + end +} + diff --git a/lua/lazy/plugins/imgclip.lua b/lua/lazy/plugins/imgclip.lua new file mode 100644 index 0000000..e292ff6 --- /dev/null +++ b/lua/lazy/plugins/imgclip.lua @@ -0,0 +1,30 @@ +-- 导入键盘映射的函数 +local map = require("core.keymap") +-- 获取当前文件名 +local filename = vim.fn.expand("%:t") +-- 删除扩展,并添加连加符号`.` +filename = string.gsub(filename, "%..*", "") .. "." +-- 使用空格+p来粘贴间剪切板的图片,然后输入想保存的图片名称, +-- 图片会自动保存在当前文件的同一目录下并调整为markdown格式 +map:cmd('p','PasteImage') + +return { + "HakonHarnes/img-clip.nvim", + event = "VeryLazy", + config = function() + require'img-clip'.setup { + default = { + dir_path = filename .. "assets", -- 图片保存路径:./文件名.assets + insert_mode_after_paste = false, -- 粘贴图片后不进入插入模式 + }, + filetypes = { + markdown = { + url_encode_path = true, ---@type boolean + template = "![$FILE_NAME_NO_EXT]($FILE_PATH)", -- 图片模板,中括号提示包含文件名 + download_images = false, ---@type boolean + }, + }, + } + end +} + diff --git a/lua/lazy/plugins/indent.lua b/lua/lazy/plugins/indent.lua new file mode 100644 index 0000000..6c9cccd --- /dev/null +++ b/lua/lazy/plugins/indent.lua @@ -0,0 +1,29 @@ +return { + "shellRaining/hlchunk.nvim", + -- 确保这个插件在lsp之后加载,不然会显示为蓝色的线 + event = "VeryLazy", + config = function() + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { pattern = "*", command = "EnableHL", }) + require('hlchunk').setup({ + chunk = { + enable = true, + use_treesitter = true, + style = { + { fg = "#806d9c" }, + }, + }, + indent = { + chars = { "│", "¦", "┆", "┊", }, + use_treesitter = false, + }, + -- 不显示缩进空白处的点点 + blank = { + enable = false, + }, + -- 让左侧数字高亮 + line_num = { + use_treesitter = true, + }, + }) + end +} diff --git a/lua/lazy/plugins/indentrainbow.lua b/lua/lazy/plugins/indentrainbow.lua new file mode 100644 index 0000000..a10e917 --- /dev/null +++ b/lua/lazy/plugins/indentrainbow.lua @@ -0,0 +1,43 @@ +return { + "lukas-reineke/indent-blankline.nvim", + dependencies = { + "TheGLander/indent-rainbowline.nvim", + }, + config = function() + opts = {} + -- Other blankline configuration here + require("ibl").setup(require("indent-rainbowline").make_opts(opts,{ + -- How transparent should the rainbow colors be. 1 is completely opaque, 0 is invisible. 0.07 by default + color_transparency = 0.15, + -- The 24-bit colors to mix with the background. Specified in hex. + -- { 0xffff40, 0x79ff79, 0xff79ff, 0x4fecec, } by default + colors = { 0xff0000, 0x00ff00, 0x0000ff, 0xffff40, 0x79ff79, 0xff79ff, 0x4fecec}, + })) + + -- local highlight = { + -- "RainbowRed", + -- "RainbowYellow", + -- "RainbowBlue", + -- "RainbowOrange", + -- "RainbowGreen", + -- "RainbowViolet", + -- "RainbowCyan", + -- } + + -- local hooks = require "ibl.hooks" + -- -- create the highlight groups in the highlight setup hook, so they are reset + -- -- every time the colorscheme changes + -- hooks.register(hooks.type.HIGHLIGHT_SETUP, function() + -- vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }) + -- vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }) + -- vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }) + -- vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }) + -- vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }) + -- vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }) + -- vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }) + -- end) + + -- require("ibl").setup { indent = { highlight = highlight } } + end +} + diff --git a/lua/lazy/plugins/jump.lua b/lua/lazy/plugins/jump.lua new file mode 100644 index 0000000..55ec1a0 --- /dev/null +++ b/lua/lazy/plugins/jump.lua @@ -0,0 +1,19 @@ +return { + "folke/flash.nvim", + event = "VeryLazy", + config = function() + require('flash').setup { + labels = "arstdhneioqwfpgjluyzxcvbkm", + modes = { + -- options used when flash is activated through + -- a regular search with `/` or `?` + search = { + -- when `true`, flash will be activated during regular search by default. + -- You can always toggle when searching with `require("flash").toggle()` + enabled = true, + }, + } + } + end +} + diff --git a/lua/lazy/plugins/lspconfig.lua b/lua/lazy/plugins/lspconfig.lua new file mode 100644 index 0000000..a986c20 --- /dev/null +++ b/lua/lazy/plugins/lspconfig.lua @@ -0,0 +1,89 @@ +return { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + dependencies = { + { 'neovim/nvim-lspconfig' }, + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + { + "MysticalDevil/inlay-hints.nvim", + event = "LspAttach", + config = function() + require("inlay-hints").setup() + end + } + }, + config = function() + -- 打算启用的语言服务列表 + local servers = { + 'marksman', -- 任意标题aw打开code action可以开头生成目录;超链接可以链接到同一个git项目的其他markdown文件#指定标题h可以预览 + 'lua_ls', + 'pyright', + 'gopls', + 'rust_analyzer', + } + -- lsp_zero的相关配置 + local lsp_zero = require('lsp-zero') + lsp_zero.on_attach(function(client, bufnr) + lsp_zero.default_keymaps({ buffer = bufnr }) + local opts = { buffer = bufnr } + vim.keymap.set('n', 'h', vim.lsp.buf.hover, opts) -- h显示提示文档 + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) -- gd跳转到定义的位置 + vim.keymap.set('n', 'go', vim.lsp.buf.type_definition, opts) -- go跳转到变量类型定义的位置 + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) -- gr跳转到引用了对应变量或函数的位置 + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) -- rn变量重命名 + vim.keymap.set({ 'n', 'x' }, 'f', function() vim.lsp.buf.format({ async = true }) end, opts) -- f进行代码格式化 + vim.keymap.set('n', 'aw', vim.lsp.buf.code_action, opts) -- aw可以在出现警告或错误的地方打开建议的修复方法 + vim.keymap.set('n', 'd', vim.diagnostic.open_float, opts) -- d浮动窗口显示所在行警告或错误信息 + vim.keymap.set('n', '-', vim.diagnostic.goto_prev, opts) -- -跳转到上一处警告或错误的地方 + vim.keymap.set('n', '=', vim.diagnostic.goto_next, opts) -- +跳转到下一处警告或错误的地方 + end) + -- “符号栏”是行号旁边的装订线中的一个空格。当一行中出现警告或错误时,Neovim 会向您显示一个字母 + lsp_zero.set_sign_icons({ + error = '✘', + warn = '▲', + hint = '⚑', + info = '»' + }) + -- 通过mason来自动安装语言服务器,可以在对应的代码运行LspIstall来安装可用的语言服务器 + require('mason').setup({}) + require('mason-lspconfig').setup({ + ensure_installed = servers -- 直接把前面的servers列表传递过来 + }) + -- cmp相关配置,通过for读取servers列表循环批量激活语言服务 + local capabilities = require("cmp_nvim_lsp").default_capabilities() + local lspconfig = require('lspconfig') + for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + -- on_attach = my_custom_on_attach, + capabilities = capabilities, + settings = { + gopls = { + hints = { -- gopls开启hints + rangeVariableTypes = true, + parameterNames = true, + constantValues = true, + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + functionTypeParameters = true, + } + }, + Lua = { + hint = { -- Lua开启hints + enable = true, -- necessary + }, + diagnostics = { + -- 忽略掉vim配置时一些全局变量语言服务器找不到的警告 + globals = { + 'vim', + 'require', + 'opts', + }, + }, + }, + }, + } + end + end +} diff --git a/lua/lazy/plugins/markdownpreview.lua b/lua/lazy/plugins/markdownpreview.lua new file mode 100644 index 0000000..c7264ce --- /dev/null +++ b/lua/lazy/plugins/markdownpreview.lua @@ -0,0 +1,16 @@ +-- === +-- === markdown preview +-- === + +return { + "iamcco/markdown-preview.nvim", + build = "cd app && npm install", + init = function() vim.g.mkdp_filetypes = { "markdown" } end, + ft = { "markdown" }, + lazy = true, + config = function() + -- 设置使用谷歌浏览器进行预览 + vim.g.mkdp_browser = '/usr/bin/google-chrome-stable' + end +} + diff --git a/lua/lazy/plugins/minifiles.lua b/lua/lazy/plugins/minifiles.lua new file mode 100644 index 0000000..a34d9ee --- /dev/null +++ b/lua/lazy/plugins/minifiles.lua @@ -0,0 +1,21 @@ +return { + 'echasnovski/mini.files', + config = function() + require('mini.files').setup{ + mappings = { + close = 'q', + go_in = 'I', + go_in_plus = 'i', + go_out = 'N', + go_out_plus = 'n', + reset = '', + reveal_cwd = '@', + show_help = 'g?', + synchronize = '=', + trim_left = '<', + trim_right = '>', + } + } + end +} + diff --git a/lua/lazy/plugins/outline.lua b/lua/lazy/plugins/outline.lua new file mode 100644 index 0000000..b41a75a --- /dev/null +++ b/lua/lazy/plugins/outline.lua @@ -0,0 +1,30 @@ +-- === +-- === outlines,大纲,函数变量结构 +-- === + +local map = require("core.keymap") +-- 空格+v打开大纲,N全部收起,n收起当前节点,r重命名,I展开全部节点,i展开当前节点 +map:cmd('v', 'SymbolsOutline') + +return { + 'simrat39/symbols-outline.nvim', + config = function() + require("symbols-outline").setup { + width = 20, + keymaps = { -- These keymaps can be a string or a table for multiple keys + close = {"", "q"}, + goto_location = "", + focus_location = "o", + hover_symbol = "", + toggle_preview = "K", + rename_symbol = "r", + code_actions = "a", + fold = "n", + unfold = "i", + fold_all = "N", + unfold_all = "I", + fold_reset = "R", + } + } + end +} diff --git a/lua/lazy/plugins/pairs.lua b/lua/lazy/plugins/pairs.lua new file mode 100644 index 0000000..395f0ca --- /dev/null +++ b/lua/lazy/plugins/pairs.lua @@ -0,0 +1,19 @@ +return { + 'windwp/nvim-autopairs', + config = function() + -- 配合cmp,我也不知道有啥效果 + -- local cmp_autopairs = require('nvim-autopairs.completion.cmp') + -- local cmp = require('cmp') + -- cmp.event:on( + -- 'confirm_done', + -- cmp_autopairs.on_confirm_done() + -- ) + + require('nvim-autopairs').setup({ + -- 在写markdown时禁用括号补全 + disable_filetype = {"markdown"}, + -- can use treesitter to check for a pair. + check_ts = true, + }) + end +} diff --git a/lua/lazy/plugins/rainbow.lua b/lua/lazy/plugins/rainbow.lua new file mode 100644 index 0000000..e5e0789 --- /dev/null +++ b/lua/lazy/plugins/rainbow.lua @@ -0,0 +1,21 @@ +-- === +-- === rainbow,彩虹括号,必须要保证安装了treesitter,我分开是为了方便通过文件查找配置 +-- === + +return { + 'p00f/nvim-ts-rainbow', + config = function() + require("nvim-treesitter.configs").setup { + rainbow = { + -- `false` will disable the whole extension + enable = true, + -- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for + extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean + max_file_lines = nil, -- Do not enable for files with more than n lines, int + -- colors = {}, -- table of hex strings + -- termcolors = {} -- table of colour name strings + } + } + end +} + diff --git a/lua/lazy/plugins/stickyScroll.lua b/lua/lazy/plugins/stickyScroll.lua new file mode 100644 index 0000000..deef31b --- /dev/null +++ b/lua/lazy/plugins/stickyScroll.lua @@ -0,0 +1,23 @@ +return { + "nvim-treesitter/nvim-treesitter-context", + config = function() + vim.keymap.set("n", "[c", function() + require("treesitter-context").go_to_context(vim.v.count1) + end, { silent = true }) + require'treesitter-context'.setup{ + enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) + max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit. + min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit. + line_numbers = true, + multiline_threshold = 20, -- Maximum number of lines to show for a single context + trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer' + mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline' + -- Separator between context and content. Should be a single character string, like '-'. + -- When separator is set, the context will only show up when there are at least 2 lines above cursorline. + separator = nil, + zindex = 20, -- The Z-index of the context window + on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching + } + end +} + diff --git a/lua/lazy/plugins/suda.lua b/lua/lazy/plugins/suda.lua new file mode 100644 index 0000000..f8c3ae3 --- /dev/null +++ b/lua/lazy/plugins/suda.lua @@ -0,0 +1,4 @@ +return { + 'lambdalisue/suda.vim' +} + diff --git a/lua/lazy/plugins/surround.lua b/lua/lazy/plugins/surround.lua new file mode 100644 index 0000000..4669583 --- /dev/null +++ b/lua/lazy/plugins/surround.lua @@ -0,0 +1,21 @@ +-- === +-- === mini.nvim surround,各种对字符的包裹{} [] '' +-- === + +return { + 'echasnovski/mini.nvim', + branch = 'stable', + config = function() + require('mini.surround').setup { + mappings = { + add = 's', -- Add surrounding + delete = 'sd', -- Delete surrounding + find = 'sf', -- Find surrounding (to the right) + find_left = 'sF', -- Find surrounding (to the left) + highlight = 'sh', -- Highlight surrounding + replace = 'cs', -- Replace surrounding/change sround + update_n_lines = 'sn', -- Update `n_lines` + }, + } + end +} diff --git a/lua/lazy/plugins/tabular.lua b/lua/lazy/plugins/tabular.lua new file mode 100644 index 0000000..a6ed542 --- /dev/null +++ b/lua/lazy/plugins/tabular.lua @@ -0,0 +1,5 @@ +-- tabular,使用:Tab /=来格式化等号之类,特使符号要转义如:Tabularize /\/ +return { + 'godlygeek/tabular' +} + diff --git a/lua/lazy/plugins/telescope.lua b/lua/lazy/plugins/telescope.lua new file mode 100644 index 0000000..adb27ad --- /dev/null +++ b/lua/lazy/plugins/telescope.lua @@ -0,0 +1,52 @@ +return { + 'nvim-telescope/telescope.nvim', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + config = function() + local builtin = require('telescope.builtin') + -- ctrl+t打开文件查找 + vim.keymap.set('n', '', builtin.find_files, {}) + -- ctrl+f打开字符串查找 + vim.keymap.set('n', '', 'lua require("telescope.builtin").grep_string({ search = vim.fn.input("Grep For > "), only_sort_text = true, })', { noremap = true }) + -- 下面的配置从cw的配置粘贴过来的,删除一部分看不懂的 + local ts = require('telescope') + ts.setup({ + defaults = { + vimgrep_arguments = { + "rg", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--fixed-strings", + "--smart-case", + "--trim", + }, + layout_config = { + width = 0.9, + height = 0.9, + }, + mappings = { + i = { + [""] = "which_key", + [""] = "move_selection_previous", + [""] = "move_selection_next", + [""] = "preview_scrolling_up", + [""] = "preview_scrolling_down", + [""] = "close", + } + }, + color_devicons = true, + prompt_prefix = "🔍 ", + selection_caret = " ", + path_display = { "truncate" }, + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + }, + }) + end +} + diff --git a/lua/lazy/plugins/themes.lua b/lua/lazy/plugins/themes.lua new file mode 100644 index 0000000..1a36dba --- /dev/null +++ b/lua/lazy/plugins/themes.lua @@ -0,0 +1,253 @@ +-- === +-- === 底部状态栏+onedark主题 +-- === + +return { + 'nvim-lualine/lualine.nvim', + dependencies = { + 'kyazdani42/nvim-web-devicons', -- 图标 + 'navarasu/onedark.nvim', -- onedark主题 + }, + config = function() + -- Eviline config for lualine + -- Author: shadmansaleh + -- Credit: glepnir + local lualine = require('lualine') + + -- Color table for highlights + -- stylua: ignore + local colors = { + bg = '#202328', + fg = '#bbc2cf', + yellow = '#ECBE7B', + cyan = '#008080', + darkblue = '#081633', + green = '#98be65', + orange = '#FF8800', + violet = '#a9a1e1', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67', + } + + local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand('%:t')) ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > 80 + end, + check_git_workspace = function() + local filepath = vim.fn.expand('%:p:h') + local gitdir = vim.fn.finddir('.git', filepath .. ';') + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, + } + + -- Config + local config = { + options = { + -- Disable sections and component separators + component_separators = '', + section_separators = '', + theme = { + -- We are going to use lualine_c an lualine_x as left and + -- right section. Both are highlighted by c theme . So we + -- are just setting default looks o statusline + normal = { c = { fg = colors.fg, bg = colors.bg } }, + inactive = { c = { fg = colors.fg, bg = colors.bg } }, + }, + }, + sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + -- These will be filled later + lualine_c = {}, + lualine_x = {}, + }, + inactive_sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + lualine_c = {}, + lualine_x = {}, + }, + } + + -- Inserts a component in lualine_c at left section + local function ins_left(component) + table.insert(config.sections.lualine_c, component) + end + + -- Inserts a component in lualine_x ot right section + local function ins_right(component) + table.insert(config.sections.lualine_x, component) + end + + ins_left { + function() + return '▊' + end, + color = { fg = colors.blue }, -- Sets highlighting of component + padding = { left = 0, right = 1 }, -- We don't need space before this + } + + ins_left { + -- mode component + function() + return '' + end, + color = function() + -- auto change color according to neovims mode + local mode_color = { + n = colors.red, + i = colors.green, + v = colors.blue, + [''] = colors.blue, + V = colors.blue, + c = colors.magenta, + no = colors.red, + s = colors.orange, + S = colors.orange, + [''] = colors.orange, + ic = colors.yellow, + R = colors.violet, + Rv = colors.violet, + cv = colors.red, + ce = colors.red, + r = colors.cyan, + rm = colors.cyan, + ['r?'] = colors.cyan, + ['!'] = colors.red, + t = colors.red, + } + return { fg = mode_color[vim.fn.mode()] } + end, + padding = { right = 1 }, + } + + ins_left { + -- filesize component + 'filesize', + cond = conditions.buffer_not_empty, + } + + ins_left { + 'filename', + cond = conditions.buffer_not_empty, + color = { fg = colors.magenta, gui = 'bold' }, + } + + ins_left { 'location' } + + ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } + + ins_left { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + symbols = { error = ' ', warn = ' ', info = ' ' }, + diagnostics_color = { + color_error = { fg = colors.red }, + color_warn = { fg = colors.yellow }, + color_info = { fg = colors.cyan }, + }, + } + + -- Insert mid section. You can make any number of sections in neovim :) + -- for lualine it's any number greater then 2 + ins_left { + function() + return '%=' + end, + } + + ins_left { + -- Lsp server name . + function() + local msg = 'No Active Lsp' + local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype') + local clients = vim.lsp.get_active_clients() + if next(clients) == nil then + return msg + end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name + end + end + return msg + end, + icon = ' LSP:', + color = { fg = '#ffffff', gui = 'bold' }, + } + + -- Add components to right sections + ins_right { + 'o:encoding', -- option component same as &encoding in viml + fmt = string.upper, -- I'm not sure why it's upper case either ;) + cond = conditions.hide_in_width, + color = { fg = colors.green, gui = 'bold' }, + } + + ins_right { + 'fileformat', + fmt = string.upper, + icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh + color = { fg = colors.green, gui = 'bold' }, + } + + ins_right { + 'branch', + icon = '', + color = { fg = colors.violet, gui = 'bold' }, + } + + ins_right { + 'diff', + -- Is it me or the symbol for modified us really weird + symbols = { added = ' ', modified = '柳 ', removed = ' ' }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.orange }, + removed = { fg = colors.red }, + }, + cond = conditions.hide_in_width, + } + + ins_right { + function() + return '▊' + end, + color = { fg = colors.blue }, + padding = { left = 1 }, + } + + -- Now don't forget to initialize lualine + lualine.setup(config) + + + -- === + -- === 主题配置 theme + -- === + -- vim.cmd 'colorscheme space-vim-dark' + -- 使用灰色注释 + vim.cmd 'hi Comment guifg=#5C6370 ctermfg=59' + -- 使用透明背景 + -- vim.cmd 'hi Normal ctermbg=NONE guibg=NONE' + -- vim.cmd 'hi LineNr ctermbg=NONE guibg=NONE' + -- vim.cmd 'hi SignColumn ctermbg=NONE guibg=NONE' + + -- dark,darker,cool,deep,warm,warmer + require('onedark').setup { + style = 'darker' + } + require('onedark').load() + end +} + diff --git a/lua/lazy/plugins/translate.lua b/lua/lazy/plugins/translate.lua new file mode 100644 index 0000000..c11cd5a --- /dev/null +++ b/lua/lazy/plugins/translate.lua @@ -0,0 +1,13 @@ +-- 可视视图下 +return { + "kraftwerk28/gtranslate.nvim", + dependencies = "nvim-lua/plenary.nvim", + config = function() + vim.api.nvim_set_keymap('n', 'tr', "viw:'<,'>Translate", { noremap = true, silent = true }) + vim.api.nvim_set_keymap('v', 'tr', ":'<,'>Translate", { noremap = true, silent = true }) + require("gtranslate").setup { + default_to_language = "Chinese_Simplified", + } + end +} + diff --git a/lua/lazy/plugins/treesitter.lua b/lua/lazy/plugins/treesitter.lua new file mode 100644 index 0000000..be00e92 --- /dev/null +++ b/lua/lazy/plugins/treesitter.lua @@ -0,0 +1,40 @@ +-- === +-- === treesitter,语法高亮 +-- === + +return { + 'nvim-treesitter/nvim-treesitter', + config = function() + -- 要安装高亮的语言直接加入括号即可,把sync_install设置为true下次进入vim自动安装,语言列表查看treesitter的github + -- 或者执行:TSInstall + local language = { + "python", + "lua", + "dart", + "markdown", + "go", + "bash", + "java", + "sql", + } + require("nvim-treesitter.configs").setup { + -- A list of parser names, or "all" + ensure_installed = language, + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = true, + -- List of parsers to ignore installing (for "all") + ignore_install = {}, + highlight = { + enable = true, + -- list of language that will be disabled + disable = {}, + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + } + end +} + diff --git a/lua/lazy/plugins/whichkey.lua b/lua/lazy/plugins/whichkey.lua new file mode 100644 index 0000000..a9ba530 --- /dev/null +++ b/lua/lazy/plugins/whichkey.lua @@ -0,0 +1,17 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }, + config = function() + require("which-key").setup {} + end +} + diff --git a/lua/lazy/plugins/winbar.lua b/lua/lazy/plugins/winbar.lua new file mode 100644 index 0000000..080f757 --- /dev/null +++ b/lua/lazy/plugins/winbar.lua @@ -0,0 +1,73 @@ +return { + "Bekaboo/dropbar.nvim", + config = function() + local api = require("dropbar.api") + vim.keymap.set('n', ';', api.pick) + vim.keymap.set('n', '[c', api.goto_context_start) + vim.keymap.set('n', ']c', api.select_next_context) + + local confirm = function() + local menu = api.get_current_dropbar_menu() + if not menu then + return + end + local cursor = vim.api.nvim_win_get_cursor(menu.win) + local component = menu.entries[cursor[1]]:first_clickable(cursor[2]) + if component then + menu:click_on(component) + end + end + + local quit_curr = function() + local menu = api.get_current_dropbar_menu() + if menu then + menu:close() + end + end + + require("dropbar").setup({ + menu = { + -- When on, automatically set the cursor to the closest previous/next + -- clickable component in the direction of cursor movement on CursorMoved + quick_navigation = true, + ---@type table> + keymaps = { + [''] = function() + local menu = api.get_current_dropbar_menu() + if not menu then + return + end + local mouse = vim.fn.getmousepos() + if mouse.winid ~= menu.win then + local parent_menu = api.get_dropbar_menu(mouse.winid) + if parent_menu and parent_menu.sub_menu then + parent_menu.sub_menu:close() + end + if vim.api.nvim_win_is_valid(mouse.winid) then + vim.api.nvim_set_current_win(mouse.winid) + end + return + end + menu:click_at({ mouse.line, mouse.column }, nil, 1, 'l') + end, + [''] = confirm, + ['i'] = confirm, + [''] = quit_curr, + ['q'] = quit_curr, + ['n'] = quit_curr, + [''] = function() + local menu = api.get_current_dropbar_menu() + if not menu then + return + end + local mouse = vim.fn.getmousepos() + if mouse.winid ~= menu.win then + return + end + menu:update_hover_hl({ mouse.line, mouse.column - 1 }) + end, + }, + }, + }) + end +} diff --git a/root_init.lua b/root_init.lua new file mode 100644 index 0000000..886bad5 --- /dev/null +++ b/root_init.lua @@ -0,0 +1,18 @@ +--[[ +用以下命令创建root账户neovim配置软链接 +sudo mkdir -p /root/.config/nvim/lua/ +sudo ln -s ~/.config/nvim/lua/core /root/.config/nvim/lua/core +sudo ln -s ~/.config/nvim/root_init.lua /root/.config/nvim/init.lua +]]-- + +-- 基本配置 +require("core.init") + +-- 基本键盘映射 +require("core.keymap") + +-- vim综合症 +require("core.cursor") + +-- markdown snippets +require("core.md-snippets") diff --git a/snippets/dart.snippets b/snippets/dart.snippets new file mode 100644 index 0000000..18c66f6 --- /dev/null +++ b/snippets/dart.snippets @@ -0,0 +1,31 @@ +snippet pri + print(${0}) + +snippet stful + import 'package:flutter/material.dart'; + + class ${1:MyWidget} extends StatefulWidget { + const $1({Key? key}) : super(key: key); + + @override + _$1State createState() => _$1State(); + } + + class _$1State extends State<$1> { + @override + Widget build(BuildContext context) { + return ${2:Container()}; + } + } + +snippet stless + import 'package:flutter/material.dart'; + + class ${1:name} extends StatelessWidget { + const $1({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return ${2:Container()}; + } + } diff --git a/snippets/go.snippets b/snippets/go.snippets new file mode 100644 index 0000000..e277845 --- /dev/null +++ b/snippets/go.snippets @@ -0,0 +1,27 @@ +snippet printf + fmt.Printf("${1}\\n"${2:}) + +snippet println + fmt.Println(${0}) + +snippet sca + fmt.Scanln(&${0}) + +snippet swi + switch ${1} { + case ${2:}: + } + +snippet for + for ${1} { + } + +snippet init + func init(${1}) ${2:} { + } + +snippet re + require "${1}" v0.0.0 + +snippet require + replace "${1}" => "${2:}" diff --git a/snippets/gomod.snippets b/snippets/gomod.snippets new file mode 100644 index 0000000..f6b7ae7 --- /dev/null +++ b/snippets/gomod.snippets @@ -0,0 +1,5 @@ +snippet re + require "${1}" v0.0.0 + +snippet re + replace "${1}" => "${2:}" diff --git a/snippets/lua.snippets b/snippets/lua.snippets new file mode 100644 index 0000000..2e7c278 --- /dev/null +++ b/snippets/lua.snippets @@ -0,0 +1,18 @@ +snippet sec + -- === + -- === ${0} + -- === + +snippet return + return { + ${1} + config = function() + ${2} + end + } + +snippet require_keymap nvim的键盘映射调用 + local map = require("core.keymap") + +snippet require_plugins nvim的插件快速调用 + require("lazy.plugins.${0}"), diff --git a/snippets/markdown.snippets b/snippets/markdown.snippets new file mode 100644 index 0000000..fccb161 --- /dev/null +++ b/snippets/markdown.snippets @@ -0,0 +1,20 @@ +snippet t2 + | ${2:<++>} | <++> | + |-|-| + | <++> | <++> |${1} + +snippet t3 + | ${2:<++>} | <++> | <++> | + |-|-|-| + | <++> | <++> | <++> |${1} + +snippet t4 + | ${2:<++>} | <++> | <++> | <++> | + |-|-|-|-| + | <++> | <++> | <++> | <++> |${1} + + +snippet t5 + | ${2:<++>} | <++> | <++> | <++> | <++> | + |-|-|-|-|-| + | <++> | <++> | <++> | <++> | <++> |${1} diff --git a/snippets/python.snippets b/snippets/python.snippets new file mode 100644 index 0000000..3598294 --- /dev/null +++ b/snippets/python.snippets @@ -0,0 +1,7 @@ +snippet pri + print(${0}) + +snippet main + if __name__ == '__main__': + ${0} +