Append to top and bottom of selected text in vim -


I have the following text (==== delimiter indicates selected text):

  This is some text in which I am not interested I ===================== This text section is selected ========== =========== This is not an important indent text yet I do not have any interest in this.   

Now I want to create a VIM function so that when called, it adds up and down at some default text. For example, I would like to end with:

  This is some text that I am not interested in. This text was added after the phone was selected. In this second lesson, the call added after the same ceremony is not important indent text. Other text I am not interested in this   

Please note that indentation should be protected (thanks benjifisher How can I do this?

It is a bit loose, but it works:

  Function! Frame () range '& lt; put! = \ "After this other text \ n function call \" \ "'gt; put = \" this other text \ n was implemented \ n after function call \ "endfun   

Select your lines in visual mode, and

 : '& lt ;;' & gt; Call frame ()   

( '<', is inserted automatically.) : execute < There are some advantages of using a: firstline and code: A: the last line as in : function-category-example , ' and ' & gt; instead of the visual digit, but it becomes a bit complex, you can call each command to : silent Also you can do it even if you do not care to tell that add 3 lines

Here is a version from which indentation copies as requested in the updated question, first and last selected lines. a: firstline And a: to make it more convenient: this version uses : call app ( instead of : put , lastline < / Code>; Probably, this would be useful if you ever want to call a function with a different range than one view.

 < code> "Row numbers, add rows below before adding on top" when you add lines, the function will change! Define a list of the "frame (range)" rows and include in the desired indentant. Give the bottle [['This other text was', 'added after', 'call function'] Botspace = matchstress (getline One: last row), 'rows for line in botline'], add call (line, botspace, line) for "Now add those lines below call option (A: Last Line, Lines)" now Do the same thing at the top. S = ['This was another text', 'added after', 'call function'] top position =), 'rows the line for lines' [] Call for line in toplon call ( Line, topspace, line) and call call end (a: first line - 1, lines)     

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -