Vim: inoremap works in buffer, not in .vimrc - vim

I'm really eager to include the following in my .vimrc file:
inoremap <Tab> <C-x><C-u>
If I set it within a buffer (via :inoremap <Tab> <C-x><C-u>) it works exactly as I'd hoped.
But, if I place it in my .vimrc, it doesn't seem to be acknowledged at all.
I've attached my .vimrc below. A few things:
Other changes to the .vimrc file are picked up, so it's not the wrong file
Have tried adding at the very bottom of the .vimrc & still doesn't work, so it's not being overwritten
Any ideas appreciated. Many thanks.
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Word complete
" :autocmd BufEnter * call DoWordComplete()
" let g:WC_min_len = 4
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
map j gj
map k gk
set showmatch " Show matching brackets
set mat=5 " Bracket blinking
set noerrorbells " No noise
" Ruby autocomplete
" Autocomplete behaviour
set completeopt=longest,menuone
open omni completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <C-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
\ '<C-x><C-o><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'
" open user completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <S-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
\ '<C-x><C-u><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
" highlight Pmenu ctermbg=238 gui=bold "improve autocomplete menu color
" Colours
highlight Pmenu ctermfg=6 ctermbg=238 guibg=grey30
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" if has("vms")
" set nobackup " do not keep a backup file, use versions instead
" else
" set backup " keep a backup file
" endif
" Set backupdir to tmp
" Do not let vim create <filename>~ backup files
set nobackup
" set nowritebackup
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Set tab to 2 spaces
set ts=2
set shiftwidth=2
" Ignore case
set ignorecase
set smartcase
" Menu autocomplete
set wildmode=longest,list
set wildmenu
" Call pathogen
call pathogen#infect()
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Turn syntax highlighting on (Added by John Bayne, 18/08/2012)
syntax on
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" My customisations
" No backup files
set nobackup
set nowritebackup
set noswapfile
" Whitespace identifier
:highlight ExtraWhitespace ctermbg=darkgreen guibg=lightgreen
:match ExtraWhitespace /\s\+$/
" Colour options
" color codeschool
" set guifont=Monaco:h12
" let g:NERDTreeWinPos = "right"
" set guioptions-=T " Removes top toolbar
" set guioptions-=r " Removes right hand scroll bar
" set go-=L " Removes left hand scroll bar
" autocmd User Rails let b:surround_{char2nr('-')} = "<% \r %>" " displays <% %> correctly
" :set cpoptions+=$ " puts a $ marker for the end of words/lines in cw/c$ commands
" Tab behaviour for ultisnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
inoremap <Tab> <C-x><C-u>

In this case, :scriptnames, while useful, is not the best way to see where a mapping was last set.
:verbose map <tab>
is a lot more precise.

Maybe another script is overwriting it after your .vimrc is read.
You can use :scriptnames to see what files are read on startup.

Related

Vim substitutes only first occurence in line (global tag not working) [duplicate]

