mutt - index search on yanked text - mutt

I'm wondering if there is anyway to "search" or "limit" in the mutt index based on text yanked from either an "edit" or "page" mode.
I'm trying to build a macro for the index, that when pressed will limit the index to only mail from (~f) the From: .*$ regex of the current item.
What this will help me to do is see the context of all the messages from a particular sender... it also helps when people accidentally "break threads" when they shouldn't.
I was hoping it would be similar to vim as discussed here and i could yank text from one area and then type ^R" to paste back into the "search" or "limit" prompt.
I tried to make a macro to go into edit and then search for the from string, but i can't figure out how to paste it back into anything in the index...

Here is an incomplete (and ugly) solution:
macro index O "|grep ^From | awk 'NR==1 {printf \"macro index Q l%s\",$2}' > /tmp/from;echo>>/tmp/from\n:source /tmp/from\nQ"
The O macro will extract the from address from the current message, and save a new macro definition to /tmp/from.
Then it will source that definition, and finally execute it.
Note: I'm having trouble adding newlines in the script (that's the reason for the echo>>, and the need for you to press enter at the end of the limit prompt. Will try to improve this.

Related

Find and replace in Visual Studio code in a selection

I have the following line in a file I'm editing in VSCode:
...............111.........111.............111..
I want to replace all .s with 0s. However, when I highlight the line and do a find/replace for .s, all the .s in the document are replaced, not just the ones in the line I've select, even when I toggle the "Find in selection" button. Is this a bug? In other editors, if I select a chunk of text and then do a find/replace, it will only find/replace matches within the selected block.
Below is a snippet that you should be able to reproduce the issue with. The ...............111.........111.............111.. line is inside the test_unicode function.
def test_simple2(self):
"""Simple CSV transduction test with empty fields, more complex idx, different pack_size.
100011000001000 ->
..........111....................111..........11111..........111..
"""
field_width_stream = pablo.BitStream(int('1000110001000001000', 2))
idx_marker_stream = pablo.BitStream(int('11101', 2))
pack_size = 4
target_format = TransductionTarget.JSON
csv_column_names = ["col1", "col2", "col3", "col4", "col5"]
pdep_marker_stream = pablo.BitStream(generate_pdep_stream(field_width_stream,
idx_marker_stream,
pack_size, target_format,
csv_column_names))
self.assertEqual(pdep_marker_stream.value, 63050402300395548)
def test_unicode(self):
"""Non-ascii column names.
Using UTF8. Hard coded SON boilerplate byte size should remain the same, column name
boilerplate bytes should expand.
100010010000000 ->
2 + 4 + 9 2 + 4 + 6 2 + 4 + 7
...............111.........111.............111..
"""
field_width_stream = pablo.BitStream(int('100010001000', 2))
idx_marker_stream = pablo.BitStream(1)
pack_size = 64
target_format = TransductionTarget.JSON
csv_column_names = ["한국어", "中文", "English"]
pdep_marker_stream = pablo.BitStream(generate_pdep_stream(field_width_stream,
idx_marker_stream,
pack_size, target_format,
csv_column_names))
self.assertEqual(pdep_marker_stream.value, 1879277596)
I'm using VSCode 1.12.2 in Ubuntu 16.04.
I was able to get it to work but the workflow is poor:
control + H to open Find/Replace
Select your line of text
Click the "Find in selection" icon to the right Alt L or ⎇ ⌘ L on macOS)
Enter your find and replace characters in their inputs
Click the Replace all icon
It works but you have to go through the workflow all over again for each new selection (except for CTR + H of course). BTW I have the exact same behavior in Sublime Text.
Could you go with a regExp to find your lines? Do they contain only .'s and 1's?
This is a more general answer for other users who come here just wanting to use basic find and replace functionality.
On Mac you can press Command + Option + F to open Find and Replace:
Alternatively, you can press Command + F to open Find and then click the little triangle on the left to show the Replace field:
From the VSCode devs:
We used to enable find in selection automatically when opening the
find widget with a selection, but it was too easy to trigger
accidentally and produced a lot of complaints. You probably want to
set "editor.find.autoFindInSelection": true which will make it work
the way you expect.
The VSCode GitHub issue has more details if anyone is interested.
EDIT: The autoFindInSelection option is available starting from VSCode 1.13. That version is currently in development (as of 6/7/2017), so this fix won't work until the new version is released.
I found the following workflow to be fairly painless:
Select text region with mouse or keyboard.
Ctrl+H to toggle find and replace
Alt+L to toggle find in selection
Ctrl+Alt+Enter to replace all (or enter to replace individually)
Since sometimes we might have similarly named things so you don't want to select everything, one of my favorites shortcut sequences is to select the next occurrence:
Use shift and arrows to highlight the term you want to match.
Use Ctrl + d to highlight the next occurrence of the term.
The Basic Editing in VS Code documentation page has some extremely useful variations on find and replace. One extremely useful shortcut is the Column (Box) Selection.
Just ran into this, my solution was to do
command + N to create a new file
paste my selection in there
do my find and replace operations on that while file
copy result back on top of my original selection
On Mac:
Select the text
Press command + shift + L
For mac
Press command + option + f to bring up this menu:
Press the little icon that has the arrow pointing at it above (3 horizontal bars)
Select the text you want to do a find and replace in, and enter the 'find' and 'replace' fields
Press this icon:
That's all!
In 2022, there's a bug to be wary of 🐛
There is a silent bug (I'll add more about this as I learn more about it). But sometimes find and replace within selection doesn't find the values, even if you can see them with your own eyes. This is dangerous because you could think you've replaced them all but it really hasn't.
So do these two things:
a visual check after doing a find and replace (to make sure it worked)
if vscode completely ignores you (and doesn't do the find and replace within selection after you've followed the above instructions), close the find and replace box by pressing the "x" in the corner, and retry the sequence of steps (it worked for me after closing and retrying).
Okay, this is really dumb, at first I felt really stupid when I finally found this, then I realized its just VS Code which has a bad interface.
The key is, there are TWO TOOLS here,
Search/Replace (the pane on the left at the top of the Explorer) and Find/Replace (which is a dialogue which opens when you press CTRL-F)
THESE ARE NOT THE SAME TOOL!!
SEARCH-REPLACE is a tool written for project-wide searches and
changes
FIND-REPLACE is a small dialogue best suited for more
surgical editing.
i.e. you should use FIND-REPLACE!
find replace window image with find-in-selection highlighted
Also, its SUPER IMPORTANT to follow these steps in the right order, or it doesn't give the expected results.
Press CTRL-F to open the find dialogue (usually opens in the top right)
press the little arrow to the right of the find field which opens the replace input field
ensure "find in selection" is turned off (i.e. not highlighted)
type in the fields the strings you want to search/replace
select the text you want to do a search/replace within.
Now press "find in selection" (or type ALT-L)
You should see only highlighting in the area you previously selected.
Now you can click either "replace all" (CTRL-ALT-ENTER) or line-by-line "replace" (ENTER)
I hope this helps.
My suggestion to VSC developers, there should be a refresh button so that after you have selected the area of interest, and you already have your find and replace strings defined, you can select a new region and click "refresh find" instead of needing to repeat steps 3 to 8.
For those where it still does not work, there is one step omitted in all of the above answers: Uncheck "Find in selection" if it is checked (which it probably is when you are struggling with it and in despair googled the problem, and then found this SO entry). Only then select the lines and then re-check "Find in selection".
For Ubuntu, highlight the lines where you want to make changes, press alt-L and then ctrl-H. Then type the name you want to replace and replacement name in the top right dropdown.
Or some combination of these actions depending on whether the dropdown is already open or you're already in alt-L mode. I'm still learning but thought I'd share what's working.

Notepad++ search with "Bookmark line" option doesn't bookmark all the lines that match a multi-line regex, but only the first one

I want to filter everything from a log that belongs to a particular user.
With the following pattern, and the ". matches newline" option enabled, I can match everything that I am looking for, but when I ask Notepad++ to bookmark these line so I can copy them, something strange happens.
([^\n]+)userB(.+?)(?=([0-9]{4}-[0-9]{2}-[0-9]{2}))
In front of line 2 and 8 I see a bookmark icon, but the lines: 3,4,5 and 9,10,11 are missing an icon, although they belong to the highlighted text.
Why does Notepad++ highlight the text, but doesn't place the bookmark correctly? And more importantly, how can I fix this?
Here is the log that I am using:
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
2015-03-02 11:28:45,468 WARN application [http-0.0.0.0-8080-9] userB 12:2 some message
extra information
at some.classes.and.function(Filename.java:123)
at some.classes.and.function(Filename.java:123)
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
2015-03-02 11:28:45,468 WARN application [http-0.0.0.0-8080-9] userB 12:2 some message
extra information
at some.classes.and.function(Filename.java:123)
at some.classes.and.function(Filename.java:123)
2015-03-02 11:28:44,993 INFO application [http-0.0.0.0-8080-17] userA 99:7 12345 some message
The following will extract the information you want without using bookmarks and should work in Notepad++ version 6.9.1 onwards.
It assumes that the lines of extra information don't start with a digit.
It deletes the copied lines from the data file so work on a copy of the data file if you want to preserve it.
It is not very efficient because the switch tab command positions the cursor back at the start of a tab's text.
It duplicates the last match for userB. (A minor irritant!)
Description
1) Define shortcuts for switching to next & previous tabs
2) Open the data file with Notepad++
3) Open a new tab then go back to the data file tab
4) Define a macro `Cut User data. Paste in next tab`
5) Run the macro `Cut User data. Paste in next tab` on the data file to `end of file`
(It needs to be run once prior to running it in `Run a Macro Multiple Times`
because of a quirk of Notepad++)
Method
1) Settings Shortcut Mapper Main menu
Switch to previous document = Ctrl+Alt+Left
Switch to next document = Ctrl+Alt+Right
Close
2) Open data file with Notepad++
3) File New Ctrl+Alt+Left
4) Start Recording
Find Find what: .+ userB.+\r\n(\D.+\r\n)*
Search Mode = Regular expression
Find Next Alt+F4
Ctrl+X Ctrl+Alt+Right
Ctrl+End Ctrl+V Ctrl+Alt+Left
Stop recording
Save Current Recorded Macro
Name: Cut User data. Paste in next tab OK
5) Macro Cut User data. Paste in next tab
Run a Macro Multiple Times
Macro to run: Cut User data. Paste in next tab
Run until end of file = Yes
Run then when it has stopped Cancel
(Editted to be an answer.)
At least in the current version of Notepad++ the macro halts while the switch dialog box appears when using the macro solution and switching tabs.
You must first go to settings, MISC., document switcher, and disable both check boxes. This is at least true in v7.6.

