Vim make a custom macro or command

nautical

Although I have been using Vim for quite some time now, I am still a novice when it comes to customizing it. I am not sure if what I have in mind can be done. Here what I would like to do: When writing a bash script I have a template to comment a function

1  #!/bin/bash
2
3  ###########################################################
4  # template
5  # globals:
6  #   none
7  # returns:
8  #   none
9  ###########################################################
10
11
12 my_function () {
13 ...

What I am currently doing is to position the cursor at line 11 and then issue the command:

:3,9y

This yanks lines 3 to 9 into the buffer. Then I hit p and it pastes the lines after the cursor. I would like to simplify this process. Can I achieve the above behavior by defining something like a macro? Ideally I would define it the .vimrc file and not rely on the script to have the template exaclty at lines 3 through 9.

romainl

You could place the text of your banner in a named register:

let @c  = "###########################################################\n"
let @c .= "# template\n"
let @c .= "# globals:\n"
let @c .= "#   none\n"
let @c .= "# returns:\n"
let @c .= "#   none\n"
let @c .= "###########################################################"

and put it with:

"cp

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

VIM Smart quit macro

From Dev

using macro in vim insert mode

From Dev

VIM: chmod command is not an editor command

From Dev

Vim macro with backspace

From Dev

Vim - Macro to expand verilog bus

From Dev

CMake: execute a macro/function as the command of add_custom_command

From Dev

Restoring Vim macro with control character

From Dev

Vim calling command on save

From Dev

How make Vim Ex command pattern range start search from current line?

From Dev

How to make a Django custom management command argument not required?

From Dev

Make a vim command act on a visual selection OR the whole buffer

From Dev

Delete last word (Ctrl-W): Make bash shell behave like vim command line

From Dev

Continuing a macro across buffers in vim

From Dev

Vim Script: Is it possible to make a custom motion non-repeatable?

From Dev

How to cancel recording a macro in Vim?

From Dev

How do I make a vim command run automatically with .vimrc?

From Dev

make the line bold or highlight on find command on vim

From Dev

How to create a macro with vim commands?

From Dev

common lisp defclass make-instance usage in custom macro

From Dev

Macro to make class noncopyable

From Dev

How to make a parameterized command map in vim editor

From Dev

VIM - running a shell command fails within a macro

From Dev

Vim - can I pass multiple args to a custom command without writing a function

From Dev

Make file macro

From Dev

Running a custom command with Vim

From Dev

Padding a multiline C macro in vim

From Dev

Is there a way to make vim run the "make" command in another terminal window?

From Dev

Make ShellScript run with custom CLI command

From Dev

How to make a saved vim macro work when it has ^M in it?

Related Related

HotTag

Archive