Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
The stupid question is the question not asked

Editing features for advanced users

by gmax (Abbot)
on Jan 26, 2002 at 15:40 UTC ( #141765=perlmeditation: print w/ replies, xml ) Need Help??


I would like to share my experience of using a powerful editor to manipulate Perl files. Since I consider myself a demanding user, I heartily appreciate every feature that makes me type less and produce more. The tips presented here range from trivial to black magic but all have in common the fact that they are now part of my editing habits and it would be very painful for me to shift to any editor that offers less than that.
Vim is a multi-platform text editor, a clone of the venerable *NIX vi. Its name stands for Vi improved and it turns out that it has a really huge range of features.
As a text editor, Vim is suitable to write almost everything, but we are interested only on some of its features related to editing Perl scripts.
This short introduction does not cover all the editor features, for which there is a 370 pages manual, but just focus on some useful tips to improve your daily chores.
This is not a tutorial for Vim. There are plenty of them (the first one in the program itself) and teaching Vim would go beyond the purpose of this text.
This text deals with Vim version 6. Most of what I am presenting is also available in version 5.8, which was the previous stable version of Vim. The real difference, as long as we (programmers) are concerned, are:
- the manual has been reorganized and now there is a comprehensive user manual, organized by editing tasks, rather than editing features; - a new feature for folding text can make much easier to work with long, complex files.

Vim is the programmer's friend. Has been designed and implemented by a C programmer who knows what the daily problems are. But it has also dedicated features for Perl, Python and Ruby programmers.
It comes with an internal script language that can automate any editing task.
As many powerful tools, its learning curve is quite steep. I was not intrigued by its cryptic interface when I started working in Unix. But if you can get past the first obstacle, your effort will be rewarded. Vim is an agile editor that can work, as a minimum, with less than 400 KB of data storage and limited memory, while offering a vast collection of quick and powerful features.

Making your scripts more readable

The first aspect of using Vim with a Perl script is syntax highlighting. Your script is colored in various way, making evident the different components of the language. Variables, functions, quoted text, regular expressions, numbers and comments are represented with various colors, giving you an immediate feeling of what you are writing. It is like having an on-line compiler that can tell you immediately if you mistyped something.
It will save you quite a lot of edit-run-fix cycles. You will catch simple errors just as you type them.

Let the editor help you

Word completion is another feature that will avoid misspelling of repeating words. You type the beginning of a word, and then press "CTRL P". The first word that matches your starting text will appear at the cursor. If more than one words are available, the status line will inform you of that, and you can recall the next matching word by repeating the command.
Matching pairs is a built-in feature that tells you if you are correctly matching parentheses, brackets and braces. While you are entering text, whenever you type a closing symbol (")]}>"), Vim will show you the corresponding opening one ("([{<"), by sending the cursor for half a second to it. If the pairs are unbalanced (more closing than opening symbols) it will beep. After typing, or when reading someone else's script, if you want to check a matching pair, you can put your cursor on a opening or closing symbol and hit the "%" key. A priceless feature when you are dealing with nested parentheses.

Task automation

Vim's script is a full featured language that you can use to create new functions or to modify existing ones. However, you don't need to learn yet another language to deal with repeating tasks. Vim lets you record a stream of text and/or commands that can be repeated at will. For example, if you want to record a complex function template, you type "q" and another letter, let's say "t" and then start doing what it needs to be done. When you are finished, you press "q" again and the macro is recorded into buffer "t". To replay what you have recorded, press "@t" and all your actions are repeated starting from the current cursor position.
A clean explanation can be found in Vim's help, by typing
:h q while in command mode.
The map and ab[breviation] commands allow you to create quick macros using only editing commands, without using the script language.

Advanced readability

Highlighted syntax is great, but sometimes is not that useful. We often use the Perl DBI to communicate to a database, using another language, SQL, which has different keywords and syntax. Whenever we write SQL, its appearance is flattened inside quoted text.
Vim can give you a hand, through Embedded syntax. You can define an alternative set of rules to highlight SQL. Let's see how and then we'll comment its meaning.
Find your syntax file for Perl. In *NIX it should be
Towards the end of the file, before the line
let b:current_syntax = "perl"
insert the following:
syn include @Sql <sfile>:p:h/sql.vim syn region perlSQL start="qq{" end="}" contains=@Sql keepend syn region perlSQL start="qq\[" end="\]" contains=@Sql keepend syn region perlSQL start="<<SQL" end="^SQL" contains=@Sql keepend
You should become system administrator to be able to edit such file.
These instructions tell Vim to treat anyhthing within "qq{" and "}" as SQL code, whose syntax is described in the file "sql.vim" in the same directory. The same treatment is reserved to SQL code within "qq[]" or in here documents starting with "<<SQL".
I am using different delimiters, so I will be able to write statements like the following:
my $sql1 = qq{ SELECT fieldname FROM $tab_array[0] WHERE otherfield = ( ? ) }; my $sql2 = qq[ SELECT fieldname FROM $tab_hash{$current} WHERE otherfield = ( ? ) ];
When I want to use qq to double quote normal Perl code, I just add a space between the operator and the braces:
my $sign = qq {DO NOT SELECT FROM MY TABLE !}
Another useful application of the same feature is to embed Perl code inside HTML.
You can enter similar statements inside the HTML.vim file, to instruct vim to consider text between <code> and </code> as Perl. Then, writing a post for PerlMonks is going to be much easier. ;)

