I know that
:noh
is for "no highlight" - to remove highlighting in text.
Sometimes by mistake I type
:Noh
and it replaces something which I do not know and I have to do control-Z.
What does :Noh do in Vim?
Edit: With command :h Noh, I get help for noh only.
I get this:
:Noh
E492: Not an editor command: :Noh
Built-in commands (except :X) start with a lowercase letter; user-defined commands (via :command) must start with an uppercase letter. (The :help has a case-insensitive search fallback, that's why you've found the original built-in command.)
So, you have a custom :Noh command (or something that starts with these letters and is unique). What that is and where it was defined can be found out via
:verbose command Noh
If you wanted to know that it does (the "replaces something"), you could :debug Noh, or :20verbose Noh.
Related
My goal is to select several words in Vim's visual mode (well, neovim in my case), press leader+L and let fzf show search results for the selected string through :Rg. I came up with this:
vnoremap <expr> <leader>l 'y:<C-U>Rg '. shellescape(escape('<C-R>"', '()[]><')) .'<CR>'
Which does work, but when I select the text options(:modifier) and trigger a search, the escape() command doesn't escape the parentheses and Rg fails to return results.
In short, I'm expecting this command to fire:
:Rg 'options\(:modifier\)'
And I'm getting this instead:
:Rg 'options(:modifier)'
I'm guessing I can't use <C-R> in this context, but I can't seem to figure out why?
UPDATE: Thanks to a helpful reply from user D. Ben Knoble indicating I could drop and construct the mapping differently, I ended up with this, solving my problem:
vnoremap <leader>l "ky:exec 'Rg '. shellescape(escape(#k, '()[]{}?.'))<CR>
You don’t need to—all registers are available as variable’s prefixed with # (all are readable except #_, most are writable, I think).
So instead of <C-R>", use #"
I am working on a Grammar.txt file in vim editor.Is there a way I could give a different color to the '/', so that it is visually more appealing to my eyes.
A lot of my work requires working on paper, and differentiating keywords on screen this way would be helpful.
Here is a small snippet from my file
<Prog> ------ <functions><building>
<functions> ------ <function><functions>/ #
<function> ------ <funsig> <funcbody>
<funsig>------ <type> id (<params>)
<type> ------ int/float/distance/<floortype>/point/wall/doors/window/ratio
<params>------ <type>id<LF1>/#
<LF1>---------comma<params>/#
<funcbody>----- {<stats>}
<stats>----- <stat> <stats>/ #
<stat>----- <assignmentstats>/<returnstats>/<declarativestats>
You could use the :match command:
:match {color-group} /\//
You can get a list of color groups by using the :highlight command without any arguments. Thus, something like this:
:match Function /\//
You can also clear any user-made matches by calling the clearmatches function.
:call clearmatches()
More help on these commands:
:help :match
:help :highlight
Assumed you use search highlighting (:set hlsearch), just search for /:
/\/
Example:
I'd like to complement #EvergreenTree's answer a bit.
Vim has this highlighting capability called matching, which indeed works like this:
:match Error /pat/
The first argument marks a highlight group, a list of which you can check out with :hi. The second argument is a regexp-powered search pattern that needs to be wrapped in / separators. In case of unclear patterns you usually test out the pattern by issuing traditional search. When the pattern looks fine, you can insert the last searched pattern in the :match line by typing <C-r> /. You can clear the highlights by calling :match alone, without arguments.
There are also commands :2match and :3match to highlight more different patterns simultaneously. These work similarly to :match.
If you need even more matches (happens easily with log file analysis), there's a set of VimL functions:
:call matchadd('Function', 'patt')
:call clearmatches()
This time the pattern doesn't need those / separators around it but otherwise the regexp syntax remains the same.
I want to highlight the search keyword in Vim. Mainly I use vim to debug the logs.
I always have to use :se hlsearch to highlight the search keyword.
So, I want the solution that it should set command permanently, and I should not use the command always when vim starts.
Set the command in .vimrc.
Use the following commands:
Open ~/.vimrc file (or create it if it didn't exist).
Add set hlsearch in the file.
Save the file.
Now your search will always be highlighted in vim.
For single time use, just use :set hlsearch in vim, which will be in effect for that instance only.
If you want to highlight multiple searches (in parallel, with different colors), check out my Mark plugin; it also allows to persist the highlightings across Vim sessions through the viminfo file; cp. :help mark-persistence.
For those wanting to visually keep highlighted their search:
:syn match stupid "ctrl + /"
:hi stupid ctermbg=Red guibg=Red
Explanation:
The first line add your regex to a syntax type called "stupid" (note that ctrl + / means you must press ctrl+R then / to get the content of the search registry).
The second line gives a red color to the "stupid" syntax regex.
My SelX plugin allows you to highlight and search for many different things at once on a per-tab basis, with different colours. The highlight config can be saved to a vim session
https://www.vim.org/scripts/script.php?script_id=5875
I use the :split in vim all the time, I however neveer uses :spelldump or :spell* in general.
Is there any way to make :split be the first commmand to appear when autocompleting on :sp ?
Like I said in the comment you don't need to autocomplete for this particular use case, :sp will do the trick. If you enter part of a builtin command that is ambiguous, Vim prefers one command over the other:
:s could be :substitute, :split, :spelldump, etc., but for Vim it is :s[ubstitute]
:sp could be :split, :spelldump, :sprevious, etc., but for Vim it is :sp[lit]
In the help this is indicated with square brackets around the optional part of the command just as is shown above.
To answer the general question: I don't think you can change the way Vim autocompletes commands. You can define your own shorter command (which must be uppercase), e.g. :command! S split. Or you could define a mapping, e.g. :nnoremap \s :split<CR>. Finally, you could use a builtin normal mode command, which for this particular use case is simply CtrlW followed by S.
I often find myself doing
:s/foo/bar/g
*move to different line*
:s/bar/foo/g
on different lines. Is there an easy way to swap them around so that I can execute the second version quickly?
You could try the Abolish plugin (git homepage):
:Subvert/{foo,bar}/{bar,foo}/g
Without plugin:
:%s/foo\|bar/\=submatch(0) ==# 'foo' ? 'bar' : 'foo'/g
The quick use once only option is to do the following
:s/~/<c-r>//g<cr>
~ matches the last substitution and <c-r>/ will insert the current search string from the "/ register. Therefore flipping the substitution. A word of warning is that ~ can only be used once because after the substitution it will be changed. Also doing a search between substitutions will result in the "/ register changing.
As an alternative you could try to use the command-line window to edit the command like text in any other window.
Use q: to open the command-line window from normal mode or press ctrl-f from the command line (assuming the default setting for 'cedit').
Drew Neil has a vimcasts episode that deals with refining search patterns via the command-window which is similar.
:h /~
:h c_CTRL-R
:h quote/
:h cmdwin
:h q:
:h 'cedit'
You can use dict in vim
:%s/foo\|bar/\={'foo':'bar', 'bar':'foo'}[submatch(0)]/g