Separate Vim spellfile for custom words - vim

I just started using the spell checking feature in vim. According to the documentation, zg adds the current word to the first spellfile.
Is it recommended to create an own, empty spellfile, so that the English one doesn't get littered? If so: How do I create an empty spell list? An empty appropriately named file yields "E757: This does not look like a spell file".

Using your own additional spell files is both the recommended and default way of doing custom spelling. In Vim you have a 'root' spell file based on the current language and encoding, and an optional quantity of 'additional' spell files.
The easiest way to create an additional spell file (if you haven't already) is simply to add or remove a word using zg or zw - If 'spellfile' is empty, an new additional spell file will be created in the first writeable directory in 'runtimepath'.
The naming of spell files can be a bit tricky. Firstly, Vim takes a text file containing a list of words and converts it into a binary file which is a lot quicker to work with internally. The reason you're getting an error E757 is that Vim is attempting to load the binary spell file, but it's not finding the marker text at the start of the file, so it's bailing out.
To create your own spell files the filename needs to be in the format "mySpellFile.en.utf-8.add" where spelllang=en and encoding=utf-8.

Related

How to create a centralized syntax file that be able to recognize multiple parts with different syntaxes?

For i.e: I'd like to have a custom syntax file, may be called sugar.vim that includes multiple other syntax files(?) to have the ability to highlight, maybe a paragraph as python.vim and another paragraph as javascript.vim, may be separated by newline (paragraphs often distinct by newline)
The real case that I often catch myself writing a document (non-extension file) other than real config a specific filetype (specific extension file), but for clear readability in the document filetype (we called sugar above). I'm thinking about a mechanism to recognize and highlight different parts of a filetype as different syntaxes.
To narrow down this case. How would it be to have a syntax file called sugar.vim that would be able to recognize python syntax and javascript syntax in files that have an extension of .sugar then the recognized python text should have highlights applied as a normal python file, same for javascript part. All recognized text must be separated by newline (at least one before and one after that text)
Sample:
# this is a sample text for this question
# i'm writing a document that has an extension of `.sugar`
def py_func1(arg1, arg2) # python.vim and its highlights applied here.
print("bello world!")
square = function(x) { # javascript.vim and its highlights applied here.
return x * x;
};
System: gvim 8.1 / windows10
Thanks in advances.
Vim supports that with the :help :syn-include command. As it's intended for syntax script writers leveraging other syntaxes, its use is somewhat complicated, and it's not really suited for interactive, on-demand use.
My SyntaxRange plugin provides commands and functions to set up regions in the current buffer that either use a syntax different from the buffer's 'filetype', or completely ignore the syntax. With it, it's trivial to dynamically add a particular syntax highlighting for a range of lines, and public API functions also make the programmatic definition easier.
You're looking for :help :syn-include.
Excerpt from vim help :
If top-level syntax items in the included syntax file are to be
contained within a region in the including syntax, you can use the
":syntax include" command:
:sy[ntax] include [#{grouplist-name}] {file-name}
All syntax items declared in the included file will have the
"contained" flag added. In addition, if a group list is specified,
all top-level syntax items in the included file will be added to
that list. >
" In perl.vim:
:syntax include #Pod :p:h/pod.vim
:syntax region perlPOD start="^=head" end="^=cut" contains=#Pod
When {file-name} is an absolute path (starts with "/", "c:", "$VAR"
or "") that file is sourced. When it is a relative path
(e.g., "syntax/pod.vim") the file is searched for in 'runtimepath'.
All matching files are loaded. Using a relative path is
recommended, because it allows a user to replace the included file
with his own version, without replacing the file that does the ":syn
include".
As long as you can clearly define boundaries for your embedded language regions it is fairly straight forward to achieve this.
You can also refer to https://github.com/tpope/vim-markdown/blob/master/syntax/markdown.vim for reference on how tpope embeds other syntax definitions within the markdown syntax, driven by configuration to minimise the number of language syntax's that need embedding for optimal performance.

How to force vim spellchecker to ignore lowercase/uppercase errors

I found here and here how to force Vim spell checker to ignore words with capital letters from being check. But my case is quite opposite. I want to ignore words that in corrected form include capital letters.
So in sentence:
europe was chozen best
only word chozen is the wrong one.
How to achieve that?
Thanks for any hint.
This answer was posted first by Rich on vi&vim stackexchange:
I don't think that Vim has a setting for this. One workaround is to
create a new spellfile that contains everything in your current spell
file(s) but with lowercase letters only:
Create a new buffer containing everything from the spell file(s) currently in use:
:spelldump
Delete lines that don't contain any upper-case characters. This isn't strictly necessary, but there's no point keeping duplicate
entries for lower-case words:
:v/\u/d
Convert the entire file to lower-case, ignoring lines that contain the locations of the spell files:
:v/^#/norm gu$
Save the file:
:w ~/.vim/spell/lowercase.utf-8.add
Start using this file in addition to the standard files in Vim's $VIMRUNTIME directory. Note that Vim uses a default 'spellfile'
value internally if the setting is empty, so if you already have any
existing spell files, you will need to ensure that they are included
in this setting (which accepts a comma-delimited list):
:set spellfile=~/.vim/spell/lowercase.utf-8.add
Note that if you set this option in a running instance of Vim, it
doesn't seem to take effect for spell-checking until you interact with
it (by, e.g. using the zg command.)
The above doesn't affect the way that Vim detects lower-case words at
the start of a sentence as spelled incorrectly. You can disable this
with the 'spellcapcheck' option:
:set spellcapcheck=

Cscope Syntax hightlight search within search

I am using CSCOPE for my project and I have few question.
1) Can I color the search result (mostly when I serach using
":cs f s " i.e. within the open file.
2) Is there a way to search within search? Like I search "ret_val" and it gave 1000 result, instead of going each line, can I search some more like folder name etc?
I am not sure how you use the tool, but generally, the answer is yes.
1) You could either redirect results to file, lets say out.cscope then create syntax file for file type *.csope OR, use a function to run the tool, then locally set up the buffer with adequate hi and match options
2) If you saved search results in a cscope file then you can search it normally. Otherwise you can redir output to new tab/split and again search the buffer (which now doesn't need to have externally associated file. I suggest you to use vim-foldsearch plugin to fold out anything (not) in the match. You can even delete folded sections (with or without any number of context lines) so that only stuff you are interested in finally remains in the buffer (i.e. it behaves like filter). Alternatively you can use unite plugin and it filtering source lines which filters lines as you type the keyword. Actually, I would personally go with that option as it provides most interactive way of working.

Ignore one "misspelling" in Vim

Is there a way to tell Vim not to highlight a word once? For example, in "the password is abc123", I don't want to add abc123 to the wordlist, but still wouldn't like the big red rectangle around it.
Clarification: I'm looking for a command that makes the spell checker ignore the current word (or last misspelling).
Without having the word stored somewhere, it's hard (not to say impossible) to ignore it always.
But, if you are looking to ignore the word really once, that is only for a moment, you can add it to the internal list with the zG command.
*zG*
zG Like "zg" but add the word to the internal word list
|internal-wordlist|.
*internal-wordlist*
The internal word list is used for all buffers where 'spell' is set. It is
not stored, it is lost when you exit Vim. It is also cleared when 'encoding'
is set.
When your cursor is positioned on a word that is highlighted as misspelled you can add it to your wordlist by pressing zg. Vim allows you to load more than one wordlist at a time, which makes it possible to have (for example) a global wordlist, and a project specific wordlist.
By default, when you run zg it will add the current word to the first spellfile it finds in your runtime path for the current encoding. In my case, that turns out to be ~/.vim/spell/en.utf-8.add when I'm working with UTF-8 encoding. Try running the following commands:
:setlocal spellfile+=~/.vim/spell/en.utf-8.add
:setlocal spellfile+=oneoff.utf-8.add
That will set you up so that zg (or 1zg) adds the current word to your default spellfile. But running 2zg would add the current word to a file called oneoff.utf-8.add, in the same directory as the file that you are working on. If the file doesn't exist, Vim will try to create it for you.
When you open the file again in the future, you will have to run the same two commands to make Vim check the oneoff.utf-8.add spellfile. Unfortunately, Vim does not allow you to set the spellfile option in a modeline, so if you want to run these commands automatically when the file opens, you would have to find some other way. This question includes a few ideas on how you might proceed.

Reload tags file Vim

How do i reload the tags file from within Vim?
Is a restart necessary?
According to :help tag-binary-search, the tags file is binary (or linear) searched on each lookup, so there's no need to reload the file:
*tag-binary-search*
Vim uses binary searching in the tags file to find the desired tag quickly
(when enabled at compile time |+tag_binary|). But this only works if the
tags file was sorted on ASCII byte value. Therefore, if no match was found,
another try is done with a linear search. If you only want the linear search,
reset the 'tagbsearch' option. Or better: Sort the tags file!
Note that the binary searching is disabled when not looking for a tag with a
specific name. This happens when ignoring case and when a regular expression
is used that doesn't start with a fixed string. Tag searching can be a lot
slower then. The former can be avoided by case-fold sorting the tags file.
See 'tagbsearch' for details.
As far as I know it is not necessary Vim 7.3 use the tags file as soon as it has been generated.
I find it helps to just load the tags file in another buffer/tab. Then I can re-load that buffer with :e! to get vim to see my tag updates.

Resources