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.
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.
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.
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!
The following is my .vimrc file in it's entirety:
For some reason, the set wrap and set textwidth=73 (at bottom of file) are not working (I want to have files wrap at 73 columns). I can still go into a file and type past 73 columns.
Is there a conflicting command here that needs to be fixed? Or am I doing something wrong?
set nocompatible
set smartindent
set cursorline
filetype plugin indent on
set background=dark
syntax enable
set grepprg=grep\ -nH\ $*
syntax on
set mouse=a
set history=1000
set showmode
if has('cmdline_info')
set ruler " show the ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " a ruler on steroids
set showcmd " show partial commands in status line and
endif
set backspace=indent,eol,start " backspace for dummys
set linespace=0 " No extra spaces between rows
set nu " Line numbers on
set showmatch " show matching brackets/parenthesis
set incsearch " find as you type search
set hlsearch " highlight search terms
set winminheight=0 " windows can be 0 line high
set ignorecase " case insensitive search
set smartcase " case sensitive when uc present
set wildmenu " show list instead of just completing
set wildmode=list:longest,full
set scrolljump=5 " lines to scroll when cursor leaves screen
set scrolloff=3 " minimum lines to keep above and below cursor
set gdefault " the /g flag on :s substitutions by default
set autoindent " indent at the same level of the previous line
set shiftwidth=4 " use indents of 4 spaces
set expandtab " tabs are spaces, not tabs
set tabstop=4 " an indentation every four columns
set softtabstop=4 " let backspace delete indent
set matchpairs+=<:>
set comments=sl:/*,mb:*,elx:*/
autocmd FileType c,cpp,java,php,js,python,twig,xml,yml autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
set foldmethod=syntax "fold based on indent
set foldnestmax=10 "deepest fold is 10 levels
set foldlevel=0 "this is just what i use
set wrap
set textwidth=73
set formatoptions+=t
EDIT: I want VIM to auto wrap at 73 lines (real time). Is that possible? I have tried adding set formatoptions+=t to wrap text but it still isn't effective.
Options wrap and textwidth regard two completely different kinds of wrapping.
The textwidth sets a line width limit, after which every new word (that means separated with spaces) will be placed in a new line.
Attached .vimrc probably works correctly, and the textwitdh does precisely this.
wrap doesn't affect the edited file contents at all, just causing the line in file be displayed in several lines if it is longer than display width. If found no pleasing way to configure this to wrap at the fixed column width and I, personally, don't see such a need.
However there are two aspects of soft-wrapping that can be changed if you find soft wrapping at the end of the screen annoying.
Change the width of the Vim window, using set columns=73 (it is quite disturbing, because it changes the width of whole window)
Soft-wrap lines not on the boundary of screen, but on the last word boundary, by setting linebreak option, see help linebreak for details.
Perhaps not the best solution, but try to assign textwidth and formatoptions inside an autocommand, and then format all lines of your file.
autocmd BufRead * set fo+=t tw=73|normal gggqG
This worked in my test. You can be more specific and substitute * with *.txt or similar.
Put this into .vimrc, that worked for me:
autocmd FileType * set textwidth=58