Exporting readability

You are pleased with your highlighted syntax and you would like to use it for a seminar, or to publish your latest brilliant code on your website. However, when the Perl script leaves your editor, it is back in boring black an white.
Fortunately, Vim comes with a script to export the currently highlighted file into a fully formatted HTML file. No sweat. Just enter this command while in command mode:
:runtime! syntax/2html.vim
And you'll have a file with the same name as the original, plus the ".html" extension, ready to astound your audience.
It is a slow procedure and the result file is quite big, but you can't have it all, can you?

More advanced features: Perl tags

Whoever has experience of C programming in *NIX should have come across the "ctags" program. In simplified terms, it is a mapping program that will read the source files and produce an index of function and variable names. Several editors can recognize such indexes and, when you point at a name in your source file they can, upon request, open the related file and show you that variable/function.
Vim offers the same service for Perl files. Distributed with Vim there is a script named "", which can analyze a list of files and create a "tags" index. After this process, all identifiers in your scripts become hyper-textual. You can put your cursor on a function name, press "CTRL ]" and Vim will open the relevant file and find that function for you. When you want to come back to your original script, "CTRL T" will beam you back.

Wizardry: editing with Perl

Vim is a fully featured editor. It supports extended regular expressions, even though its syntax is different from Perl's. It would be nice to use the same syntax within your code and when you write it as well. Also, sometimes you would like to enter some Perl instructions to manipulate your text. On the other hand, when writing a script to manipulate a complex text, you would just love to have a handler to the innards of the editor, so that you can combine Perl code with multiple text buffers, undo features, windows resizing and so on.
Vim lets you do that. All you need is to get the source code and recompile the editor with the appropriate option (requires Perl 5.004 or later already installed before you compile).
# ./configure --enable-perlinterp # make # make install
Now from Vim command mode you can enter the :perl {cmd} command and execute any Perl instruction. Or you can use the [range]:perldo {cmd} which will execute command for each line in the range, with default to the whole text in the editor.
There are dozens of functions available to interface Vim to your Perl's code. You can get full details from Vim's help, entering h perl
Think about the possibilities:
You can use the "tr///" operator on a range of lines, instead of being limited to Vim's "s///" (which, let's not forget, uses the old syntax full of chopsticks like s/\<\(this\) \(that\)\>/\2 \1/ instead of s/\b(this) (that)\b/\2 \1/). Or you can sort a range of lines with a customized Perl function, without leaving your editor.
Or you can even test snippets of your code, to see if they give you the expected result, still within the editor.
You should be dying to see some examples and here we go:
First, a customizable word count
:perl $count = 0 :perldo $count += split /[;_<> ]/, $_ :perl VIM::Msg($count)
Then, a special sorting routine, getting text from the editor's current buffer and writing back to it:
:perl @lines = sort {$a <=> $b} $curbuf->Get(1 .. 15) :perl $curbuf->Set(1, @lines)
Or, in short,
:perl $curbuf->Set(1, sort {$a <=> $b} $curbuf->Get(1 .. 15))
Finally, we can combine using Perl's RegEx syntax with Vim's range facilities. This example applies the substitution pattern from row 10 to 30, and then uses the "tr///" operator to delete all non hexadecimal characters from lines 40-45.
:10,30perldo s/\b(:?Monks|advocates)\b/PerlMonks/ :40,45perldo tr/A-F0-9//cd
I am sure that some of the Monks must have watering mouths at this code, especially the ones with a knack for one-liners.