I've been making a lot of changes to my .vimrc lately, and somewhere along the line I've introduced an undesirable feature. When performing a substitution command where the search token appears more than once per line, only the first token is changed (although the remaining tokens are highlighted as a result of the substitution). I have seen a few posts here about how to enable this behavior on a case-by-case basis, but I have yet to see something about what would cause this to be the default behavior or how to disable it. If anyone has any ideas, they would be appreciated.
For reference, my .vimrc (https://github.com/chpatton013/dotfiles/blob/master/vim/.vimrc):
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Reread configuration of Vim if .vimrc is saved
augroup VimConfig
au!
au BufWritePost ~/.vimrc so ~/.vimrc
au BufWritePost _vimrc so ~/_vimrc
au BufWritePost vimrc so ~/.vimrc
augroup END
" Set colorcolumn to 80 chars, or (if not supported) highlight lines > 80 chars
augroup ColorColumnConfig
au!
if exists('+colorcolumn')
au BufWinEnter * set colorcolumn=80
au BufWinEnter * hi ColorColumn ctermbg=lightgrey guibg=lightgrey
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
augroup END
" Highlight over-length characters and trailing whitespace
augroup ExtraCharacters
au!
au ColorScheme * highlight ExtraWhitespace ctermbg=Red guibg=Red
au ColorScheme * highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
au BufWinEnter * let w:whitespace_match_number =
\ matchadd('ExtraWhitespace', '\s\+$')
au BufWinEnter * call matchadd('OverLength',
\ '\(^\(\s\)\{-}\(*\|//\|/\*\)\{1}\(.\)*\(\%81v\)\)\#<=\(.\)\{1,}$')
au InsertEnter * call s:ToggleWhitespaceMatch('i')
au InsertLeave * call s:ToggleWhitespaceMatch('n')
augroup END
" Resize splits on window resize
au VimResized * exe "normal! \<c-w>="
" Restore the cursor when we can.
au BufWinEnter * call RestoreCursor()
" Change the statusline color based on current mode
augroup StatuslineColor
au!
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline ctermfg=cyan ctermbg=black guifg=cyan guibg=black
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pathogen - https://github.com/tpope/vim-pathogen
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
" Easymotion - https://github.com/Lokaltog/vim-easymotion/
" This is so much more convenient
let g:EasyMotion_leader_key=',m'
" Neocomplcache - https://github.com/Shougo/neocomplcache
" Enable at startup.
let g:neocomplcache_enable_at_startup=1
" Only display 'n' items in the list.
let g:neocomplcache_max_list=5
" Do not auto-select the first candidate.
let g:neocomplcache_enable_auto_select=1
" Do not try to match until 'n' characters have been typed
let g:neocomplcache_auto_completion_start_length=3
" Do not try to match to anything less than 'n' characters
let g:neocomplcache_min_keyword_length=6
let g:neocomplcache_min_syntax_length=6
" Only consider case if an uppercase character has been typed
let g:neocomplcache_enable_smart_case=1
" Syntastic - https://github.com/scrooloose/syntastic/
" Commands:
" :Errors // pop up location list and display errors
" :SyntasticToggleMode // toggles between active and passive mode
" :SyntasticCheck // forces a syntax check in passive mode
" check for syntax errors on file open
let g:syntastic_check_on_open=1
" echo errors to the command window
let g:syntastic_echo_current_error=1
" mark lines with errors and warnings
let g:syntastic_enable_signs=1
" set sign symbols
let g:syntastic_error_symbol='E>'
let g:syntastic_warning_symbol='W>'
let g:syntastic_style_error_symbol='S>'
let g:syntastic_style_warning_symbol='s>'
" open error balloons when moused over erroneous lines
let g:syntastic_enable_balloons=1
" customize Syntastic statusline
let g:syntastic_stl_format = '[%E{E: %fe #%e}%B{, }%W{W: %fw #%w}]'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
let _s=#/
let l = line(".")
let c = col(".")
%s/\s\+$//e
let #/=_s
call cursor(l, c)
endfunction
" Toggle match of trailing whitespace
function! s:ToggleWhitespaceMatch(mode)
let pattern = (a:mode == 'i') ? '\s\+\%#\#<!$' : '\s\+$'
if exists('w:whitespace_match_number')
call matchdelete(w:whitespace_match_number)
call matchadd('ExtraWhitespace', pattern, 10, w:whitespace_match_number)
else
" Something went wrong, try to be graceful.
let w:whitespace_match_number = matchadd('ExtraWhitespace', pattern)
endif
endfunction
" Restore the cursor when we can
function! RestoreCursor()
if line("'\"") <= line("$")
normal! g`"
normal! zz
endif
endfunction
" Change the statusline color based on current mode
function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi statusline ctermfg=darkmagenta ctermbg=black guifg=darkmagenta guibg=black
elseif a:mode == 'r'
hi statusline ctermfg=darkgreen ctermbg=black guifg=darkgreen guibg=black
else
hi statusline ctermfg=darkred ctermbg=black guifg=darkred guibg=black
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Configuration customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" gui configuration (do not move from top of configurations)
set guioptions=am
set guifont=Consolas:h9
set encoding=utf-8
set fileencoding=utf-8
set nocompatible " No compatibility with vi.
filetype on " Recognize syntax by file extension.
filetype indent on " Check for indent file.
filetype plugin on " Allow plugins to be loaded by file type.
behave xterm " Maintain keybindings across enviornments
set autowrite " Write before executing the 'make' command.
set background=dark " Background light, so foreground not bold.
set backspace=indent,eol,start " Allow <BS> to go over indents, eol, and start of insert
set expandtab " Expand tabs with spaces.
set nofoldenable " Disable folds; toggle with zi.
set gdefault " Assume :s uses /g.
set hidden " Use hidden buffers so unsaved buffers can go to the background
set history=500 " Set number of lines for vim to remember
set hlsearch " Highlight all search matches
set ignorecase " Ignore case in regular expressions
set incsearch " Immediately highlight search matches.
set laststatus=2 " Show status line even where there is only one window
set lazyredraw " Redraw faster
set linespace=-1 " Bring lines closer together vertically
set modeline " Check for a modeline.
set noerrorbells " No beeps on errors.
set nohls " Don't highlight all regex matches.
set nowrap " Don't soft wrap.
set number " Display line numbers.
set path=~/Code/** " Set default path
set scrolloff=5 " Keep min of 'n' lines above/below cursor.
set shellslash " Use forward slashes regardless of OS
set shiftwidth=3 " >> and << shift 3 spaces.
set showcmd " Show partial commands in the status line.
set showmatch " Show matching () {} etc..
set showmode " Show current mode.
set sidescrolloff=10 " Keep min of 'n' columns right/left cursor.
set smartcase " Searches are case-sensitive if caps used.
set smarttab " Tabs and backspaces at the start of a line indent the line one level
set smartindent " Maintains most indentation and adds extra level when nesting
set softtabstop=3 " See spaces as tabs.
set splitright splitbelow " Open splits below and to the right
set synmaxcol=160 " Only matches syntax on first 'n' columns of each line ( faster)
set tabstop=3 " <Tab> move three characters
set textwidth=79 " Hard wrap at 79 characters
set title " Set the console title
set viminfo='20,\"500,% " Adjust viminfo contents
set virtualedit=block " Allow the cursor to go where it should not
set wildmenu " Tab completion opens a Tab- and arrow-navigable menu
set wildmode=longest,full " Tab completion works like bash.
set wrapscan " Searching wraps to start of file when end is reached
" Define statusline
set statusline=%f " Relative file path
set statusline+=%(\ [%M%R%H%W]%) " File flags (mod, RO, help, preview)
set statusline+=%(\ %<%) " Start truncation
set statusline+=%(\ %{fugitive#statusline()}%) " Git branch name (if applicable)
set statusline+=%= " Begin right justification
set statusline+=%#warningmsg# " Start warning highlighting
set statusline+=%(\ %{SyntasticStatuslineFlag()}%) " Show Syntastic errors and warnings
set statusline+=%* " End warning highlighting
set statusline+=\ [line\ %l\/%L,\ col\ %c%V,\ %p%%] " Line and column numbers and percentage through file
" Text formatting settings
" t: Auto-wrap text using textwidth. (default)
" c: Auto-wrap comments; insert comment leader. (default)
" q: Allow formatting of comments with "gq". (default)
" r: Insert comment leader after hitting <Enter>.
" o: Insert comment leader after hitting 'o' or 'O' in command mode.
" n: Auto-format lists, wrapping to text *after* the list bullet char.
" l: Don't auto-wrap if a line is already longer than textwidth.
set formatoptions+=ronl
" Enable mouse scrolling in selected modes
" a: All
" c: Command
" i: Insert
" n: Normal
" v: Visual
set mouse=a
" Set scrolling to be single-line
"map <MouseDown> <C-Y>
"map <S-MouseDown> <C-U>
"map <MouseUp> <C-E>
"map <S-MouseUp> <C-D>
" Highlighting
syntax enable
set t_Co=16
colorscheme solarized
" Configuration variables
let loaded_matchparen=0 " do automatic bracket highlighting.
let mapleader="," " Use , instead of \ for the map leader.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command mode customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Make y behave like all other capitals
map Y y$
" Make Q reformat text.
noremap Q gq
" Toggle paste mode.
noremap <Leader>p :set paste!<CR>
" Open the file under the cursor in a new tab.
noremap <Leader>ot <C-W>gf
" Toggle highlighting of the last search.
noremap <Leader>h :set hlsearch! hlsearch?<CR>
" Open a scratch buffer.
noremap <Leader>s :Scratch<CR>
" Improve movement on wrapped lines
nnoremap j gj
nnoremap k gk
" Keep search pattern at the center of the screen
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
nnoremap <silent> g# g#zz
" Use C-hjkl in to change windows
nnoremap <C-h> <C-w><Left>
nnoremap <C-j> <C-w><Down>
nnoremap <C-k> <C-w><Up>
nnoremap <C-l> <C-w><Right>
" Strip trailing whitespace
nnoremap <silent> <leader>W :call <SID>StripTrailingWhitespaces()<CR>
" Allow easy toggling of spaces / tabs mode
nnoremap <C-t><C-t> :set invexpandtab<CR>
" Create simple toggles for line numbers, paste mode, and word wrap.
nnoremap <C-N><C-N> :set invnumber<CR>
nnoremap <C-p><C-p> :set invpaste<CR>
nnoremap <C-w><C-w> :set invwrap<CR>
" Folding stuff
nnoremap <C-o> zo
nnoremap <C-c> zc
nnoremap <C-O> zO
nnoremap <C-O><C-O> zR
set foldmethod=indent
" Open file for class name under cursor
nnoremap <C-i> yiw:find <C-R>".php<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Insert mode customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set up dictionary completion.
set dictionary+=~/.vim/dictionary/english-freq
set complete+=k
" Smash Esc
inoremap jk <Esc>
inoremap kj <Esc>
" Use hjkl in insert mode
imap <C-h> <Left>
imap <C-j> <Down>
imap <C-k> <Up>
imap <C-l> <Right>
" Make C-s write the buffer and return to insert mode when applicable
inoremap <C-s> <C-O>:w<CR>
nnoremap <C-s> :w<CR>
" auto-insert second braces and parynthesis
inoremap {<CR> {<CR>}<Esc>O
inoremap ({<CR> ({<CR>});<Esc>O
inoremap <<<<CR> <<<EOT<CR>EOT;<Esc>O<C-TAB><C-TAB><C-TAB>
set cpoptions+=$ "show dollar sign at end of text to be changed
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual mode customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" reselect visual block after indent/outdent
xnoremap < <gv
xnoremap > >gvo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
And the following plugins make up the contents of my bundle directory (https://github.com/chpatton013/dotfiles/tree/master/vim/.vim/bundle):
neocomplcache/
syntastic/
vim-abolish/
vim-colors-solarized/
vim-commentary/
vim-easymotion/
vim-fugitive/
vim-pathogen/
vim-repeat/
vim-surround/
Finally, I have disabled all plugins, but the issue was not resolved. I removed my .vimrc and the issue was resolved (so it is not some global setting outside of my control). I disabled several individual settings in my .vimrc, but I could not seem to eliminate the problem. Eventually, I got tired of playing whack-a-mole and decided to turn to the community. Any ideas?
EDIT: As an example,
I use the command :%s/foo/foobar/g
The text foo bar foo is converted to foobar bar foo
EDIT: Resolved by pb2q. set gdefault inverts the behavior of /g.
The substitute command accepts the switch g, for global, which causes the substitution to be made on all matches on the line:
:s/regex/replacement/g
The default is that only the first occurrence of the match is substituted, but there's a setting to switch the default to global: gdefault. So set gdefault in your vimrc if you want this as the default behavior. Try it out first in the current vim session with :set gdefault.
Note that when you set gdefault, this not only makes g the default behavior, but it changes the usage of the g flag so that using /g at the end of a substitute will cause the substitution to be made only once.
See: :help gdefault.

Vim freezes after pressing CTRL-U in insert mode. Any suggestions?

Recently I figured out that pressing CTRL-U locks/freezes vim in insert mode. The only CTRL-C helps to get it back. Terminal version and gvim have the same behaviour. Only in virtual console mode (CTRL-ALT-F1) the C-U works properly. Here is my .vimrc:
" This must be first, because it changes other options as a side effect.
set nocompatible
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
imap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" Options
" =========================================================
colorscheme gruvbox
let g:gruvbox_contrast_dark = 'normal'
set background=dark
set t_Co=256
" spelling
set spell spelllang=ru_yo,en_us
set spellsuggest=10
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
" backup
set writebackup " backup on write
set nobackup " keep a backup file
set undofile " keep an undo file
set swapfile " keep a swap file
" directories
" set autochdir
set backupdir=~/.vim/tmp/backup//
set undodir=~/.vim/tmp/undo//
set directory=~/.vim/tmp/swp//
" active editor
set nowrap
set nu
set backspace=indent,eol,start " backspacing over everything in im
set ruler " show the cursor position all the time
" cmd
set history=50 " keep 50 lines of command line history
set showcmd " display incomplete commands
" search
set ignorecase " ignore case using a search pattern.
set smartcase " override 'ignorecase' when pattern has upper case.
set incsearch " do incremental searching
" tab
" set tabstop=2 shiftwidth=2 noexpandtab " n-column tab
set tabstop=2 shiftwidth=2 expandtab " n-space character tab
" window
set splitbelow
set splitright
set winminheight=0
" folding settings
set foldmethod=indent " fold based on indent
set foldnestmax=10 " deepest fold is 10 levels
set nofoldenable " dont fold by default
set foldlevel=1 " this is just what i use
" invisible chars
set list " don't show invisible characters.
set listchars=tab:.\ ,trail:~,extends:>,precedes:<,eol:\ "¬
set nohidden " unload buffer when no longer shown in window.
set laststatus=2 " Display vim-lightline
" indent, cursor, width
set cursorline " Highlight the screen line of the cursor.
set colorcolumn=72 " Columan to highlight.
set autoindent " Automatically set the indent of a new line.
set textwidth=80
set completeopt=menuone,longest ",preview prevents immediate complete
" tab
set switchbuf=usetab " use window or tabs to find selected buff
" windows
set noea " fix window size after closing others
" sessions (^blank,help)
set sessionoptions=buffers,curdir,folds,help,options,tabpages,winsize
" Autocmd
" =========================================================
au BufReadPost *.tmpl set syntax=html
" Mappings
" =========================================================
" source and update file
nmap <F5> :so ~/.vimrc<CR>
nmap <leader>e :e<CR>
" copy filepath
nmap <silent> <F4> :let #+=expand("%:p")<CR>
" buffers
nmap <F2> :ls<CR>:b
nmap <c-w><c-t> :tabnew<CR>
nmap <c-w><c-e> :tab sp<CR>
nmap <c-w><c-b>n :tabnew %<Bar>:bNext<Bar><CR>
nmap <c-w><c-b><c-b> :bw %<CR>
nmap <c-w><c-b>w :bw! %<CR>
nmap <c-w><c-b>a :tab ball<CR>
" sessions
nmap <silent> <leader>ss :wa<Bar>exe "mksession! " . v:this_session<CR>
nmap <leader>sr :so .session.vim<CR>
nmap <leader>sc :msk .session.vim<CR>
" quit
nmap <leader>qd :qa!<CR> " quit & discard changes
nmap <leader>qq :xa<CR> " quit & write if changed
nmap <leader>qs <leader>s<leader>qd
" new vertical window
nmap <c-w><c-n> :vnew<CR>
" tab movement and switching
nmap <c-l> :tabnext<CR>
nmap <c-h> :tabprevious<CR>
nmap <c-j> :tabmove -1<CR>
nmap <c-k> :tabmove +1<CR>
" search and replace
nmap <leader>c :let #/=""<CR>
" trailing spaces
nmap <silent> <leader>dt mq:%s/\s\+$//e<Bar>:let #/=""<CR>`q:delm q<CR>
" update, write
nmap <leader>u <leader>dt:update<CR>
nmap <leader>w <leader>dt:write<CR>
cmap w!! w !sudo tee > /dev/null %
" window manipulation
nmap <c-w>== :set ead=ver ea noea<CR>
nmap <c-w>=- :set ead=hor ea noea<CR>
" shell
nmap <space> :sh<CR>
" Plugins
" =========================================================
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
Plug 'mattn/emmet-vim'
Plug 'itchyny/lightline.vim'
Plug 'sheerun/vim-polyglot'
Plug 'scrooloose/syntastic'
call plug#end()
" Lightline.vim
let g:lightline = {
\ 'colorscheme': 'jellybeans',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'filename', 'readonly', 'modified' ] ] },
\}
" Syntastic
" let g:syntastic_sass_checkers = ["sassc"]
" Netrw
nmap <leader>tr <Plug>NetrwRefresh
map <leader>tf :Ntree<CR>
map <silent> <leader>f <S-CR>
let g:netrw_liststyle=3
let g:netrw_banner=0
let g:netrw_mousemaps=0
let g:netrw_chgwin=1 " open files in left window by default
" let g:netrw_keepdir=0
" let g:netrw_silent= 1
" fire up the sidebar
nmap <silent> <C-#> :rightbelow 25vs<CR>:e .<CR>
" vim-go
" disable fmt on save
let g:go_fmt_autosave = 0
" format with goimports instead of gofmt
let g:go_fmt_command = "goimports"
" additional highlight
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
" YouCompleteMe
let g:ycm_confirm_extra_conf=0
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_min_num_of_chars_for_completion=1
" Emmet-vim
let g:user_emmet_leader_key='<c-m>'
" Formats the statusline
" set statusline=%f " file name
" set statusline+=[%{strlen(&fenc)?&fenc:'none'}, "file encoding
" set statusline+=%{&ff}] "file format
" set statusline+=%y "filetype
" set statusline+=%h "help file flag
" set statusline+=%m "modified flag
" set statusline+=%r "read only flag
"
" set statusline+=\ %= " align left
" set statusline+=Line:%l/%L[%p%%] " line X of Y [percent of file]
" set statusline+=\ Col:%c " current column
" set statusline+=\ Buf:%n " Buffer number
" set statusline+=\ [%b][0x%B]\ " ASCII and byte code under cursor
" Miscellaneous
" =========================================================
nmap <leader>t :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
:set guioptions-=m "remove menu bar
:set guioptions-=T "remove toolbar
:set guioptions-=r "remove right-hand scroll bar
:set guioptions-=L "remove left-hand scroll bar
It's quite big, but the only one mapping related with C-U: imap <C-U> <C-G>u<C-U>. What's going on?
I've copied your vimrc and used it. Same effect. It's this line:
imap <C-U> <C-G>u<C-U>
which apparently causes a recursion. When commented out, <C-u> erases back to start-of-line.
Given the problem that #Jens found... you, Timur, might want to try
inoremap <c-u> <c-g>u<c-u>
That will prevent remapping (ie. an infinite recursion) from taking place.

