Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:47:32+00:00 2026-06-11T19:47:32+00:00

Background: I’m using this mapping map ,r :! bundle exec ruby %<CR> all the

  • 0

Background: I’m using this mapping map ,r :! bundle exec ruby %<CR> all the time to easily run test file I’m currently editing. However I also do:

map ,t :! bundle exec ruby test/integration/some_integration_test.rb<CR>

so that I can run this particular integration test with two key strokes while working on some other file. It has hard-coded path, when I move to some other area of the application I type above command with another integration test file path.

How to make a command that creates such mapping automatically?

map ,T :map ,t :! bundle exec ruby %<CR> won’t work because it doesn’t expand % while creating the mapping, so ,t will always run current file (while I want it to run file I was editing at the time of creating the mapping).

[EDIT]:
Slightly adjusted solution from the answer:

nnoremap ,r :! bundle exec ruby %<CR>
nnoremap ,T :let g:testfile = expand('%:p')
nnoremap ,t :! bundle exec ruby <C-r><C-r>=g:testfile<CR><CR>
  • ,r always runs file under cursor
  • ,T saves current file path under in a variable for running later
  • ,t runs file path stored previously
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:47:33+00:00Added an answer on June 11, 2026 at 7:47 pm

    Just save the current file name (best with a full absolute path to be immune against changes to the current directory; the :p modifier does that) in a variable, and insert the variable instead of % via <C-r>:

    :noremap ,r :let g:testfile = expand('%:p')<Bar>! bundle exec ruby %<CR>
    :noremap ,t :! bundle exec ruby <C-r><C-r>=g:testfile<CR><CR>
    

    PS: I used :noremap, because that is generally safer and should be the first choice unless you really need remapping to occur.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: Using unix, codeigniter from localhost. I'd like to run a controllers via a
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
Background - I am using paramiko to put files on a bunch of remote
Background I graduated 6 months ago, and my collaborative work in college has all
Background - I want to extract specific columns from a csv file. The csv
Background I have an installation of VisualSVN on a server. under this, I have
Background Hi All, I'm trying to use Boost::MPI, at the moment I'm just trying
Background info: Me and a couple of friends are building this platform game in
Background: I have a website where people can store transactions. As part of this
Background Windows 7 x 64 Python 2.7 Django 1.4 Celery with Redis bundle While

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.