WolfgangMehner / vim-plugins

Vim plug-ins which offer support for various programming languages.
415 stars 96 forks source link

bash-support: Go to end of file after inserting a new header #45

Closed theova closed 6 years ago

theova commented 6 years ago

Hello,

thank you for the nice plugin! It's really helpful!

One little thing to improve would be to set the cursor to the last line of the file after inserting the header.

WolfgangMehner commented 6 years ago

Thanks, I appreciate it.

Do you mean the insertion of the file header when a new file is created?

I recently extended that behavior, see News: Customizable file skeletons. I honestly feel that the availability of this configuration option is more important than the exact cursor placement. I anyway estimate that the usecase "start editing a new file" is not that common that a new configuration option would be warranted.

I will make a suggestion on how you can achieve this behavior by yourself later, stay tuned ...

theova commented 6 years ago

Do you mean the insertion of the file header when a new file is created?

exactly.

I honestly feel that the availability of this configuration option is more important than the exact cursor placement.

Of course, I can understand it.

Thank you anyway!

WolfgangMehner commented 6 years ago

So, here is what you can do. The file skeleton used to create a new file is configured in the template library. It is set up via the property Bash::FileSkeleton::Script:

SetProperty ( 'Bash::FileSkeleton::Script', 'Comments.shebang;Comments.file header; ;Skeleton.script-set' )

This default setting will insert a shebang, a file header comment, and some options into a newly created file *.sh.

The placement of the cursor is determined by the first template in the list, Comments.shebang in this case. If we only insert one template, then that one will determine the placement of the cursor.

Set up a custom template file, which is most easily done via the set-up wizard (map \ntw inside a Bash buffer or menu entry Bash -> Snippets -> template setup wizard, then choose the option "Create a customization file")

Now we can set the property to a new value:

SetProperty ( 'Bash::FileSkeleton::Script', 'Skeleton.file' )

And create a template "Skeleton.file", which includes everything that should be inserted into the new file:

== Skeleton.file == nomenu ==
#!|BASH_INTERPRETER| -
#===============================================================================
#
#          FILE: |FILENAME|
#
#         USAGE: ./|FILENAME|
#
#   DESCRIPTION: TODO
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: |AUTHOR| (|AUTHORREF|), |EMAIL|
#  ORGANIZATION: |ORGANIZATION|
#       CREATED: |DATE| |TIME|
#      REVISION:  ---
#===============================================================================

set -o nounset                                  # Treat unset variables as an error
shopt -s extglob                                # Extended pattern matching

<CURSOR>
== ENDTEMPLATE ==

The template option nomenu prevents the creation of a menu entry for this template. The tag <CURSOR> determines the placement of the cursor after inserting the template. Lastly, the macros |FILENAME|, |DATE|, |TIME|, ... will be replaced accordingly.

theova commented 6 years ago

Thanky for your answer!

Where do I have to store "Skeleton.file" ?

WolfgangMehner commented 6 years ago

Skeleton.file is a template, not a file. It goes into a template library, which in turn actually is a file.

You can either edit the stock templates shipped with this plug-in. However, that has the disadvantage that you have to deal with these changes every time you pull a new version of the plug-in. (map \ntl inside a Bash buffer or menu entry Bash -> Snippets -> edit local templates)

The other option is to set-up a custom template file, and put the template there. The custom template file is stored outside of the repository. You can set it up as described above:

Setting up a custom template file is most easily done via the set-up wizard (map \ntw inside a Bash buffer or menu entry Bash -> Snippets -> template setup wizard, then choose the option "Create a customization file")

theova commented 6 years ago

Oh, thank you very much! It works fine for me.

I didn't realize, that I just have to paste it into the file.