Add trailing zeroes to line in notepad++

I have a file containing (hundreds) of blocks of numbers like below;
This one is fine (16x20, correct number of rows and columns)
11111111111111111110
16666616666666661110
16111616111111162610
16111646111663132610
16162616261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261626132610
16166313661116632610
16111111111116132610
16666666666666136610
11111111111111111110
This one needs to be padded with trailing zeroes so it is (16x20)
111111111111111111
166616666666663661
166611111111111661
166666366663661661
113161111111161611
1316166666616161
1616162262616161
11616166112616161
16616166116616161
16616162262616161
16616166266616161
16616111161116161
1661666666666616111
1661666166163366661
1641666166166613661
1111111111111111111
I would like to pad them with zeroes so they are all like the first example. I'm aware of the regular expressions feature in notepad++ but am struggling to get it to work. I appreciate any help given.
You could do it via a macro.
First append a large number of zeroes to the end of each line using a macro.
Caret on the first entry
click record macro
press end
type out 20 zeroes
press down arrow
click stop recording
play the macro until all lines look like this
11111111111111111100000000000000000000000000000000000000000000
16661666666666366100000000000000000000000000000000000000000000
16661111111111166100000000000000000000000000000000000000000000
16666636666366166100000000000000000000000000000000000000000000
11316111111116161100000000000000000000000000000000000000000000
131616666661616100000000000000000000000000000000000000000000
161616226261616100000000000000000000000000000000000000000000
1161616611261616100000000000000000000000000000000000000000000
1661616611661616100000000000000000000000000000000000000000000
1661616226261616100000000000000000000000000000000000000000000
1661616626661616100000000000000000000000000000000000000000000
1661611116111616100000000000000000000000000000000000000000000
166166666666661611100000000000000000000000000000000000000000000
166166616616336666100000000000000000000000000000000000000000000
164166616616661366100000000000000000000000000000000000000000000
111111111111111111100000000000000000000000000000000000000000000
Then...
Caret on first line
click record
press home key
press the right arrow key 20 times
hold shift and press end key
press delete key
press down arrow
click stop recording
play the macro until all lines are processed
You could save the entire process as a single macro so its just a single click in the future.
I can give you a macro solution
go to the beginning of your text
select Macro/Start Recording
press end, press 0 16 times then press Home and down arrow key
select Macro/End Recording
You now have a macro to add sixteen zeros to the end of all lines.
Playback this macro on all lines.
You now have appended zeroes to all lines.
Pressing Alt key and using mouse select the required block(columns) of text you want and paste it into another empty notepad tab
help on column mode editing is there inside notepad ? / help contents menu
Good luck
You can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps:
use the command line cc.aal 00000000000000000000 to append after lines with twenty zero character.
use the command line cc.gc 1/\d{20}/ to get the first column of regex match.
Looking to do this manualy and not progomaticly ?
Open Findreplace
Copy from the last to rhe first WITHOUT NUMBERS on a line so...
in this example
111111111111111111 <---from here
to here ---> 166616666666663661
166611111111111661
paste that into the fine ( yes your effecticly copying the return wich some applications allow you to manualy input others wont )
then in the replace box, type '0' then your return
Hit that magic replace all :D
This will then add a 0 every time it hits a new line, then add a new... new line....
edit : quickly reviewing another method a second to recover for alternate options :P give me 10
edit 2:
Ah ok somthing like this will work :P just tested it.
use [0-9] in the find replace. so if im looking for 123123123123 ( wich is 12 long ) and i need to buff i up to 20,
Your FIND must be in ()
so..
the find would be
([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
and the replace is referd to as \1 no the regex, this was my mistake
\100000000
tested and confirmed !dont forget YOU NEED MATCH ALL on, WRAP off!
And so on for your other numbers, Not sure if you can loop this with macros nd stuff :P but hope it helps more than you have now
two good resources.
http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/comment-page-1/
http://regexpal.com/
base on OP's comment: you could try an editor called vim/gvim
open your file in vim, then type:
:%s/.*/\=printf("%-20s",getline("."))/|%s/ *$/\=substitute(submatch(0)," ","0","g")/
don't forget pressing <Enter> after the above typing.
then you will see the text has been changed into what you want.
of course vim macro can work as well, however, I feel command better... :)

Vim: Invert string (by words)

This is my string:
"this is my sentence"
I would like to have this output:
"sentence my is this"
I would like to select a few words on a line (in a buffer) and reverse it word by word.
Can anyone help me?
It's not totally clear what the context is here: you could be talking about text in a line in a buffer or about a string stored in a VimScript variable.
note: Different interpretations of the question led to various approaches and solutions.
There are some "old updates" that start about halfway through that have been rendered more or less obsolete by a plugin mentioned just above that section. I've left them in because they may provide useful info for some people.
full line replacement
So to store the text from the current line in the current buffer in a vimscript variable, you do
let words = getline('.')
And then to reverse their order, you just do
let words = join(reverse(split(words)))
If you want to replace the current line with the reversed words, you do
call setline('.', words)
You can do it in one somewhat inscrutable line with
call setline('.', join(reverse(split(getline('.')))))
or even define a command that does that with
command! ReverseLine call setline('.', join(reverse(split(getline('.')))))
partial-line (character-wise) selections
As explained down in the "old updates" section, running general commands on a character- or block-wise visual selection — the former being what the OP wants to do here — can be pretty complicated. Ex commands like :substitute will be run on entire lines even if only part of the line is selected using a character-wise visual select (as initiated with an unshifted v).
I realized after the OP commented below that reversing the words in a partial-line character-wise selection can be accomplished fairly easily with
:s/\%V.*\%V./\=join(reverse(split(submatch(0))))/
wherein
\%V within the RE matches some part of the visual selection. Apparently this does not extend after the last character in the selection: leaving out the final . will exclude the last selected character.
\= at the beginning of the replacement indicates that it is to be evaluated as a vimscript expression, with some differences.
submatch(0) returns the entire match. This works a bit like perl's $&, $1, etc., except that it is only available when evaluating the replacement. I think this means that it can only be used in a :substitute command or in a call to substitute()
So if you want to do a substitution on a single-line selection, this will work quite well. You can even pipe the selection through a system command using ...\=system(submatch(0)).
multiple-line character-wise selections
This seems to also work on a multiple-line character-wise selection, but you have to be careful to delete the range (the '<,'> that vim puts at the beginning of a command when coming from visual mode). You want to run the command on just the line where your visual selection starts. You'll also have to use \_.* instead of .* in order to match across newlines.
block-wise selections
For block-wise selections, I don't think there's a reasonably convenient way to manipulate them. I have written a plugin that can be used to make these sorts of edits less painful, by providing a way to run arbitrary Ex commands on any visual selection as though it were the entire buffer contents.
It is available at https://github.com/intuited/visdo. Currently there's no packaging, and it is not yet available on vim.org, but you can just git clone it and copy the contents (minus the README file) into your vimdir.
If you use vim-addon-manager, just clone visdo in your vim-addons directory and you'll subsequently be able to ActivateAddons visdo. I've put in a request to have it added to the VAM addons repository, so at some point you will be able to dispense with the cloning and just do ActivateAddons visdo.
The plugin adds a :VisDo command that is meant to be prefixed to another command (similarly to the way that :tab or :silent work). Running a command with VisDo prepended will cause that command to run on a buffer containing only the current contents of the visual selection. After the command completes, the buffer's contents are pasted into the original buffer's visual selection, and the temp buffer is deleted.
So to complete the OP's goal with VisDo, you would do (with the words to be reversed selected, and with the above-defined ReverseLine command available):
:'<,'>VisDo ReverseLine
old updates
...previous updates follow ... warning: verbose, somewhat obselete, and mostly unnecessary...
The OP's edit makes it more clear that the goal here is to be able to reverse the words contained in a visual selection, and specifically a character-wise visual selection.
This is decidedly not a simple task. The fact that vim does not make this sort of thing easy really confused me when I first started using it. I guess this is because its roots are still very much in the line-oriented editing functionality of ed and its predecessors and descendants. For example, the substitute command :'<,'>s/.../.../ will always work on entire lines even if you are in character-wise or block-wise (ctrlv) visual selection mode.
Vimscript does make it possible to find the column number of any 'mark', including the beginning of the visual selection ('<) and the end of the visual selection ('>). That is, as far as I can tell, the limit of its support. There is no direct way to get the contents of the visual selection, and there is no way to replace the visual selection with something else. Of course, you can do both of those things using normal-mode commands (y and p), but this clobbers registers and is kind of messy. But then you can save the initial registers and then restore them after the paste...
So basically you have to go to sort of extreme lengths to do with parts of lines what can easily done with entire lines. I suspect that the best way to do this is to write a command that copies the visual selection into a new buffer, runs some other command on it, and then replaces the original buffer's visual selection with the results, deleting the temp buffer. This approach should theoretically work for both character-wise and block-wise selections, as well as for the already-supported linewise selections. However, I haven't done that yet.
This 40-line code chunk declares a command ReverseCharwiseVisualWords which can be called from visual mode. It will only work if the character-wise visual selection is entirely on a single line. It works by getting the entire line containing the visual selection (using getline()) running a parameterized transformation function (ReverseWords) on the selected part of it, and pasting the whole partly-transformed line back. In retrospect, I think it's probably worth going the y/p route for anything more featureful.
" Return 1-based column numbers for the start and end of the visual selection.
function! GetVisualCols()
return [getpos("'<")[2], getpos("'>")[2]]
endfunction
" Convert a 0-based string index to an RE atom using 1-based column index
" :help /\%c
function! ColAtom(index)
return '\%' . string(a:index + 1) . 'c'
endfunction
" Replace the substring of a:str from a:start to a:end (inclusive)
" with a:repl
function! StrReplace(str, start, end, repl)
let regexp = ColAtom(a:start) . '.*' . ColAtom(a:end + 1)
return substitute(a:str, regexp, a:repl, '')
endfunction
" Replace the character-wise visual selection
" with the result of running a:Transform on it.
" Only works if the visual selection is on a single line.
function! TransformCharwiseVisual(Transform)
let [startCol, endCol] = GetVisualCols()
" Column numbers are 1-based; string indexes are 0-based
let [startIndex, endIndex] = [startCol - 1, endCol - 1]
let line = getline("'<")
let visualSelection = line[startIndex : endIndex]
let transformed = a:Transform(visualSelection)
let transformed_line = StrReplace(line, startIndex, endIndex, transformed)
call setline("'<", transformed_line)
endfunction
function! ReverseWords(words)
return join(reverse(split(a:words)))
endfunction
" Use -range to allow range to be passed
" as by default for commands initiated from visual mode,
" then ignore it.
command! -range ReverseCharwiseVisualWords
\ call TransformCharwiseVisual(function('ReverseWords'))
update 2
It turns out that doing things with y and p is a lot simpler, so I thought I'd post that too. Caveat: I didn't test this all too thoroughly, so there may be edge cases.
This function replaces TransformCharwiseVisual (and some of its dependencies) in the previous code block. It should theoretically work for block-wise selections too — it's up to the passed Transform function to do appropriate things with line delimiters.
function! TransformYankPasteVisual(Transform)
let original_unnamed = [getreg('"'), getregtype('"')]
try
" Reactivate and yank the current visual selection.
normal gvy
let #" = a:Transform(#")
normal gvp
finally
call call(function('setreg'), ['"'] + original_unnamed)
endtry
endfunction
So then you can just add a second command declaration
command! -range ReverseVisualWords
\ call TransformYankPasteVisual(function('ReverseWords'))
tangentially related gory detail
Note that the utility of a higher-level function like the ones used here is somewhat limited by the fact that there is no (easy or established) way to declare an inline function or block of code in vimscript. This wouldn't be such a limitation if the language weren't meant to be used interactively. You could write a function which substitutes its string argument into a dictionary function declaration and returns the function. However, dictionary functions cannot be called using the normal invocation syntax and have to be passed to call call(dictfunct, args, {}).
note: A more recent update, given above, obsoletes the above code. See the various sections preceding old updates for a cleaner way to do this.
Maybe:
:s/\v(.*) (.*) (.*) (.*)/\4 \3 \2 \1/
Of course you probably need to be more specific in the first part to find that particular sentence. Generally you can refer to match groups as \number with \0 being the whole match.
Here's a way to do by calling out to Ruby. After selecting the line you want to reverse, you can do this in command mode to replace it:
!ruby -e 'puts ARGF.read.strip.split(/\b/).reverse.join'
I found the solution myself thank to your answers and a lot of trying :)
This works:
function! Test()
exe 'normal ' . 'gv"ay'
let r = join(reverse(split(getreg('a'))))
let #a = r
exe 'normal ' . 'gv"ap'
endfunction
Didn't thought that I was enable to write such a function :)

