Using expand-region
I would recommend installing the expand-region
package (available on Melpa too). It would be useful for editing situations mentioned in your example and lot more.
expand-region
is intelligent. Based on the major mode, it will try to figure out what you are trying to select. I don't know from which language you have the example snippet so I will use your example code snippet and slightly modify it for Python (remove ;). So my below explanation is with the below code snippet in a python-mode
buffer.
ref = open('specific-file-name')
If point is next to a single quote
The black vertical rectangles below indicate how the cursor will look.
# point on left of left quote, the cursor is hiding the quote under it
ref = open(▮specific-file-name')
# point on left of right parenthesis, the cursor is hiding the parenthesis under it
ref = open('specific-file-name'▮
In either case, when you do M-x er/expand-region
, 'specific-file-name'
will get selected and you can then hit DEL
(or backspace) to delete the selection.
If you have delete-selection-mode
enabled (I like to have that enabled personally), you can start typing away after doing the selection and that will overwrite the selection.
Of course, if you use er/expand-region
a lot, you would bind it to a short key binding. I like to bind it to C-\
. So with point next to a single quote: C-\fname
will give me ref = open(fname);

If point is somewhere inside the quotes
Using expand-region
, the point does not need to be near the quotes. But in this case, you will need just few more (usually one or two more) key strokes.
Let's say the cursor position is as below now:
# cursor shown below is hiding the i character under it
ref = open('specif▮c-file-name')
Using the same binding as I used above:
First time I hit C-\
will select specific
.
Now I just need to hit \
to expand the selection (expand-region
feature). That will select specific-file-name
.
If you had bound er/expand-region
to C-=
, hitting =
again will do the incremental expansion. Read its documentation on how to binding keys for incremental expansion/contraction of selection.
Hitting \
once more will select 'specific-file-name'
.
Now you proceed with hitting DEL
to delete the selection and then type fname
. If delete-selection-mode
is enabled, you can skip the DEL
stroke.
In summary, with delete-selection-mode
enabled, the key strokes look like: C-\\\fname
.

Using change-inner
I also came across change-inner
package by the expand-region
author magnars (which uses expand-region
as back-end) to do exactly what the Vim ci
does (and also change outer).
From the package README:
change-inner
gives you vim's ci
command, building on expand-region
. It is most easily explained by example:
function test() {
return "semantic kill";
}
With point after the word semantic
change-inner "
would kill the contents of the string
change-outer "
would kill the entire string
change-inner {
would kill the return-statement
change-outer {
would kill the entire block