Like most, i have enabled hlsearch in vimrc.
so, all my text searches are highlighted.
But, when i use 'f' command to move to a letter and use ';' command to repeat, vim highlights all the occurrences of the character overriding my previous text search.
how can i make vim just move to the character without interfering with my text search keyword?
You've likely found a bug in the ft_improved plugin; you should report that to the plugin's issue tracker.
Alternatively, you can also check out an alternative; Extended-FT and Fan,FingTastic are two. Also, using vims f command over multiple lines has some light-weight implementations in the answers.
Related
How do i remove the row lines at the start of the line? I typed the command
:s/^/# /
while in command mode and it suddenly appeared. I typed the command again, but it's still in my editor. I was trying to comment out a few blocks of code. This is the stackoverflow page I was following: What's a quick way to comment/uncomment lines in Vim?
Please see the image below to see what I'm pertaining to. Thanks in advance!
Vim highlights the current search pattern; this is the 'incsearch' option; either you have it explicitly turned on in your ~/.vimrc, or you use a recent Vim 8 version that has this enabled by the defaults.
Check with :hi IncSearch; it should show the same white-underscore-onblack formatting as your screenshot. You can also use a :hi command to customize this (or choose a different colorscheme).
To turn this off, use
:nohlsearch
You can shorten that to :noh; some people also define a mapping to quickly clear this. Alternatively, you can also search for something else.
When I issue an ex command in the vim command line, e.g. :% s/^I/ /g (replacing all tabs in file with spaces -- the ^I is not carat-capital-i, it's the tab character entered by typing Tab or Ctrl+i), I end up with only the replacement operation affecting the first match within the lines specified.
Then on a hunch what I tried the command without the g flag, :% s/^I/ /
This worked and did the job on all the tabs.
This is backwards!
Why?
I have a ludicrously huge .vimrc, it is 1199 lines as of today, so it's pretty certain that something in it or in the plugins I use is causing this behavior. However, especially now that I have found the way to get the global flag working again, I am certainly not looking to sacrifice any of the plugins or even really attempt to do some kind of manual binary search hunting to blindly narrow down the cause of this, as that would take too long.
If the 'gdefault' option is on, this flag is on by default and the [g]
argument switches it off.
Update:
The 'Feng shui' way to get to this line in the docs is :h :s, then CTRL-] on ":s_flags"
I like to use "*" to search text in vim. after hight light the target text, I want to edit all of them, is there any way I can do it in vim? for example, after highlight text, I just need to press ctrl+i then the highlight text can be edited simultaneously
Simultaneous editing (like seen in other editors) is not built into Vim (but there are plugins). You don't need them, though. After *, the text is stored in the last search pattern register, and you can just :substitute// without repeating what you're searching for:
:%s//replacement/g
The % is a range and applies this to the whole buffer; the /g is a flag that replaces all (globally) instances, not just the first in each line. Read :help :s for details.
You can check out the vim-multiple-cursors plugin.
Personally, I like #Ingo's solution. The less plugins the better.
As a nice alternative. You can use gn and the . command.
Set your search pattern i.e. * or /foo
Change your highlighted pattern via c operator over the gn motion
cgnbar<esc> will change the highlighted area to bar.
Now you can use . too repeat this change. You can also use n to skip places.
Note: This requires at least 7.4
For more help see:
:h gn
:h .
If you wish to edit the word with another you can use the substitute command. (e.g. :%s/hi/hello/g)
This will change all occurrences of hi to hello in the file.
I'm currently trying to switch from gedit to vim. I try to make vim look similar to gedit:
Especially, I would like to show spaces with dots.
I currently have:
There are some differences, but it looks quite similar (this is my current .vimrc file). But I don't get those dots for spaces.
How can I make vim show spaces?
I found some answers (like this one) that seem to suggest to replace spaces by a special visible character and then replace it back. I don't want to do this every time. I want to be able to open vim and see those spaces.
Show non-space whitespace with
set list
Additionally show spaces as . with
set lcs+=space:·
Turn it off with
set nolist
There are times when I absolutely need to see which whitespaces are tabs and which are true space characters, as well as when spaces appear at the end of a line.
When I'm using vim, I use:
:set list
(which I can turn off with :set nolist)
With :set list, literal spaces show up as spaces, tabs show up as ^I, and the end-of-line shows up as a bright-pink $. (So any blank space you see to the left of the pink $ you'll know is a true space character, and the blank spaces to the right of it is just the "nothing" between the end-of-line and the right side of the editor.)
It's ugly, but it works well.
I don't recommend using it all the time -- just those times when it is crucial to see where literal spaces and literal tab characters exist.
While you can't do exactly what you want here, if your reasoning is like mine, you're wanting to see those spaces because it helps verify proper indentation (do I have 2 spaces there, or is it 3?). For Vim >= 7.3, you can use the indentLine plugin to add a marker at each indentation. It's awesome.
To install if you're using Pathogen:
cd ~/.vim/bundle
git clone https://github.com/Yggdroot/indentLine
It may be worth using undercurl to do the job.
hi WhiteSpaces gui=undercurl guifg=LightGray
match WhiteSpaces / \+/
or you can put this in your .vimrc
autocmd ColorScheme * highlight WhiteSpaces gui=undercurl guifg=LightGray | match WhiteSpaces / \+/
Show leading spaces (indent spaces) using the above mentioned plugin indentLine.
If you use Vundle as plugin manager you can add Plugin 'Yggdroot/indentLine' to your .vimrc and then run vim +PluginInstall +qall to install the plugin.
Add the following two lines to your .vimrc to show leading spaces as ·.
let g:indentLine_leadingSpaceChar='·'
let g:indentLine_leadingSpaceEnabled='1'
Using the answers of J-L and Cedric Simon. Edit ~/.vimrc and add:
set lcs+=space:·
nmap <F2> :set invlist<CR>
imap <F2> <ESC>:set invlist<CR>a
and when you work with vim just pres F2
Vim has been providing the 'listchars' option to show Tab vs. Space, and space characters in critical places, i.e. trailing at the end of lines. In previous versions (when the question was written), it did not offer a modification for all spaces: a blank square is a space, period. Other answers provided some workarounds, though.
In current Vim versions, there are many space-related options; cp. :help 'listchars' for details.
You can get the effect seen in your screenshot; persist by putting that command into your ~/.vimrc:
:set list listchars+=space:. listchars-=eol:$
You don't need to install any plugin to this:
set listchars=tab:\|\
"set listchars=tab:\┊\
"set listchars=tab:\┆\
"set listchars=tab:\¦\
set list
I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $ with a \n^, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5 will highlight 5 fewer characters, but he=he+5 doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
It is possible to highlight an entire
line using the :sign mechanism.
An example can be found at :help
sign-commands
In a nutshell:
:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt
Obviously, you should pick a higlight
group that changes the color of the
background for the linehl argument.
source: Erik Falor, vim mailing list
From the documentation on syn-pattern:
The highlighted area will never be
outside of the matched text.
I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line