2

I have this test code in my bash file:

gtest() {
    echo 'hello'
}

bind '"\C-g\C-x": "$(gtest)\e\C-e"'

When I start typing something like vim ", and then press C-g C-x, I get vim hello instead of vim "hello.

If I type vim """sometext and then press C-g C-x, I get vim sometexthello instead of vim """sometexthello.

Is there a way to retain the quotes?

1 Answer 1

3
+50
bind '"\C-g\C-x": "\C-u$(gtest)\e\C-e\C-a\C-y\C-e"'

The problem was that \e\C-e evaluates the line. It's good for executing $(gtest), yet it can obviously mess with " chars.

The trick is to save the line with C-u, evaluate only $(gtest), place the cursor at the beginning (C-a), restore saved line (C-y) and finally place the cursor at the end (C-e).

1
  • +1 OMG, thank you very much, I have been trying a bunch of stuff ..:) Again, thank you mate.
    – whitesiroi
    May 11, 2016 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .