Your approach is valid. This is a textbook example on how to use :substitute
.
The command
:%s/\.fits//
(the trailing slashes can be omitted) will remove the first ".fits" in each line of the buffer.
The actual solution
OP commented that the :substitute
command only worked if the trailing slashes weren't omitted. Apparently only
:%s/\.fits//
worked.
All the stuff below is me trying to troubleshoot a problem that never existed. I'll leave it around for your amusement.
Since it's not working - and assuming you did not manage to break :substitute
in your Vim - the fault must be with the CSV file rather than with the command. I think ".fits" in your command does not match ".fits" as it's in the file.
Three approaches on how to find the error are detailed below. Each would work on their own but you can also combine them.
Highlight search results
An easy way to see if your search pattern is correct is to :set incsearch
which will highlight matches as you type and before you actually run the command.
:set incsearch
:%s/\.fits
If you mistype, the highlight will be gone and you can go back and fix it.
Copy and paste into the command
You could also copy ".fits" into your command line by first yanking it. Place your cursor on the dot starting ".fits" and press yE
. Then start typing the command as :%s/
and put ".fits" there with Ctrl-R". Run the command.
In short, that's:
yE:%s/<C-R>"<CR>
No matter how ".fits" was actually spelled, it will be removed.
Check the spelling
It's also possible to inspect the characters in your CSV file as laid out in the answer to See the Unicode code point of the current character. You can use ga
on each character of ".fits" to see if it fits (sorry for that) the ASCII range (0 to 127). For example, there's the fi ligature that will look like "fi" - well, it should - but is one character, not two.
Can you spot the difference: fififififififi
?
A note on finding :help
In your question you say your command was "based on a couple other SO posts". That's one way to learn Vim but you could also read :help :s
which contains the reference on how to use the :substitute
command. Having the documentation all in one place right in front of you might be easier than gathering bits and pieces scattered all over the internet.