Bash reg-exp substitution

Is there a way to run a regexp-string replace on the current line in the bash?
I find myself rather often in the situation, where I have typed a long commandline and then realize, that I would like to change a word somewhere in the line.
My current approach is to finish the line, press Ctrl+A (to get to the start of the line), insert a # (to comment out the line), press enter and then use the ^oldword^newword syntax (^oldword^newword executes the previous command after substituting oldword by newword).
But there has to be a better (faster) way to achieve this. (The mouse is not possible, since I am in an ssh-sessions most of the time).
Probably there is some emacs-like key-command for this, that I don't know about.
Edit: I have tried using vi-mode. Something strange happened. Although I am a loving vim-user, I had serious trouble using my beloved bash. All those finger-movements, that have been burned into my subconscious suddenly stopped working. I quickly returned to emacs-mode and considered, giving emacs a try as my favorite editor (although I guess, the same thing might happen again).
in ksh, in vi mode, if you hit 'v' while in command mode it will spawn a full vi session on the contents of your current command line. You can then edit using the full range of vi commands (global search and replace in your case). When :wq from vi, the edited command is executed. I'm sure something similar exists for bash. Since bash tends to extend its predecessors, there's probably something similar.
G'day,
What about using vi mode instead? Just enter set -o vi
Then you can go to the word you want to change and just do a cw or cW depending on what's in the word?
Oops, forgot to add you enter a ESC k to o to the previous line in the command history.
What do you normally use for an editor?
cheers,
Rob
Edit: What I forgot to say in my original reply was that you need to think of the vi command line in bash using the commands you enter when you are in "ex" mode in vi, i.e. after you've entered the colon.
Worst thing is that you need to move around through your command history using the ancient vi commands of h (to the left) and l (to the right). You can use w (or W) to bounce across words though.
Once you get used to it though, you have all sorts of commands available, e.g. entering ESC / my_command will look back through you r history, most recent first, to find the first occurrance of the command line containing the text my_command. Once it has found that, you can then use n to find the next occurrance, etc. And N to reverse the direction of the search.
I'd go have a read of the man page for bash to see what's available under vi mode. Once you get over the fact that up-arrow and down-arrow are replaced by ESC k, and then j, you'll see that vi mode offers more than emacs mode for command line editing in bash.
IMHO natchurly! (-:
Emacs? Eighty megs and constantly swapping!
cheers,
Rob
Unfortunately, no, there's not really a better way. If you're just tired of making the keystrokes, you can use macros to trim them down. Add the following to your ~/.inputrc:
"\C-x6": "\C-a#\C-m^"
"\C-x7": "\C-m\C-P\C-a\C-d\C-m"
Now, in a new bash instance (or after reloading .inputrc in your current shell by pressing C-x C-r), you can do the following:
Type a bogus command (e.g., ls abcxyz).
Press Ctrl-x, then 6. The macro inserts a # at the beginning of the line, executes the commented line, and types your first ^.
Type your correction (e.g., xyz^def).
Press Ctrl-x, then 7. The macro completes your substitution, then goes up to the previous (commented) line, removes the comment character, and executes it again.
It's not exactly elegant, but I think it's the best you're going to get with readline.