Despite circumstantial evidence of the contrary, I am not advocating for Vim. Everyone is free of using the editor that best suits one's purposes. For my side, as an experienced programmer, I chose Vim for the great flexibility and some of the advanced features that I presented here.

Note to non-Vim users Please don't take this post as a challenge against your favorite editor. I am talking about Vim because I know how to use it (or, at least, I have been using it confidently for long enough), trying to be helpful.
I would appreciate if someone could match the same advice for other editors, not in the spirit of "mine is smarter than yours" but just to offer the same range of features to the community.

I hope I have provided some useful ideas.

update Title changed following crazyinsomniac advice.
 _  _ _  _  
(_|| | |(_|><

Comment on Editing features for advanced users
Select or Download Code
Re: Editing features for power users
by Juerd (Abbot) on Jan 26, 2002 at 16:49 UTC
    My favorite editor is mcedit (this is gonna cost me lots of XP :). I like the blue background, and the bright syntax coloring. While it's not perfect, I like it better than the vim Perl syntax color schemes I've seen.
    Unfortunately, mcedit is packaged with mc (it's the built-in editor), but you can use the "mcedit" executable (which is mc, but under a different name) to call it directly.

    You don't need to read any manual before you know how it works: cursor keys and function keys are easy to use - I don't like :w and :wq. I like F2, enter and F10, Y(es).

    I've used MANY other editors, including vim and jed - but I still like mcedit best.

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      I wasn't a big fan of the color schemes either, but like everything else in Vim, that too can be customized. For Gvim (non terminal based GTK X app) you can add this:
      set background=dark hi Normal guifg=#ffffff guibg=#000000 hi PreProc guifg=#ff80ff guibg=#000000 hi Statement guifg=#00d000 guibg=#000000 hi Comment guifg=#707070 guibg=#000000 hi Identifier guifg=orange guibg=#000000 hi Constant guifg=#6060ff guibg=#000000 hi Special guifg=#80f0f0 guibg=#000000 hi Cursor guifg=black guibg=red
      to the .gvimrc file in your home dir under Un*x and get my color scheme (which you may not like either :) ).

      I'm not sure where the equivalent windows .gvimrc file is.

      perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

        I wasn't a big fan of the color schemes either, but like everything else in Vim, that too can be customized.
        Careful with that attitude, or you may end up with
        alias vim="emacs -f viper"

Re: Editing features for power users
by moodster (Hermit) on Jan 26, 2002 at 16:58 UTC
    I like vim and use it a lot along with emacs. The one feature I like the most is the regexp search-and-replace thingy. I have only two gripes so far:
    1. Having to switch insert mode on and off is a hassle. But I can live with that.
    2. Starting the GUI version of vim (gvim) from a launcher (like gnome) produc different results than starting gvim from the command line. It seems like different config files are read, since the color schemes and some menus are different. I've noticed this behaviour under both linux and NT but so far I've failed to find an explanation in the docs. Anyone?
    -- moodster
      Do :version to check which vimrc files get sourced. That should give you a hint of what's going on.

      Makeshifts last the longest.

Re: Editing features for power users
by perrin (Chancellor) on Jan 26, 2002 at 22:22 UTC
    Another option for nice HTML-formatted code output is perltidy.
Re: Editing features for power users
by Aristotle (Chancellor) on Jan 26, 2002 at 23:09 UTC

    I have only just started using gvim less than a week ago, and I must say I love it. I know very few of its features yet but I can already work as fast as I could with NEdit - I expect my editing speed will increase a lot once I'm really used to Vim. Yes, having to switch between command and edit mode seems a nuisance at first, but it removes the need for a lot of extra keypresses - rather than Ctrl-this/Ctrl-that'ing, you just hit a single key (or two) to execute some command. I can only recommend this editor to everyone. Just suffer through the initial getting-to-know phase and you'll be rewarded richly.

    Do take the vimtutor! That is what got me started for real. Don't try to figure Vim out on your own cause it will take you ages to collect a useful set of shortcuts. The tutor will get you started on becoming productive in very little time. Go through it again after 2 or 3 days of using Vim for a refresher, then print the reference card.

    This editor really rocks. I'm glad I was repeatedly nagged to try it :-)

    Makeshifts last the longest.

Re: Editing features for power users
by jlongino (Parson) on Jan 26, 2002 at 23:43 UTC
    I suppose my editor(s) of choice follow my basic programming philosophy KISS, or as foopad suggests, LAW (Least Amount of Work).

    Features I like:

    • autoindent, along with auto-outdent when you press the backspace key.
    • block and rectangular cut/paste modes.
    • having multiple windows open and being able to tile them vertically or horizontally.
    • being able to cut/paste between different apps.
    • being able to jump to a specific line number.
    • flexible find/replace

    Unfortunately, none of the editors I use have all of the things I want (there are several other things to add to the list that I can't think of at the moment). So I use Open Perl IDE and TextPad with Windows and Joe with Unix. I've never liked vi or Emacs, although I have to admit using vi to delete lines from or view large files (not much else though).

    I'll also use Notepad, WordPad or Edit (Windows) if a quick or throwaway task is needed. I'm not adverse to trying new editors if they're practically free, easy to install, provide most of my listed features, have a short learning curve, and the keyboard shortcuts are not too disimilar from standard Windows apps or WordStar (though I've always hated WordStar with a passion, I at least learned most of the keystroke combinations).

    I'm a pretty good typist so I don't really bother with macros. The other advanced features don't appeal to me either but I can see where other people might like them.

    TETO! (to each their own).


      vim has most of the features you're asking for:
      • Autoindent: :set smartindent will turn it on
      • Block cut and paste: there are SEVERAL command sequences for this. You could:
        • position the cursor at the start of the block press ma (set a mark named a at this line)
        • move to some other line press y'a (yank / copy from this line to mark a) or d'a (delete / cut from this line to mark a)
        • then move to the line you want insert those copied or cut lines and press p (paste).
        as for between other apps, copy or cutting goes to the windows clipboard and mouse highlighting will copy to the X buffer.
      • gvim supports this:
        • CTRL-W N splits the current window horizontally. (think: Control Window New)
        • CTRL-W J moves the focus to the window below
        • CTRL-W K moves the focus to the window above
        • :q (or another exit command) will close the current window
        • you can cut / paste between any of the windows
      • Jump to specific line number:
        • :(number)
        • :.+10 ten lines below the current one
        • :$ last line of the file
        • :$-5 5 lines before last line of file
      • Umm...regex find and replace. hello? :) you can also have it prompt per each replacment by adding c after the closing / on the replacement
      A very large part of the appeal for me is that my hands never leave the home keys regardless of the task I'm performing. I even mapped the escape key to ALT so that I didn't have to reach for it.


      perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

        Thanks for taking the time to reply. I was pretty sure vi, vim, and gvim could meet my short list, probably my longer list too. I'm not so sure, at least from what I've read in this thread and my limited exposure to vi, that they fit the bill as far as short learning curve and familiar keyboard shortcuts (afraid the command/edit mode ":" annoyance is something I just can't get past).

        As for regex-like find/replace? I don't really like regex at all, and don't particularly want to learn two different flavors. Don't get me wrong, with Perl it is a wonderful and efficient tool for people who like it, need it and too rarely use it correctly, I just usually don't (like, need, or use it correctly ;-). On the rare occasions that I do need it, I use it appreciatively, but to use a different flavor of it regularly for editor find/replace? Er, no thanx.


        re:  Screamer++, fair enough!

          I even mapped the escape key to ALT so that I didn't have to reach for it.

        You can just use CTRL-[ to send the escape character. Your fingers never leave the home row and you don't have to mess around with alternate key mappings. You can also use this key combination to send ESC to Emacs. :-)


        What time is it? It's Camel Time!

      Just the other day I downloaded a (free!) Windows txt editor called Context that basically has all the features you list. I've only used it for a couple of days, but so far the only thing that I've missed is regexp support in search & replace -- but in another message you mentioned that you don't really regexps anyway. So it might be a good fit.

      Available here if you want to check it out:

(shockme) Re: Editing features for advanced users
by shockme (Chaplain) on Jan 27, 2002 at 23:49 UTC
    # ./configure --enable-perlinterp
    # make
    # make install

    Or, if you're using Debian:

    apt-get install vim-perl

    Excellent post gmax. ++.

    If things get any worse, I'll have to ask you to stop helping me.

Re: Editing features for advanced users
by Anonymous Monk on Apr 26, 2002 at 14:47 UTC
    Great article! I appreciate the coverage of the more esoteric and useful aspects of Vim. A couple of questions.

    1. If I want to load the sql.vim syntax file in the standard syntax directory ($VIMFILES/syntax), what format should the syn include line take? I tried looking this up in the online help, but find the Vim ex syntax to be quite cryptic.

    2. Can you (or someone) give some more details about generating tags. You talked about how to use them but I cannot seem to generate them. Right now I think Vim uses a different program to generate the tags than the file you mentioned.

    Thanks, William

      If I want to load the sql.vim syntax file in the standard syntax directory ($VIMFILES/syntax), what format should the syn include line take?
      syn include @Sql syntax/sql.vim

      "A Jedi uses the Force for knowledge and defense, never for attack."
Re: Editing features for advanced users
by meonkeys (Chaplain) on Apr 27, 2002 at 20:16 UTC
    gmax++. Excellent article! I've been delving into so many features of vim I don't think I'll ever be able to use another editor. Exporting to syntax-highlighted, numbered HTML is cool. I've also never seen the 'showmatch' option, but always wanted it!

    I just have one question for you, which may be more of a ctags question--I don't know. Say you have some perl...
    #!/usr/bin/perl -w use strict; use Business::CreditCard qw(); Business::CreditCard::validate('4111111111111111') or die "The credit card number appears to be invalid\n";
    When I run on this, it just returns "No tags found.". Isn't the function call a tag? I would expect it to make a tags file with a hyperlink to Business::CreditCard that points straight to the line where validate() is defined. Is this possible? I would so love to know the answer to this riddle. If I could do this it would be incredibly easy to navigate my perl code.

    "A Jedi uses the Force for knowledge and defense, never for attack."
      The purpose of the tags program is to bookmark where a variable or sub was declared, so that you can go back to that point when needed.
      Say you have this script:
      use DBI; use strict; my $DNS = shift; my $dbh = DBI->connect($DNS);
      Save it as and then run
      $ /your_path_to_it/ `perldoc -l DBI`
      (perldoc -l returns the path of an installed module).
      Then, editing, if you have your cursor over the "connect" word, Ctrl-] will take you to the module, at the line where the "connect" sub was defined.
      In your case, replace the script and module names and you'll have some more tags available.
       _  _ _  _  
      (_|| | |(_|><
Re: Editing features for advanced users
by swiftone (Curate) on May 03, 2002 at 17:47 UTC
    An excellent tutorial! Very nice, practical examples, something that's often missing.

    Unfortunately, the area you skimmed was the area I know little about: pltags. I _don't_ have ctags experience, and even the ctags documentation seems to assume I have ctags experience.

    A few tests on my system shows that this creates a tags file in the present directory. How do I tell vim which tags file to use if I'm elsewhere on the system? Do I have to run pltags over a script that calls outside functions, or just the scripts/modules that hold those outside functions? Is the tags file incremental or replaced? Where can I locate documentation for (There doesn't appear to be a man page)? Should I cron job this sucker so that it keeps up with updating modules?

    Assistance appreciated.

      I have only used ctags, so this response only deals with that.

      To ctags, you can specify whether to append or replace the tagfile, where to store the resulting tagfile, what to tag, etc. This the script that i use to update the tag files.

      set tags[-+]?= is how to set the the location of a tag file in vim. You can use autocmd to set the tag file(s) based on directory or file name. See :h au | :only (vim online help on au in the full window) for more information. Note that the au command understands only the shell regex.

VIM syntax highlighting in test scripts
by grantm (Parson) on Mar 24, 2003 at 02:04 UTC

    Excellent article. Here's another tip Perl/vim users may find useful:

    When you're creating test files for your CPAN distribution (or other projects) you'll often have a bunch of t/*.t files. Because they don't have a shebang line or a .pl extension, the Perl syntax mode is not automatically enabled. You can have it come on automatically by including a comment like this:

    # vim: syntax=perl

      Or, if you don't want to add that to the top of every test script, you can make vim understand that *.t files are perl by adding this to your .vimrc:

      autocmd BufRead *.t set syntax=perl

      This also has the advantage of having hilighting already turned on when you are editing a new file that you haven't added the vim comment to yet.

      We're not surrounded, we're in a target-rich environment!

        Or, if you have filetype autodetection turned on, you can use:

            autocmd BufRead *.t set filetype=perl

        This will trigger the FileType event which is used to load syntax files, etc. See :help filetype for details.

      Hi all,
      here is my new .vimrc script for
      - compiling my script
      - IF there is an error, it opens a new tab, where it jumps to the line of the first error, and displays all the errors in a QuickFix buffer under the code (so, all my previous buffers are preserved and it doesn't "move them around")
      - ELSE (no errors) it executes the script
      This is all fairly common, but i added a feature :
      by pressing
      it sets $CURRENT_FILE_TO_RUN to the path of the current active file. Then, when i press
      from any other file or tab, it runs the "current file to run" (the one chosen with ;f).

      In its current version, you MUST have this line in all your perl files, i'm sure it's possible to not need this, i just didn't find how on my computer

      " CAREFUL : i MUST have exactly this line in my Perl files : use Vi::QuickFix 'C:/quickfix_errors_tmp.err';

      It's very useful to me when i'm trying to make a test pass. I press ;f on the test file. Then I open other files in other buffers and/or tabs to modify them and try to make the test pass, and when i want to run the test, i just have to press ;r.
      Then if there are errors it jumps to them, i correct them, press ;r to re-run the test, until the test passes. Then, i press ;qq to close the two buffer of the tab opened by QuickFix (there must be a better way to implement ;qq, but it works fine like this for me)

      I also added ;R to run the current active file (and not the "file to run").

      I hope this helps other people. Here is the code, to paste in .vimrc

      """"""""""""""""""""""""""" " COMPILE, JUMP TO ERROR, and RUN the "CURRENT FILE TO RUN" " CAREFUL : i MUST have exactly this line in my Perl files : " use Vi::QuickFix 'C:/quickfix_errors_tmp.err'; let $ERROR_FILE = "C:/quickfix_errors_tmp.err" map ;r :call MakeWithCopenAndCfileInNewTab()<CR><CR> "current file to make must be the current one... let $CURRENT_FILE_TO_RUN = "%" let $PERL_COMPILE = "perl\\ -Ilib\\ -c\\ " function SetMakeprg() exe ":set makeprg=" . $PERL_COMPILE . $CURRENT_FILE_TO_RUN endfunction autocmd FileType perl call SetMakeprg() autocmd FileType perl set errorformat=%f:%l:%m autocmd FileType perl set autowrite "...unless we choose the file that we are reading as the "current file + to run" map ;f :call SetActiveFileToRun()<CR> function SetActiveFileToRun() let $CURRENT_FILE_TO_RUN=bufname("%") call SetMakeprg() endfunction " print who is the "current file to run" map ;F :call TellAndStop("The \"file to run\" with ;r is " \ . $CURRENT_FILE_TO_RUN \ . "\nUse ;R to run the active buffer file instead" ) "Compile, jump to first error (with QuickFix), and execute if there's +no error "From Marc Jessome, by email, 14th July 2012. "I modified the "for e in qflist "if !e.valid "by replacing it with "if len(qflist)>1 " because the elements of my qflist were not valid until i used :cfile function MakeWithCopenAndCfileInNewTab() make let qflist = getqflist() if len(qflist)>1 tabnew copen cfile $ERROR_FILE else exe "!perl\ -Ilib\ " . $CURRENT_FILE_TO_RUN endif endfunction " tells something to the user, and asks to press a button function TellAndStop(text) call inputsave() let name = input(a:text . "\npress Enter...") call inputrestore() endfunction "run the current file, not the "current_file_to_make" map ;R :call MakeTheCurrentFile()<CR> function MakeTheCurrentFile() "copy the "current_file_to_make" to a buffer let $BUF=$CURRENT_FILE_TO_RUN "compile+run the current file let $CURRENT_FILE_TO_RUN=bufname('%') call SetMakeprg() call MakeWithCopenAndCfileInNewTab() "retrieve the "current_file_to_make" path (from the buffer) let $CURRENT_FILE_TO_RUN=$BUF call SetMakeprg() endfunction "used for QuickFix to open its window after i compile set switchbuf=useopen " to quit a tab with 2 buffers open map ;qq :q<CR>:q<CR> " END of : COMPILE, JUMP TO ERROR, and RUN the "CURRENT FILE TO RUN " """"""""""""""""""""
      BE CAREFUL (this happened to me) : if 'makeprg' is set to a value somewhere else in your .vimrc file, be careful that it doesn't override the value set by this code

      Please enjoy it, improve it, and share what you've improved.

      PS : i think i didn't put this message in the right place. Feel free to move it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://141765]
Approved by root
Front-paged by bunnyman
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-04-20 05:10 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (485 votes), past polls