How to correct spelling in entire file? - vim

Spelling mistakes can be fixed by pointing the cursor on the misspelled word and pressing z= (a list appears and you can select correct word). But this will fix the mistake only once (on current word). This is not that much of us will want, most will be happy to do replacement in entire file. How can I do so?
Unsuccessful Attempt:
I got an idea of substitute that mistake with correct one (i.e. :%s/badspell/goodspell/g). But the bad part of this is, it is painful. First I need to (atleast) correct a word, then store bad spelling and corrected spelling in my buffer (brain), then write the command for substitution (chances are I will do mistake in writing bad spelling and good one.). Though its time taking too.
There's a similar question on StackOverflow which says I can solve my problem with doing :spellrepall after the correction. The only problem is I don't want to all this typing. I want to automate this everytime there is a spelling correction.
And don't suggest me about plugins.

you can set the spell on in .vimrc
set spell
or if u execute this on vim directly do in vim command mode.
:set spell
Once the spell is on, you need to know following command:
]s — move to the next mispelled word
[s — move to the previous mispelled word
zg — add a word to the dictionary
zug — undo the addition of a word to the dictionary
z= — view spelling suggestions for a mispelled word

If most of the time you're selecting the first fix from the query you can use a remap for 1z= as such:
nnoremap 1z= 1z=:spellrepall<cr>
Although I would recommend binding :spellrepall to a seperate key as many people already suggested. I highly doubt you have run out of keybindings with all those <leader> and <localleader> combos. (something like <leader>z would be a perfect candidate for this)
I don't think this can go any easier without you loosening your expectations.

Related

Single key for dwi or dei in Vim

Is there a single key for doing dwi or dei (Substitute a word) in Vi(m)? I use this enough to warrant saving 2 extra keystrokes.
Run vimtutor
Learn about c. There isn't a single key. c[motion] is the same as d[motion]i.
You do not want a single key for that. Yeah I am serious. That's not how Vim works. Vim is modular. You first think about what you want to do, in your case you want to change something. Then you need to know what you want to change, in your case a word. And voila! cw is the sequence to use.
Of course there is but more to think of. Do you need a word or a WORD? Do you want to change around the word (caw)? And so on.
But the important part is, Vim is not a collection of functions, it is a language to modify text. It is always a chain of actions. Sure you could say, ciw is so common it should have a shortcut, then you can map it. But it will only make Vim harder to use.
Thinking about changing a whole sentence? Yeah, it is cs. The same goes for deleting, or yanking and nearly everything else.
So if you map everything you need often to a single command, instead of a chain of commands like in vanilla Vim, you lose everything which makes Vim better than any other editor and you will end up with a worse Emacs...

alter vim's mode indicator text to just the first letter in airline

I have vim with airline, that tells me which mode I am in. I would like to change it so that rather than the whole word it just displays the first letter. So N, I or V. Although I can find instructions for changing colours of the mode indicator, I can't find the command to add to my .vimrc that will change the text.
What do I add?
I don't use the plugin, but was able to locate the information in its help almost immediately.
You're looking for the g:airline_mode_map configuration; the example even does exactly what you're asking for (single mode letters), so just copy-and-paste the fragment into your ~/.vimrc!
Also, I would recommend to open an issue / ask the plugin author next time. It might take a bit longer until you get an answer, but it alerts the author about things that aren't yet documented or are hard to find in the documentation, so he can improve it.

Spellchecking in Vim - tell Vim that this is okey

Yes, that title is the best I could come up with :-)
I have a text, and when activating spellchecking naturally a lot of words come out highlighted. Like emails, adresses, names and so on. How to tell Vim that some word is okey, without adding it to the wordlist.
Meaning, just, while editing this document I don't want to see my name highlighted.
Try: zG
:help internal-wordlist
From http://vimdoc.sourceforge.net/htmldoc/spell.html
zg Add word under the cursor as a good word to the first
name in 'spellfile'. A count may precede the command
to indicate the entry in 'spellfile' to be used. A
count of two uses the second entry.
In Visual mode the selected characters are added as a
word (including white space!).
When the cursor is on text that is marked as badly
spelled then the marked text is used.
Otherwise the word under the cursor, separated by
non-word characters, is used.
If the word is explicitly marked as bad word in
another spell file the result is unpredictable.
I have my Vim config in a git repository, which is useful for several things; For example, you could alias your vim to a small script that invokes Vim normally, but after Vim finishes checks if the ~/.vim/spell directory has any modifications and if so, asks you if you want to keep or discard them. If you want to keep them, it could automatically commit everything in spell and otherwise reset everything in there. So you usually wont be bothered by that script unless you actually do use the spellchecker.
The only drawback would be that you couldn't both make persistent and volatile additions to the dictionary in one session.

Get the last search or search&replace string back in vim?

How can I bring back the last string I used for a search or a search&replace?
For example, assume that I enter :%s/some_text/some_other_text/gc and vim gives me the E486: Patterns not found: some_text error message back. I then realize that I actually meant to write some_magic_text instead of some_text. At that point, how can I get back my original string in the bottom command row (or whatever it is called) so I can change it and do a second search? Is there a nifty little command for that?
In this brief example it looks unnecessary, but when the text you are looking to replace is mighty long and you just typed one letter wrong, it is fantastically annoying to have to retype everything.
And I am using MacVim if that makes any difference.
From the normal mode, hit q/ to navigate through your search history!
Check out this vimvcast which explains what you want.
More generally, you can recall any command you have previously typed by entering the first few characters, and then use arrow multiple times to navigate in history.
In your case, you could type:
:%s<Up>
See :help history
This answer might be good an improvement to what you are after, after all.
Use search with highlighting, to interactively check if the regex you are crafting is definitely working, and then use it in a search-replace.
:se is (incsearch, better put se is in your .vimrc)
/<search term>
check with n/N if you are happy with the matches
:s%//<replace term>/g
When omitting the <search term> in the search-replace in 4., the last used search will be used.
For acessing the list of last (search-replace) commands use q:, or as already noted q/ for the list of last search terms.
Bonus:
When using :se gd, s/<search>/<replace> will behave as s/<search>/<replace>/g.
Accessing just the first search match in each line can then still be done with adding /g, so essentially both behaviours are just switched.
/ and then up to bring up the last search query.

Preprocessing a word before spell checking in Vim

I use Vim's spell checking to validate texts in Russian. We have letter ё in our alphabet which is often replaced with simple е. So, for example, word ёжик из written as ежик. It is a bad tone actually. Its like using - (hyphen) where — (em-dash) is required, like using "computer" quotes forgetting about existence of „typographic” «quotes», etc.
The bad thing is that spell dictionary for Vim composed out of simplified words with all ёs, replaced with еs. So I always get an error in a word with ё.
So the question, is there any hook I can use that will allow me to normalize a word just before it will be spell checked? Or maybe someone has a better idea? Thanks.
UPDATE
With the hint from #sarnold, I found the solution. One should use ru_yo locale instead of ru_ru if he wants ёёёёё
My first thought when reading your post was to suggest using zg to add the word to the spellfile; after a few weeks you'll have a lot of them. Not ideal, but simple.
:help spell-russian lists several different spelling variations, would one of these help?
I also notice in :help spell.txt that there are options for downloading your own spellfiles from OpenOffice or http://www.a-a-p.org to automate building spellfiles.
I would recommend you to use your own spell checking for vim. Use a method #2 explained here

Resources