When I edit html, I have highlights like this picture
I don't want it highlighted. FYI this is my .vimrc
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/vundle/ " set the runtime path to include Vundle and initialize
call vundle#rc()
" Bundle 'gmarik/vundle' " let Vundle manage Vundle, required
Bundle "wookiehangover/jshint.vim"
Bundle "mru.vim"
Bundle 'godlygeek/tabular'
Bundle 'plasticboy/vim-markdown'
filetype plugin indent on " required
syntax on " Enable syntax highlighting
set wildmenu " Better command-line completion
set showcmd " Show partial commands in the last line of the screen
set hlsearch
set autoindent
set shiftwidth=2
set softtabstop=2
set expandtab " Allow backspacing over autoindent, line breaks and start of insert action
set ignorecase " for case insensitive search
set smartcase " except when using capital letters
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
set splitright " when vertically split, open new window on the right(default, left)
set splitbelow " when horizontally split, open new window on the bottom(default, top)
" Keyboard Mapping
nnoremap <Leader>b :MRU<CR> " \b to see the most recent used files
" = to run tidy on html
au FileType html setlocal equalprg=tidy\ -q\ -i\ --show-errors\ 0\ --tab-size\ 4\ --wrap\ 200\ --indent-spaces\ 4
" for markdown plugin
let g:vim_markdown_folding_disabled=1
let g:vim_markdown_no_default_key_mappings=1
EDIT ----
I love this SO community.
I followed all comments and answers, and found out the following soultion;
changed <i/> to <i></i>
syntax off
syntax on
It might be because of the <i/> tag... your syntax highlighting might not recognize that you self-closed it.
Otherwise you might have the 'list' option set (it's not in your vimrc, but a plugin might have added it)... If some of your code is indented with tabs and other parts spaces, then if 'list' is set then it will highlight just the tabs, for example.
Try doing :set nolist and see if the highlighted areas go away. You can remove stray tabs or spaces (depending on your expandtab setting) by doing :retab.
The visual result of :set list depends on your colorscheme and your setting for listchars. For example, I have set listchars=tab:▸\ ,eol:¬ in my .vimrc at home. See :help 'listchars' for more information.
If you want to still have some visual distinction between leading tabs and spaces, you can modify your colorscheme. This is a bit more involved. From the Vim help:
The "NonText" highlighting will be used for "eol", "extends" and
"precedes". "SpecialKey" for "nbsp", "tab" and "trail".
To change the visual appearance of these syntax groups, add your own :highlight commands in your .vimrc or edit a colorscheme file.
Related
Preliminary Info:
Issue is in terminal Vim, not gVim
I used CMDER (based on conemu) as my terminal emulator
I am on Windows 10
Detailed Description:
When I'm in Insert mode, I can type text as normal, but backspace does nothing. While in normal mode, the backspace key deletes text. This is exactly opposite the behavior I had just earlier today. I have read numerous other posts online describing Vim's unorthodox backspace behavior, but the suggested config settings (namely bs=2 or bs=indent,eol,start) had done nothing.
More unusual is that gVim behaves "normally" that is: Backspace move the cursor to the left in normal mode, and deletes text in insert mode.
What I would like is for backspace to delete text in insert mode (just like most other programs) and to be navigation/disabled in normal mode. How can I regain this behavior?
Below is a copy of my _vimrc: (I would put this on github but my git is messed up at the moment and I've yet to fix it.) Additionally there was a function that was inside of the _vimrc by default. I have no idea what it does but omitted it to save space. If you want to see if I can post it in a reply.
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
" Pathogen - Plugin manager
execute pathogen#infect()
set nocompatible " Turns off Vi compatability gubbinz
" Color Theme
if !has("gui_running") " Allows some 256 color themes to work in Terminal
set term=xterm
set t_Co=256
let &t_AB="\e[48;5;%dm"
let &t_AF="\e[38;5;%dm"
colorscheme gruvbox
endif
let g:gruvbox_dark_contrast = 'hard' " Both of these are just visual gruvbox tweaks
let g:gruvbox_light_contrast = 'hard'
set guifont=Consolas:h10:cANSI:qDRAFT " Changes font
set bs=indent,eol,start " Makes backspace be normal
set filetype=ON " Has vim check for filetype
set showcmd " Displays incomplete commands
set ruler " Shows position of cursor in document
set syntax=ON " Turns on syntax highlighting
set number " Show line numbers
set linebreak " Break lines at word (requires Wrap lines)
set showbreak=+++ " Wrap-broken line prefix
set textwidth=100 " Line wrap (number of cols)
set showmatch " Highlight matching brace
set hlsearch " Highlight all search results
set smartcase " Enable smart-case search
set incsearch " Searches for strings incrementally
set autoindent " Auto-indent new lines
set shiftwidth=4 " Number of auto-indent spaces
set smartindent " Enable smart-indent
set smarttab " Enable smart-tabs
set softtabstop=4 " Number of spaces per Tab
set undolevels=1000 " Number of undo levels
set backspace=indent,eol,start " Backspace behaviour
set go=egrLTm " Changes flags that specify how the GUI loads
Most likely, your insert-mode backspace is mapped to do nothing (i.e. <nop>). Verify this by typing :verbose imap <bs>. This will show if backspace key is mapped and where the map was set.
What I would like is for backspace to delete text in insert mode (just like most other programs) and to be navigation/disabled in normal mode. How can I regain this behavior?
You can do:
iunmap <bs>
nnoremap <bs> <nop>
The first line unmaps <bs> in insert mode, thus <bs> will recover its default functionality. The second line maps <bs> in normal mode to do nothing.
No idea how I've just broken my vimrc, but I have. I have solarized installed, but syntax highlighting is no longer working automatically - I have to retype "syntax enable" every time I open the editor.
My vimrc is below - any help much appreciated!
" ----- BASICS -----
set nocompatible "compatible with vi
if !exists("g:syntax_on")
syntax enable
endif
filetype on "QS not sure about this one !
set number "add line numbers
set showcmd "show command in bottom bar
set cursorline "highlight cursor line
set wildmenu "commandline tab completion
set mouse=a "make vim useable with mouse
set backspace=indent,eol,start " make backspace work like in most editors.
set showmatch " highlight matching [{()}]
" ----- COLORSCHEME -----
let g:solarized_termcolors = 256
set background=light
colorscheme solarized
" ------ NAVIGATION -----
" long line navigation in normal mode
nnoremap j gj
nnoremap k gk
" ------ TABS & SPACES -----
set tabstop=4 "number of visual spaces per TAB
set shiftwidth=4 "size of indent with tab
set softtabstop=0
set noexpandtab "if you are using tab character inside your source
"code - these are defensive settings to avoid conversion
" ---------Searching ----------
set incsearch " search as characters are entered
set hlsearch " highlight matches
" ----------Folding -----------
set foldenable " enable folding
set foldlevelstart=10 " open most folds by default
set foldnestmax=10 " 10 nested fold max
nnoremap <space> za
"space open/closes folds
set foldmethod=indent " fold based on indent level
set smartindent " indents your code automatically
filetype off " required
The last line in your ~/.vimrc disables filetype detection. Without that, Vim treats every opened file as plain text, and therefore does not load any syntax plugin. Drop that line, it doesn't make sense.
filetype off " required
In order to benefit from the built-in filetype and indent plugins, rather turn on everything:
filetype plugin indent on
See :help :filetype for further details.
For some reason it seems the default for vim with Go files is to highlight trailing whitespace in red. In a way this is nice, but mostly I find it annoying because every time I type a space it starts as a red highlight. Is there a way to stop this behavior? I've only experienced this with Go files. Below is my vimrc, but I don't think I put anything there that would affect it.
set nocompatible
syntax on
set autoindent
set tabstop=4 softtabstop=0
autocmd FileType go set tabstop=8 softtabstop=0
set formatoptions=tcroql
set relativenumber
set incsearch
set hlsearch
set smartindent
filetype indent on
From go.vim Vim syntax file:
" There are some options for customizing the highlighting; the recommended
" settings are the default values, but you can write:
" let OPTION_NAME = 0
" in your ~/.vimrc file to disable particular options.
Put in your .vimrc
let g:go_highlight_trailing_whitespace_error=0
There are these other options:
" - g:go_highlight_array_whitespace_error
" Highlights white space after "[]".
" - g:go_highlight_chan_whitespace_error
" Highlights white space around the communications operator that don't
" follow the standard style.
" - g:go_highlight_extra_types
" Highlights commonly used library types (io.Reader, etc.).
" - g:go_highlight_space_tab_error
" Highlights instances of tabs following spaces.
If you still like the highlighting of trailing whitespaces but not during the typing, you can try
au InsertEnter *.go match goSpaceError /\s\+\%#\#<!$/
au InsertLeave *.go match goSpaceError /\s\+$/
Read more in Highlight unwanted spaces from wikia.
In VIM I've, all my tabs are 2 spaces. But when I push to github, they get converted to 4 spaces. Can anyone help me figure out how to prevent them from getting converted to 4 spaces?
My vimrc file:
call pathogen#infect()
call pathogen#runtime_append_all_bundles()
" search
set hlsearch " highlight the search
set incsearch " incremental search
set ignorecase " search ignoring case
set showmatch " show matching bracket
" colors
set background=dark
let g:solarized_termcolors=8 " proper solarized coloring
colorscheme peachpuff
" syntax
syntax on
filetype on " Enable filetype detection
filetype plugin on " Enable filetype-specific plugins
filetype indent on " Enable filetype-specific indenting
set ruler " show the line number on the bar
set more " use more prompt
set autoread " watch for file changes
set number " line numbers
set hidden
set noautowrite " don't write old file out when switching files
set lazyredraw " don't redraw when don't have to
set showmode
set showcmd
set nocompatible " vim, not vi
set autoindent smartindent " auto/smart indent
set smarttab " tab and backspace are smart
set tabstop=2 " 6 spaces
set shiftwidth=2
set scrolloff=5 " keep at least 5 lines above/below
set sidescrolloff=5 " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set linebreak
set cmdheight=2 " command line two lines high
set undolevels=1000 " 1000 undos
set updatecount=100 " switch every 100 chars
set complete=.,w,b,u,U,t,i,d " do lots of scanning on tab completion
set ttyfast " we have a fast terminal
set noerrorbells " No error bells please
set shell=bash
set fileformats=unix
set ff=unix
set wildmode=longest:full
set wildmenu " menu has tab completion
set laststatus=2
set diffopt=filler,iwhite " ignore all whitespace and sync
" scss formatting
autocmd BufRead,BufNewFile *.scss ""set ft=scss.css
" jade formatting
autocmd BufRead,BufNewFile *.jade setlocal ft=jade noexpandtab
autocmd FileType jade :setlocal sw=2 ts=2 sts=2
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
autocmd Filetype javascript setlocal ts=2 sw=2 sts=0 noexpandtab
The standard representation of a tab character is 8 spaces. In reality, the tab is a control character and as such doesn't have an associated glyphs or a set width. This allows most programs to offer a way to modify how it is displayed but no program ever change its width because it doesn't have one to start with: a tab is still a tab, no matter the value of tabstop.
Your Vim settings only alter how tabs are displayed in Vim: they have no bearings on how they are displayed outside of Vim.
You have two solutions:
set GitHub and Vim to use the same tab width
use spaces
Since we are at it…
set background=dark
let g:solarized_termcolors=8 " proper solarized coloring
colorscheme peachpuff
You can delete the solarized line if you don't use it and set background is useless because your colorscheme takes care of that.
set noautowrite
is also useless because autowrite is off by default.
And
call pathogen#runtime_append_all_bundles()
serves no purpose whatsoever.
I would recommend reading this on how to change tabsize for Github
There appears to be a browser extension called Stylish that changes tabs in Github by downloading the style "Better sized tabs in code"
Download the browser extension and use the style and change the tab spacing to two space tabs.
Hope this helped!
How do the sections of code in the _vimrc file interact with each other?
My current file looks like the following but I'm wondering if it matters if a line such as filetype plugin indent on is at the start or the end of this file?
Does it matter if a line like filetype plugin indent on is repeated twice in the file?
Should the Pathogen settings be near the start?
"------------------------------------------------------------
" Must have options {{{1
"this will make the window maximized on startup
au GUIEnter * simalt ~x
" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on
set omnifunc=syntaxcomplete#Complete
" Enable syntax highlighting
syntax on
"set highlight search always on
:set hlsearch
"------------------------------------------------------------
" Usability options {{{1
" Show partial commands in the last line of the screen
set showcmd
" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase
" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start
" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent
" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline
" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler
" Always display the status line, even if only one window is displayed
set laststatus=2
" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm
" Use visual bell instead of beeping when doing something wrong
set visualbell
" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=
" Enable use of the mouse for all modes
set mouse=a
" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2
" Display line numbers on the left
set number
" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200
" Use <F11> to toggle between 'paste' and 'nopaste'
set pastetoggle=<F11>
"------------------------------------------------------------
" Indentation options {{{1
"
" Indentation settings according to personal preference.
" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
"set shiftwidth=2
"set softtabstop=2
"set expandtab
" Indentation settings for using hard tabs for indent. Display tabs as
" two characters wide.
set shiftwidth=2
set tabstop=2
"------------------------------------------------------------
" Look and Feel {{{1
"
" Use CTRL-S for saving, also in Insert mode
:nnoremap <C-S> :<C-U>update<CR>
:vnoremap <C-S> :<C-U>update<CR>gv
:cnoremap <C-S> <C-C>:update<CR>
:inoremap <C-S> <C-O>:update<CR>
"color scheme setting
" Set nice colors
" background for normal text is light grey
" Text below the last line is darker grey
" Cursor is green, Cyan when ":lmap" mappings are active
" Constants are not underlined but have a slightly lighter background
set guifont=Consolas:h16:cANSI
colorscheme pyte
"highlight Normal guibg=grey90
"highlight Cursor guibg=Green guifg=NONE
"highlight lCursor guibg=Cyan guifg=NONE
"highlight NonText guibg=grey80
"highlight Constant gui=NONE guibg=grey95
"highlight Special gui=NONE guibg=grey95
"a quick way to locate python files
nnoremap <Leader>p :pyf P:\Computer Applications\Python\
"quick quit command
noremap <Leader>e :quit<CR> "quits the current window
"------------------------------------------------------------
" NERTtree settings {{{1
"
"get NERDTree command quick
nnoremap <Leader>nd :NERDTree M:\
map <F2> :NERDTreeToggle<CR>
let NERDTreeQuitOnOpen = 1
" Rebind <Leader> key...not sure about this one
"let mapleader = ","
map <Leader>n <esc>:tabprevious<CR>
map <Leader>m <esc>:tabnext<CR>
"------------------------------------------------------------
" dbext settings {{{1
"
"let g:sql_type_default = 'SQLSVR'
" Since I repeatedly need to edit stored procedures, the CREATE PROCEDURE
" statement is preceeded by an IF ... END IF block which will drop
" the procedure or it uses the CREATE OR REPLACE syntax.
" This function will visually select the IF block to the END; statement
" of the stored procedure and execute it. Or check for the
" CREATE OR REPLACE and stop there and look to the end.
function! SQLExecuteIfCreateReplace()
let l:old_sel = &sel
let &sel = 'inclusive'
let saveWrapScan=&wrapscan
let saveSearch=#/
let l:reg_z = #z
let &wrapscan=0
let #z = ''
let found = 0
let startLine = 0
let endLine = 0
let curLine = line(".")
let curCol = virtcol(".")
" Must default the command terminator
let l:dbext_cmd_terminator = ";"
try
" Search backwards and do NOT wrap
" Find the line beginning with an IF clause
" IF EXISTS( SELECT 1 ...
" or find an or replace clause
" CREATE OR REPLACE PROCEDURE ...
" And execute it until we find an
" END
" at the beginning of a line.
let startLine = search('\c\(^\<if\>\|^\<alter\s\+procedure\>\|\<or\s\+replace\>\)', 'bcnW' )
if startLine > 0
" Search forward and visually select all lines
" until we find an END; clause
let endLine = search('^END'.l:dbext_cmd_terminator.'\s*$', 'cnW')
exec startLine.','.endLine.'DBExecRangeSQL'
endif
finally
call cursor(curLine, curCol)
noh
let l:query = #z
let #z = l:reg_z
let #/=saveSearch
let &wrapscan=saveWrapScan
let &sel = l:old_sel
endtry
endfunction
"------------------------------------------------------------
" pathogen settings {{{1
"pathogen customization
"set nocp
" Use pathogen to easily modify the runtime path to include all plugins under
" the ~/.vim/bundle directory
filetype off " force reloading *after* pathogen loaded
call pathogen#infect()
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
syntax on
filetype plugin indent on " enable detection, plugins and indenting in one step
The order does matter.
e.g. you have two lines:
Options:
set nu
set nonu
the latter will overwrite the previous setting.
for functions, if you declared a function at the end of your file, but called it at the 1st line. When you load your vimrc the first time, you will get the error Unknown function: function name
Also if you manually set some hi group before the color scheme (if you used one) loading, the color scheme is gonna overwrite your settings too.
If you call some command/function defined in a plugin before it was loaded, you will have error message too.
so , it is ok if you have some command/setting in vimrc multiple times, but the last one will take effect.
tl;dr: Some do, some don't; use a logical structure from simple to complex.
Pathogen wants its settings to appear at the top, because it modifies the way other scripts are loaded (explicitly via :runtime, or as a side effect of calling autoload functions).
The order of :set usually doesn't matter (unless you have conflicting settings), and any mappings or autocmds you define are only activated after the startup, so you can put them anywhere.
In general, I'd recommend a logical structure, starting with basic stuff like Pathogen, settings, plugin configuration, followed by custom mappings and more involved adaptations like autocmds.
Also, I'd avoid putting filetype-specific stuff into ~/.vimrc; rather, put those into the corresponding ~/.vim/after/ftplugin/<filetype>.vim script and use filetype plugin on.