If I set :set mouse-=a to .vimrc, the highlight color will not be seen when I open the file with vim.
how can I set :set mouse-=a automatically when I use the vim editor with the previous feature(color, etc.)?
The syntax in .vimrc is set mouse=a.
You only use a preceding colon when you are using the command pallet accesed by pressing escape key.
The correct syntax in .vimrc to enable your mouse's usage is the following:
set mouse=a
It appears, according to your question, that you have added a hyphen character(-) before the equals sign, making it -=, when it should just be an equals sign (=).
Could you please make sure to remove the hyphen and see if it works after that?
Related
Today I have discovered vim's relativenumber option. I really would like to use it, but sometimes I need to swap between relative numbering and classic one.
I have tried to turn it off with :set relativenumber=off option (which returns me error attached above) and using :set number again but none of those works.
To turn on relative line numbering use this:
:set rnu
To turn it off use this:
:set nornu
By the way, if you had Googled around for your question, you would have found this great post which discusses things in more detail.
To turn on whatever option in vim:
:set <option>
To turn off whatever option in Vim:
:set no<option>
To toggle an option on/off:
:set <option>!
To check if an option is on or off:
:set <option>?
To set an option back to its default:
:set <option>&
I just use this toggle switch in my vimrc file.
function! NumberToggle()
if(&rnu == 1)
set nornu
else
set rnu
endif
endfunc
nnoremap <C-l> :call NumberToggle()<cr>
Relative Numbering is not turned on by default in vim, which means that you are probably turning it on through your ~/.vimrc file or one of your plugins. Look for set relativenumber or set rnu.
To turn it off for the current vim session you would simply run set norelativenumber or set nornu for short. This is a normal vim pattern for turning on and off settings like this. For example, spell check is set spell to activate and set nospell to deactivate.
To find this information and more on relative numbering, I recommend that you look in the vim help docs. For this case, while in vim run :h relativenumber
You actually have hybrid mode on (the line number your cursor is on is labelled as the absolute line number, not 0). In this case, both nu and rnu are on. You'll need to remove both to remove line numbers:
The following should work:
set nornu nonu
I am a new vim user and trying to turn on syntax coloring for vim on Mac OS X. I followed http://vim.wikia.com/wiki/Turn_on_syntax_coloring_in_Mac_OS_X's instructions, and my ~/.vimrc file has the following content
set term=builtin_ansi
filetype plugin indent on
syntax on
And the text above in ~/.vimrc is highlighted perfectly fine. However, whenever I use vim to edit a current text file or create a new one, I only see black and white text, and manually calling :syntax on does nothing. Any help is apprecaited!
You can use the :highlight command to list all defined groups (according to your colorscheme). A plain text file probably has no filetype and therefore no syntax assigned; you want to try this with any programming language (e.g. *.py or *.c) to see syntax highlighting in action.
Your ~/.vimrc looks fine. (Do you really need the :set term, though?!)
You should remove that useless line:
set term=builtin_ansi
Do you use the default Vim? What filetypes are you editing?
I am editing Markdown using Macvim and may I know is there anyway that I can set it, so that whenever I enter, the space indent on the previous line is maintain. I don't want to use TAB for every single line. Thanks.
Try enabling the autoindent option:
:set autoindent
or:
:set ai
Explanation from Vim manual:
'autoindent' 'ai' boolean (default off)
local to buffer
Copy indent from current line when starting a new line (typing <CR>
in Insert mode or when using the "o" or "O" command).
I can't stop vim from wrapping my Python code. If I enter :set nowrap like a champ, but it still wraps.
I can hit J to unite the split lines of code, so it seems like a real carriage return is being inserted. I just don't understand why or how to stop it.
'textwidth' 'tw' number (default 0)
local to buffer
{not in Vi}
Maximum width of text that is being inserted. A longer line will be
broken after white space to get this width. A zero value disables
this. 'textwidth' is set to 0 when the 'paste' option is set. When
'textwidth' is zero, 'wrapmargin' may be used. See also
'formatoptions' and |ins-textwidth|.
When 'formatexpr' is set it will be used to break the line.
NOTE: This option is set to 0 when 'compatible' is set.
'wrapmargin' 'wm' number (default 0)
local to buffer
Number of characters from the right window border where wrapping
starts. When typing text beyond this limit, an <EOL> will be inserted
and inserting continues on the next line.
Options that add a margin, such as 'number' and 'foldcolumn', cause
the text width to be further reduced. This is Vi compatible.
When 'textwidth' is non-zero, this option is not used.
See also 'formatoptions' and |ins-textwidth|. {Vi: works differently
and less usefully}
If you refer to auto wrapping of long lines sending them to the next one, try
:set textwidth=0
:set wrapmargin=0
None of the other answers worked for me (IDK why).
:set wrap! Did the trick for me (using GVim for Windows).
set formatoptions-=t should do the trick. set formatoptions+=t will turn auto-wrapping back on.
For more information on what you can do with formatoptions, see the docs.
For preventing vim from wrapping long lines I use these two lines in my .vimrc:
set nowrap " do not automatically wrap on load
set formatoptions-=t " do not automatically wrap text when typing
To disable line wrap, you can enter
:set wrap! or append this command to your ~/.vimrc.
Maybe it's the textwidth that's set, which automatically breaks lines when it reaches a certain length
Try
:set tw=0
If that fails play with e.g.
:set wrap linebreak textwidth=0
and
:set virtualedit=insert
Vim may have to be in vi-compatible mode.
Open vimrc_example.vim (Yes, this is the file in Vim74) and set textwidth=0.
On macbook pro I outcommented in .vimrc the line
autocmd FileType text setlocal textwidth=78
so it became
" autocmd FileType text setlocal textwidth=78
.
(I installed a version of vim via homebrew.)
This helped for all .txt files.
I used textmate to work with ruby code for over one year. Recently I switched to using mvim. When I open some of the files in mvim I get empty blocks. Look at this picture to get a feel for it.
Any idea on how to get rid of them?
Thanks
Others have explained that this could either be a search highlighting spaces or tabs or (more likely) it could be highlight designed to show up mixed indentation (particularly useful in python for what it's worth). I find this very useful personally.
Anyway, there are a number of options to sort out your highlighting depending on the cause:
To clean end of line spaces (as mentioned by chaos), use something like:
:%s/ \+//
Probably the most useful one: tidy up the tabbing:
If you're using spaces for indentation:
:set expandtab
:retab
If you're using tabs:
:set noexpandtab
:retab!
If you're using tabs for indentation and spaces elsewhere:
:set expandtab
:retab
:set noexpandtab
:execute '%s#^\( \{'.&ts.'}\)\+#\=repeat("\t", len(submatch(0))/'.&ts.')#'
I have the last line mapped to a command called :RetabIndents. All of those assume that your tabstop setting is correct (it should be set with set ts=2 based on your picture). Personally, I'd also recommend keeping shiftwidth equal to tabstop, so set ts=2 sw=2.
You may also be able to get away with a simple gg=G (auto-indent the whole file). However, this won't work in some languages (in particular python as there's no way for any editor to know which lines should be indented to which level).
To switch off search-based highlighting temporarily:
:noh
Or permanently (put this in .vimrc):
:set nohlsearch
Or a quick shortcut for when you've used it and don't want it anymore:
:nnoremap <ESC> :noh<CR><ESC>
To switch off indent highlighting, you'll have to identify which highlighting group is used, which is a little complicated and is probably easiest to just read your .vimrc, but if you really want to search for it, move the cursor to one of the highlighted characters and enter (taken from here):
:echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
You can then clear the highlighting group by searching for the name that is reported on the command line in your .vim/.vimrc/_vimrc/vimfiles configuration and commenting out anything relevant.
For more information
:help :s
:help 'expandtab'
:help :retab
:help :execute
:help 'tabstop'
:help :noh
:help 'hlsearch'
It's looks like highlighting of redundant whitespace (see line 214 for example)
Is there anything in your .vimrc along the lines of..
highlight RedundantSpaces ctermbg=grey guibg=grey
match RedundantSpaces /\s\+$\| \+\ze\t/
..try commenting it out, and seeing if this fixes the problem
I guess the reason it's highlighting the indentation is vim is configured to expect tabs, no spaces (or vice versa) - again make sure your .vimrc is setup correctly (say, using soft-tabs)
It looks like you might have a search pattern stored that highlights spaces at the beginning of the line: /^ + and your highlight color is light gray.
To get rid of it, try searching for something else: /asdf<ENTER>.
If you want to get rid of hanging spaces on the ends of lines (they always annoy the hell out of me, honestly), this command will strip them from a given file:
:%s/ *$//
As Seth mentioned, these are spaces. Essentially, mvim is showing you the spaces that are placed in your file by coloring them grey instead of black.
Personally, I think this is a feature, you can use this highlighting scheme to identify where you may have trailing spaces, and can use it to make your code look neater.
You could probably get it to go away by adjusting the highlighting options.