how to install VIM + Vuddle on msys2

Vim came as default on my msys2 version but I don't see the ~/.vimrc file nor ~/.vim/ directory
any thoughts
just place a file in /etc/vimrc
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram#vim.org>
" Last change: 2011 Apr 15
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif

non latin identifier based autocompletion

I am using vim with YouCompleteMe plugin, which is awesome except the fact it has no support of unicode completion as is written here and here.
I switched to vim from sublime text and i am completely excited with vim. But the fact i dont get autocompletion of words which contains (or wholly constructed) with non latin characters drives me crazy because i am writing a lot of documents in latex and use russian keyboard layout with vim's langmap option.
I dont know if there is any way to get autocompletion of my native locale (russian) words.
I played a little with encodings and tried cp1251 as fileencoding and encoding but get no result.
Could you tell me if it is possible ?
The default vim's complete (which is triggered by pressing <C-x> <C-n>) is working but it is very inconvenient to press such a long combination when you need to complete several hundreds words in a day.
I dont want any complicated completion as i understand that it is nearly impossible with the current implementation of vim. I want identifier based completion -- complete with words that were already typed in current document.
I googled but found nothing.
I would greatly appreciate any information related to my problem.
Here is my .vimrc:
set nocompatible " be iMproved, required
filetype off " required
if &diff
" no options at all for vimdiff
else
"=====================================================
" Vundle settings
"=====================================================
" set the runtime path to include Vundle and initialize
"
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim' " let Vundle manage Vundle, required
"---------=== Code/project navigation ===-------------
Plugin 'scrooloose/nerdtree' " Project and file navigation
Plugin 'majutsushi/tagbar' " Class/module browser
"------------------=== Other ===----------------------
Plugin 'tpope/vim-surround' " Parentheses, brackets, quotes, XML tags, and more
Plugin 'kien/ctrlp.vim' " Convenient navigation
Plugin 'vim-scripts/diffchanges.vim' " difchanges in file
"--------------=== Snippets support ===---------------
Plugin 'SirVer/ultisnips' " Track the engine.
Plugin 'honza/vim-snippets' " snippets repo
"--------------=== Completion ===---------------
" Plugin 'Shougo/neocomplete' " completion
Plugin 'Valloric/YouCompleteMe' " completion
Plugin 'shvechikov/vim-keymap-russian-jcukenmac' " alternative keymap for mac
Plugin 'ervandew/supertab' " man c-n to tab for compatibility YCM with UltiSnips
"------------------=== Latex ===---------------------
Plugin 'lervag/vim-latex' " latex module
"------------------=== Colors ===---------------------
Plugin 'altercation/vim-colors-solarized' " solarized colors
"---------------=== Languages support ===-------------
" --- Python ---
Plugin 'klen/python-mode' " Python mode (docs, refactor, lints, highlighting, run and ipdb and more)
" Plugin 'mitsuhiko/vim-jinja' " Jinja support for vim
" Plugin 'mitsuhiko/vim-python-combined' " Combined Python 2/3 for Vim
call vundle#end() " required
"====================================================
" YouCompleteMe and UltiSnip fix settings
"=====================================================
" show completion even in comments
let g:ycm_complete_in_comments = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_collect_identifiers_from_tags_files = 1
" set omnifunc=syntaxcomplete#Complete
let g:ycm_filetype_blacklist = {}
" add language keywords to list of autocomplete
let g:ycm_seed_identifiers_with_syntax = 1
" if one want to use ctags he should assure oneself that
" >> ctags --version print Exuberant Ctags, see :help YouCompleteMe
let g:ycm_key_list_select_completion=['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion=['<C-p>', '<Up>']
let g:UltiSnipsExpandTrigger="<Tab>"
let g:UltiSnipsJumpForwardTrigger="<Tab>"
let g:UltiSnipsJumpBackwardTrigger="<S-Tab>"
let g:UltiSnipsSnippetsDir = "~/.vim/bundle/vim-snippets/UltiSnips"
"====================================================
" Latex settings
"=====================================================
" Enable latex
let g:latex_enabled = 1
" complete closing brace on label editing
" let g:latex_complete_close_braces = 1
" jump to the first error on quickfix window is open
let g:latex_quickfix_autojump = 1
" ignore any warnings
let g:latex_quickfix_ignore_all_warnings = 1
" which warnings should be ignored
let g:latex_quickfix_ignored_warnings = [ ]
" \ 'Underfull',
" \ 'Overfull',
" \ 'specifier changed to',
" \ ]
" callback
let g:latex_latexmk_callback = 1
" set viewer and configure forward search with <leader>ls combination
let g:latex_view_general_viewer = 'open -a Skim'
let g:latex_view_general_viewer = '/Applications/Skim.app/Contents/MacOS/Skim'
"====================================================
" General settings
"=====================================================
" do not close files when type :e filename
set hidden
filetype on
filetype plugin on
filetype plugin indent on
set backspace=indent,eol,start
" aunmenu Help.
" aunmenu Window.
let no_buffers_menu=1
set mousemodel=popup
set ruler
set completeopt-=preview
set gcr=a:blinkon0
if has("gui_running")
set cursorline
endif
set ttyfast
syntax on
if has("gui_running")
" GUI? Устанавливаем тему и размер окна
set background=dark
set lines=40 columns=125
let g:solarized_termcolors=256
colorscheme solarized
if has("mac")
set guifont=Consolas:h16
set fuoptions=maxvert,maxhorz
else
set guifont=Ubuntu\ Mono\ derivative\ Powerline\ 15
endif
else
" colorscheme solarized
endif
set switchbuf=useopen
set enc=utf-8 " utf-8 по дефолту в файлах
set ls=2 " всегда показываем статусбар
set incsearch " инкреминтируемый поиск
set hlsearch " подсветка результатов поиска
set nu " показывать номера строк
set relativenumber " относительная нумерация строк
" autocmd InsertEnter * :set number
" autocmd InsertLeave * :set relativenumber
set scrolloff=5 " 5 строк при скролле за раз
set ignorecase
set smartcase " case searching tunning
" hide panels
set guioptions-=m " меню
set guioptions-=T " тулбар
set guioptions-=r " скроллбары
" tab tunning
set tabstop=4
set shiftwidth=4
set expandtab
set showmatch " set show matching parenthesis
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title " change the terminal's title
set visualbell " don't beep
set noerrorbells " don't beep
" disable colorcolumn that is set up nowhere ??
highlight ColorColumn ctermbg=DarkGray
" all spaces at the end of lines highlight with DarkGray color
highlight WhitespaceEOL ctermbg=8 guibg=#073642
match WhitespaceEOL /\s\+$/
" delete all spaces at the end of lines
autocmd BufWritePre * :%s/\s\+$//e
"----------========= Folding ==========------------
" remap keys zj an zk to jump to next closed fold
nnoremap <silent> <leader>zj :call NextClosedFold('j')<cr>
nnoremap <silent> <leader>zk :call NextClosedFold('k')<cr>
function! NextClosedFold(dir)
let cmd = 'norm!z' . a:dir
let view = winsaveview()
let [l0, l, open] = [0, view.lnum, 1]
while l != l0 && open
exe cmd
let [l0, l] = [l, line('.')]
let open = foldclosed(l) < 0
endwhile
if open
call winrestview(view)
endif
endfunction
"folding settings
" set foldmethod=indent "fold based on indent
" set foldnestmax=10 "deepest fold is 10 levels
" set nofoldenable "dont fold by default
" set foldlevel=1 "this is just what i use
" toggle fold with space rather then inconvenient za
"nnoremap <space> za
" highlight text on dark when exceeding 80 column
augroup vimrc_autocmds
autocmd!
autocmd FileType ruby,python,javascript,c,cpp highlight Excess ctermbg=DarkGrey guibg=Black
autocmd FileType ruby,python,javascript,c,cpp match Excess /\%80v.*/
autocmd FileType ruby,python,javascript,c,cpp set nowrap
augroup END
" show NERDTree on F1 pressed
map <F1> :NERDTreeToggle<CR>
" ignore theese extensions
let NERDTreeIgnore=['\~$', '\.pyc$', '\.pyo$', '\.class$', 'pip-log\.txt$', '\.o$']
" set switching to Russian keyboard by pressing C-^
" the combination is awful but it is default and we will use it
" set keymap=russian-jcukenmac
" " the option for being able to press CTRL-N or CTRL-P to complete from
" set iminsert=0
" set imsearch=0
" highlight lCursor guifg=NONE guibg=Cyan
" задаём проверку правописания
set langmap=йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],фa,ыs,вd,аf,пg,рh,оj,лk,дl,э'
set langmap+=яz,чx,сc,мv,иb,тn,ьm,ю.,ЙQ,ЦW,УE,КR,ЕT,НY,ГU,ШI,ЩO,ЗP,Х{,Ъ},ФA,ЫS
set langmap+=ВD,АF,ПG,РH,ОJ,ЛK,ДL,ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Ж:,Б<,Ю>,]`,[~
set langmap+=\\;*,\\,^
set spelllang=ru_ru,en_us
" get suggestions on spelling
set complete+=kspell
" check spell by default
set spell
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
" wrap long lines to the new lines
set wrap
" do not break words in the middle
set linebreak
"====================================================
" Here would be useful comments on how vim executes,
" behaves, some useful features, links, etc.
"=====================================================
"
" 1. To see where all keymaps appears to be on the FS:
" :echo globpath(&rtp, "keymap/*.vim")
" 2. See all mappings: :help index
"
"
endif

What causes substitution in Vim to only match one element per line?

I've been making a lot of changes to my .vimrc lately, and somewhere along the line I've introduced an undesirable feature. When performing a substitution command where the search token appears more than once per line, only the first token is changed (although the remaining tokens are highlighted as a result of the substitution). I have seen a few posts here about how to enable this behavior on a case-by-case basis, but I have yet to see something about what would cause this to be the default behavior or how to disable it. If anyone has any ideas, they would be appreciated.
For reference, my .vimrc (https://github.com/chpatton013/dotfiles/blob/master/vim/.vimrc):
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Reread configuration of Vim if .vimrc is saved
augroup VimConfig
au!
au BufWritePost ~/.vimrc so ~/.vimrc
au BufWritePost _vimrc so ~/_vimrc
au BufWritePost vimrc so ~/.vimrc
augroup END
" Set colorcolumn to 80 chars, or (if not supported) highlight lines > 80 chars
augroup ColorColumnConfig
au!
if exists('+colorcolumn')
au BufWinEnter * set colorcolumn=80
au BufWinEnter * hi ColorColumn ctermbg=lightgrey guibg=lightgrey
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
augroup END
" Highlight over-length characters and trailing whitespace
augroup ExtraCharacters
au!
au ColorScheme * highlight ExtraWhitespace ctermbg=Red guibg=Red
au ColorScheme * highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
au BufWinEnter * let w:whitespace_match_number =
\ matchadd('ExtraWhitespace', '\s\+$')
au BufWinEnter * call matchadd('OverLength',
\ '\(^\(\s\)\{-}\(*\|//\|/\*\)\{1}\(.\)*\(\%81v\)\)\#<=\(.\)\{1,}$')
au InsertEnter * call s:ToggleWhitespaceMatch('i')
au InsertLeave * call s:ToggleWhitespaceMatch('n')
augroup END
" Resize splits on window resize
au VimResized * exe "normal! \<c-w>="
" Restore the cursor when we can.
au BufWinEnter * call RestoreCursor()
" Change the statusline color based on current mode
augroup StatuslineColor
au!
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline ctermfg=cyan ctermbg=black guifg=cyan guibg=black
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pathogen - https://github.com/tpope/vim-pathogen
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
" Easymotion - https://github.com/Lokaltog/vim-easymotion/
" This is so much more convenient
let g:EasyMotion_leader_key=',m'
" Neocomplcache - https://github.com/Shougo/neocomplcache
" Enable at startup.
let g:neocomplcache_enable_at_startup=1
" Only display 'n' items in the list.
let g:neocomplcache_max_list=5
" Do not auto-select the first candidate.
let g:neocomplcache_enable_auto_select=1
" Do not try to match until 'n' characters have been typed
let g:neocomplcache_auto_completion_start_length=3
" Do not try to match to anything less than 'n' characters
let g:neocomplcache_min_keyword_length=6
let g:neocomplcache_min_syntax_length=6
" Only consider case if an uppercase character has been typed
let g:neocomplcache_enable_smart_case=1
" Syntastic - https://github.com/scrooloose/syntastic/
" Commands:
" :Errors // pop up location list and display errors
" :SyntasticToggleMode // toggles between active and passive mode
" :SyntasticCheck // forces a syntax check in passive mode
" check for syntax errors on file open
let g:syntastic_check_on_open=1
" echo errors to the command window
let g:syntastic_echo_current_error=1
" mark lines with errors and warnings
let g:syntastic_enable_signs=1
" set sign symbols
let g:syntastic_error_symbol='E>'
let g:syntastic_warning_symbol='W>'
let g:syntastic_style_error_symbol='S>'
let g:syntastic_style_warning_symbol='s>'
" open error balloons when moused over erroneous lines
let g:syntastic_enable_balloons=1
" customize Syntastic statusline
let g:syntastic_stl_format = '[%E{E: %fe #%e}%B{, }%W{W: %fw #%w}]'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
let _s=#/
let l = line(".")
let c = col(".")
%s/\s\+$//e
let #/=_s
call cursor(l, c)
endfunction
" Toggle match of trailing whitespace
function! s:ToggleWhitespaceMatch(mode)
let pattern = (a:mode == 'i') ? '\s\+\%#\#<!$' : '\s\+$'
if exists('w:whitespace_match_number')
call matchdelete(w:whitespace_match_number)
call matchadd('ExtraWhitespace', pattern, 10, w:whitespace_match_number)
else
" Something went wrong, try to be graceful.
let w:whitespace_match_number = matchadd('ExtraWhitespace', pattern)
endif
endfunction
" Restore the cursor when we can
function! RestoreCursor()
if line("'\"") <= line("$")
normal! g`"
normal! zz
endif
endfunction
" Change the statusline color based on current mode
function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi statusline ctermfg=darkmagenta ctermbg=black guifg=darkmagenta guibg=black
elseif a:mode == 'r'
hi statusline ctermfg=darkgreen ctermbg=black guifg=darkgreen guibg=black
else
hi statusline ctermfg=darkred ctermbg=black guifg=darkred guibg=black
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Configuration customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" gui configuration (do not move from top of configurations)
set guioptions=am
set guifont=Consolas:h9
set encoding=utf-8
set fileencoding=utf-8
set nocompatible " No compatibility with vi.
filetype on " Recognize syntax by file extension.
filetype indent on " Check for indent file.
filetype plugin on " Allow plugins to be loaded by file type.
behave xterm " Maintain keybindings across enviornments
set autowrite " Write before executing the 'make' command.
set background=dark " Background light, so foreground not bold.
set backspace=indent,eol,start " Allow <BS> to go over indents, eol, and start of insert
set expandtab " Expand tabs with spaces.
set nofoldenable " Disable folds; toggle with zi.
set gdefault " Assume :s uses /g.
set hidden " Use hidden buffers so unsaved buffers can go to the background
set history=500 " Set number of lines for vim to remember
set hlsearch " Highlight all search matches
set ignorecase " Ignore case in regular expressions
set incsearch " Immediately highlight search matches.
set laststatus=2 " Show status line even where there is only one window
set lazyredraw " Redraw faster
set linespace=-1 " Bring lines closer together vertically
set modeline " Check for a modeline.
set noerrorbells " No beeps on errors.
set nohls " Don't highlight all regex matches.
set nowrap " Don't soft wrap.
set number " Display line numbers.
set path=~/Code/** " Set default path
set scrolloff=5 " Keep min of 'n' lines above/below cursor.
set shellslash " Use forward slashes regardless of OS
set shiftwidth=3 " >> and << shift 3 spaces.
set showcmd " Show partial commands in the status line.
set showmatch " Show matching () {} etc..
set showmode " Show current mode.
set sidescrolloff=10 " Keep min of 'n' columns right/left cursor.
set smartcase " Searches are case-sensitive if caps used.
set smarttab " Tabs and backspaces at the start of a line indent the line one level
set smartindent " Maintains most indentation and adds extra level when nesting
set softtabstop=3 " See spaces as tabs.
set splitright splitbelow " Open splits below and to the right
set synmaxcol=160 " Only matches syntax on first 'n' columns of each line ( faster)
set tabstop=3 " <Tab> move three characters
set textwidth=79 " Hard wrap at 79 characters
set title " Set the console title
set viminfo='20,\"500,% " Adjust viminfo contents
set virtualedit=block " Allow the cursor to go where it should not
set wildmenu " Tab completion opens a Tab- and arrow-navigable menu
set wildmode=longest,full " Tab completion works like bash.
set wrapscan " Searching wraps to start of file when end is reached
" Define statusline
set statusline=%f " Relative file path
set statusline+=%(\ [%M%R%H%W]%) " File flags (mod, RO, help, preview)
set statusline+=%(\ %<%) " Start truncation
set statusline+=%(\ %{fugitive#statusline()}%) " Git branch name (if applicable)
set statusline+=%= " Begin right justification
set statusline+=%#warningmsg# " Start warning highlighting
set statusline+=%(\ %{SyntasticStatuslineFlag()}%) " Show Syntastic errors and warnings
set statusline+=%* " End warning highlighting
set statusline+=\ [line\ %l\/%L,\ col\ %c%V,\ %p%%] " Line and column numbers and percentage through file
" Text formatting settings
" t: Auto-wrap text using textwidth. (default)
" c: Auto-wrap comments; insert comment leader. (default)
" q: Allow formatting of comments with "gq". (default)
" r: Insert comment leader after hitting <Enter>.
" o: Insert comment leader after hitting 'o' or 'O' in command mode.
" n: Auto-format lists, wrapping to text *after* the list bullet char.
" l: Don't auto-wrap if a line is already longer than textwidth.
set formatoptions+=ronl
" Enable mouse scrolling in selected modes
" a: All
" c: Command
" i: Insert
" n: Normal
" v: Visual
set mouse=a
" Set scrolling to be single-line
"map <MouseDown> <C-Y>
"map <S-MouseDown> <C-U>
"map <MouseUp> <C-E>
"map <S-MouseUp> <C-D>
" Highlighting
syntax enable
set t_Co=16
colorscheme solarized
" Configuration variables
let loaded_matchparen=0 " do automatic bracket highlighting.
let mapleader="," " Use , instead of \ for the map leader.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command mode customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Make y behave like all other capitals
map Y y$
" Make Q reformat text.
noremap Q gq
" Toggle paste mode.
noremap <Leader>p :set paste!<CR>
" Open the file under the cursor in a new tab.
noremap <Leader>ot <C-W>gf
" Toggle highlighting of the last search.
noremap <Leader>h :set hlsearch! hlsearch?<CR>
" Open a scratch buffer.
noremap <Leader>s :Scratch<CR>
" Improve movement on wrapped lines
nnoremap j gj
nnoremap k gk
" Keep search pattern at the center of the screen
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
nnoremap <silent> g# g#zz
" Use C-hjkl in to change windows
nnoremap <C-h> <C-w><Left>
nnoremap <C-j> <C-w><Down>
nnoremap <C-k> <C-w><Up>
nnoremap <C-l> <C-w><Right>
" Strip trailing whitespace
nnoremap <silent> <leader>W :call <SID>StripTrailingWhitespaces()<CR>
" Allow easy toggling of spaces / tabs mode
nnoremap <C-t><C-t> :set invexpandtab<CR>
" Create simple toggles for line numbers, paste mode, and word wrap.
nnoremap <C-N><C-N> :set invnumber<CR>
nnoremap <C-p><C-p> :set invpaste<CR>
nnoremap <C-w><C-w> :set invwrap<CR>
" Folding stuff
nnoremap <C-o> zo
nnoremap <C-c> zc
nnoremap <C-O> zO
nnoremap <C-O><C-O> zR
set foldmethod=indent
" Open file for class name under cursor
nnoremap <C-i> yiw:find <C-R>".php<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Insert mode customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set up dictionary completion.
set dictionary+=~/.vim/dictionary/english-freq
set complete+=k
" Smash Esc
inoremap jk <Esc>
inoremap kj <Esc>
" Use hjkl in insert mode
imap <C-h> <Left>
imap <C-j> <Down>
imap <C-k> <Up>
imap <C-l> <Right>
" Make C-s write the buffer and return to insert mode when applicable
inoremap <C-s> <C-O>:w<CR>
nnoremap <C-s> :w<CR>
" auto-insert second braces and parynthesis
inoremap {<CR> {<CR>}<Esc>O
inoremap ({<CR> ({<CR>});<Esc>O
inoremap <<<<CR> <<<EOT<CR>EOT;<Esc>O<C-TAB><C-TAB><C-TAB>
set cpoptions+=$ "show dollar sign at end of text to be changed
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual mode customization
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" reselect visual block after indent/outdent
xnoremap < <gv
xnoremap > >gvo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
And the following plugins make up the contents of my bundle directory (https://github.com/chpatton013/dotfiles/tree/master/vim/.vim/bundle):
neocomplcache/
syntastic/
vim-abolish/
vim-colors-solarized/
vim-commentary/
vim-easymotion/
vim-fugitive/
vim-pathogen/
vim-repeat/
vim-surround/
Finally, I have disabled all plugins, but the issue was not resolved. I removed my .vimrc and the issue was resolved (so it is not some global setting outside of my control). I disabled several individual settings in my .vimrc, but I could not seem to eliminate the problem. Eventually, I got tired of playing whack-a-mole and decided to turn to the community. Any ideas?
EDIT: As an example,
I use the command :%s/foo/foobar/g
The text foo bar foo is converted to foobar bar foo
EDIT: Resolved by pb2q. set gdefault inverts the behavior of /g.
The substitute command accepts the switch g, for global, which causes the substitution to be made on all matches on the line:
:s/regex/replacement/g
The default is that only the first occurrence of the match is substituted, but there's a setting to switch the default to global: gdefault. So set gdefault in your vimrc if you want this as the default behavior. Try it out first in the current vim session with :set gdefault.
Note that when you set gdefault, this not only makes g the default behavior, but it changes the usage of the g flag so that using /g at the end of a substitute will cause the substitution to be made only once.
See: :help gdefault.

Resources