Compile error or warning will close project in VIM - linux

I'm using VIM for writing some basic C algorithms. I have some key binded to SCCompile plugin and when I press it it will compile my program. If there is no problem it will show me press any key, and then I'm back in VIM with opened file. But if there is some problem or warning, it will just show me that error and I don't know how can I get back to my file.
Is there some command how can I get back to project? Or do I need reopen it?
There is my .vimrc file:
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" All of your Plugins must be added before the following line
call vundle#end() " required
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set nocompatible
filetype plugin indent on
syntax on
silent! runtime macros/matchit.vim
set autochdir
set backspace=indent,eol,start
set foldenable
set hidden
set incsearch
set laststatus=2
set ruler
set switchbuf=useopen,usetab
set tags=./tags,tags;/
set wildmenu
nnoremap gb :buffers<CR>:sb<SPACE>
set number
set tabstop=4
set shiftwidth=4
set softtabstop=4
set fo=cqt
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
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
filetype plugin on
if &term=="xterm"
set t_Co=8
set t_Sb=[4%dm
set t_Sf=[3%dm
endif
" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
autocmd Filetype c nmap <buffer> <F5> :SCCompileAF -std=c99 -Wall -Wextra -pedantic <CR>
execute pathogen#infect()

From what I can tell the SCCompile plugin is supposed to make it easier to compile thing in Vim. I cannot vouch for this claim but the plugin's documentation states that if an error during compiling then you should use the quickfix list.
To understand this process it is probably easier to first understand Vim's native :make / quickfix workflow.
:make
Running :make will execute the make program, 'makeprg'. Then parse the output with 'errorformat' and put each entry into the quickfix list.
Typically 'makeprg' defaults to the make command which runs a Makefile. However you can change your 'makeprg' via the :compiler command or set it directly.
You can also pass extra arguments to :make. e.g. :make clean
Note: running :make will often show the output of the command at the bottom of the screen with a prompt asking to press enter. Just press enter as all the output will be available in the quickfix list.
quickfix list
After you run :make your quickfix list will hold the output of compiler.
Use the following command to navigate the quickfix list.
:copen to open the quickfix window
:cclose to close the quickfix window
:cnext/:cprev to move to the next/previous item
:cc to print out at the bottom the current error or :cc 3 to show a specific error in this example 3
Personally I use Tim Pope's unimpaired plugin to navigate the quickfix list.
Back to using SCCompile
From what I can tell SCCompile is wrapper around :make that handles setting up 'makeprg' and/or 'errorformat'. Therefore SCCompile is just a drop in replacement for :make. To compile just execute your SCCompile mapping and then use the quickfix list to check your errors.
Please take a look at SCCompile's documentation: :h SingleCompile-overview and :h SingleCompile-contents.
Conclusion
As you are a newbie then I would suggest creating a Makefile and using :make because that will keep things very simple and as well as have a nice record of how you compiled your program.
I would also suggest you look into create a mapping to run :make. Example:
nnoremap <f5> :make<cr>
For more information see
:h :make
:h 'makeprg'
:h 'errorformat'
:h :compiler
:h quickfix
:h :cc
:h :cope
:h :cnext

Related

vim help produces "unable to open swap file" error

In vim, frequently when I perform a ':help ' command, I get an error. Here's an error I see when I perform ':help tags' for example:
"tagsrch.txt.gz" [readonly][noeol] 42L, 11288C
Error detected while processing function gzip#read:
line 51:
E303: Unable to open swap file for "/usr/share/vim/vim74/doc/tagsrch.txt.gz", recovery impossible
41 fewer lines
Press ENTER or type command to continue
When I press enter, the help comes up as desired, but this is still a nuisance. What have I done wrong? My google-foo is apparently too weak for this because I don't see other people complaining about this.
Is this because I have this set for my swap directory?
set directory=~/.vim/swap,.
Let me know if it would be helpful to paste my entire vimrc. I'm on rhel7 with vim 7.4, in case it's helpful.
Here's my ~/.vimrc:
" vim:softtabstop=4:shiftwidth=4:et
" Tab preferences
set shiftwidth=4
set softtabstop=4
set autoindent
set expandtab
execute pathogen#infect()
" Where to store swap files. By default, they will go into ~/.vim/swap, but
" if that doesn't work, they will go in cwd.
set directory=~/.vim/swap,.
filetype plugin indent on " enables filetype indent specific plugins
" Instructions on how to tab complete filenames.
" set wildmode=longest,list,full
set wildmode=longest,list
set wildmenu
" In case there are vim modelines at the top of the file, as there
" is with this one.
set modeline
" Always show the status line.
set laststatus=2
" Look for a tags file.
set tags=./tags,tags;
" Also search for .git/tags files.
set tags^=./.git/tags,*/.git/tags;~
" Make Ctrl-] show the list of options by default.
nnoremap <C-]> g<C-]>
nnoremap <C-w><C-]> <C-w>g<C-]>
" Colors
" Have syntax highlighting in terminals which can display colours:
if has('syntax') && (&t_Co > 2)
syntax on
else
syntax off
endif
set background=dark
set hlsearch
set incsearch
" I so often type teh instead of the.
abbreviate teh the
" To help vim deal with pasting text
:map <F9> :set invpaste <CR>
set pt=<F9>
" Toggle vim's spell checker with <F5>
:map <F5> :setlocal spell! spelllang=en_us<cr>
" Shortcuts for c code.
map! ,bc /* */^[hhi
map! ,bz #if 0^M#endif /* 0 */^[O
" Ignore whitespace when diffing files.
map ,iw :set diffopt+=iwhite<CR>
set path^=/home/bneradt/work/trafficserver/**
In my situation / partition is full. Cleaned it and it works now.

Why is Vim so slow?

I am a beginning vim user and I am a little confused. It looks like Vim is slower than Geany. And it is a very noticeable difference. When I hold any key in Geany it prints it without any lag (llllllll for example). In Vim it is slow and jumping. Autocomplete in vim is horrible in comparison to Geany. I thought Vim is as fast as light. It looks like it isn't. Is there any advice to change that, make vim faster?
This is my _vimrc file:
" This must be first, because it changes other options as side effect
set nocompatible
" Use pathogen to easily modify the runtime path to include all
" plugins under the ~/.vim/bundle directory
call pathogen#helptags()
call pathogen#infect()
" change the mapleader from \ to ,
let mapleader=","
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
set hidden
set nowrap " don't wrap lines
set tabstop=4 " a tab is four spaces
set backspace=indent,eol,start
" allow backspacing over everything in insert mode
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set number " always show line numbers
set shiftwidth=4 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch " set show matching parenthesis
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,
" case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to
" shiftwidth, not tabstop
set hlsearch " highlight search terms
set incsearch " show search matches as you type
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
set nobackup
set noswapfile
filetype plugin indent on
autocmd filetype python set expandtab
if &t_Co >= 256 || has("gui_running")
colorscheme badwolf
endif
if &t_Co > 2 || has("gui_running")
" switch syntax highlighting on, when the terminal has colors
syntax on
endif
" Vim can highlight whitespaces for you in a convenient way:
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:.
set pastetoggle=<F2>
set mouse=a " Enable mouse
set encoding=utf-8
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set autochdir " working directory is always the same as the file you are editing
noremap <F5> :w !python %<CR>
inoremap <F5> <ESC>:w !python %<CR>
nmap <leader>t :NERDTree<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
set guifont=Hack:h10:cDEFAULT
let g:Powerline_symbols = 'fancy'
set laststatus=2
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
filetype plugin on
set omnifunc=syntaxcomplete#Complete
au CompleteDone * pclose
set completeopt=longest,menuone,preview
set guioptions-=T
set nofoldenable " disable folding
nmap <silent> ,/ :nohlsearch<CR>
It could be a lot of things, not necessarily Vim's fault. Actually it's unlikely to be vim's fault.
First, get a feel for how fast Vim can be: run with vim -u NONE and comment out everything in your .vimrc - then do the single thing that seems slow.
Run without the -u NONE and compare. It should be just as fast, or some plugin is autoloaded and is causing problems. If so, try and temporarily move files away from the ~/.vim/bundle directory.
Next, uncomment half of your .vimrc and check if it causes the slowness or not. Keep commenting/uncommenting until you find the exact line.
Google the line that caused the slowness and find out if there are alternatives.
I'm guessing you could be doing an expensive operation with every scroll, such as checking the file syntax.
It's best to hunt down the slowness step by step.
Another issue may be slow terminal and/or drivers (so compare Vim with GVim). If you have a slow terminal with fancy fonts, transparency, small font and big screen size, terminals can be very, very, VERY slow.
If you use vim in terminal like me (and not GVim), I just found that, try, and it seems pretty good :
add this in your ~/.vimrc :
set timeoutlen=1000
set ttimeoutlen=0
and this (even more important) in your ~/.screenrc :
maptimeout 0
Since I did that, everything is better.
My vim started to fly after I added the following config to my vimrc, this is extremely useful when you keep vim running all day/week long editing a lot of different files with opening and closing them often.
function! CloseHiddenBuffers()
" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
" close any buffers hidden
" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
let open_buffers = []
for i in range(tabpagenr('$'))
call extend(open_buffers, tabpagebuflist(i + 1))
endfor
for num in range(1, bufnr("$") + 1)
if buflisted(num) && index(open_buffers, num) == -1
exec "bdelete ".num
endif
endfor
endfunction
au BufEnter * call CloseHiddenBuffers()
I had a similar problem where pasting paragraphs of text or just typing at a typical speed would hang vim.
You could troubleshoot your .vimrc, and if you are, take a look at this question to see which plugins are slow. You could also skip the troubleshooting and use neovim, which is fully compatible with vim and asynchronous.
My issues with input lag disappeared once I started using it. It uses an async library libuv, which is the same library powering node. I'm using the same .vimrc as with vim (copied to ~/.config/nvim/init.vim), so it's not a matter of different plugins. I also see this responsiveness improvement on both Ubuntu 20.04 and Macos 10.14.
I'm posting this answer because I wish it had existed when I last read this question.

Slow performance on CtrlP , it doesn't work to ignore some folders

I tried to ignore the vendor by adding the following setting in .vimrc
and I start my ctrlP by typing ff
map ff :CtrlP<.><cr>
However, it still tried to index all the files under the zeus folder including vendor folder.
But after finishing index, I still can NOT search the files under vendor,
Why does CtrlP take long time to index ?
129 "add ctrlp.vim setting
130 ""
131 set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
132 let g:ctrlp_custom_ignore = 'tmp$\|\.git$\|\.hg$\|\.svn$\|.rvm$|.bundle$\|vendor'
133 let g:ctrlp_working_path_mode = 'ra'
134 let g:ctrlp_match_window_bottom=1
135 let g:ctrlp_max_height=25
136 let g:ctrlp_match_window_reversed=0
137 let g:ctrlp_mruf_max=500
138 let g:ctrlp_follow_symlinks=1
139 let g:ctrlp_clear_cache_on_exit=0
Here is my .vimrc, I thought there might be some settings conflicting each other
hi Comment ctermfg=6
"make vim save and load the folding of the document each time it loads"
""also places the cursor in the last place that it was left."
au BufWinLeave *.* mkview
au BufWinEnter *.* silent loadview
"function SetCafeOptions()
"CoffeeCompile
":set nonu
":res -24
":res +24
"endfunction
set encoding=utf-8
set fileencoding=utf-8
colorscheme elflord
set smartindent
set tabstop=4
set expandtab
set shiftwidth=4
"make it autoreload
set autoread
"auto move it last time the position you viewed
"make vim save and load the folding of the document each time it loads"
""also places the cursor in the last place that it was left."
"try to set show ansi color
if &term=="ansi"
set t_Co=0
endif
"set expandtab
filetype on
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
set cscopetag
set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-
endif
"let Tlist can close windows at one time
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
" Key map
" Presee F4 and you can open the NERDTree
nnoremap <silent> <F4> :NERDTree<CR>
"nnoremap <silent> <F3> :!/usr/bin/env python %<CR>
" Show function List with Tlist
nnoremap <F12> :TlistToggle<CR>
" Map ctrl+q to ctrlw+ctrlw
"
"nnoremap <silent> <C-q> :<C-w><C-w>
"switch in splitted window
map <c-d> <c-w>l
map <c-a> <c-w>h
"set highlight
set hlsearch
"set autocomplet
"autocmd BufNewFile,BufRead *.html.erb set filetype=html.eruby
autocmd BufNewFile,BufRead *.html.erb set filetype=erb.html.eruby
filetype plugin indent on
"auto import python template
autocmd bufnewfile *.py 0r ~/common_lib/python_lib/tmpl.py
map ff :CtrlP<.><cr>
"set NerdTreeSize
let g:NERDTreeWinSize=12
let g:NERDTreeIgnore=['\.vim$', '\~$', '\vendor$']
"auto close the nerdtress window whe you open new file
"let g:ctrlp_dont_split = 'nerdtree'
set nocompatible " explictly get out of vi-compatible mode
set background=dark " we plan to use a dark background
syntax on " syntax highlighting on
set number " turn on line numbers
set ruler "always show current position along the bottom
set incsearch " do highlight as you type you search phrase
set ignorecase " case insensitive by default
set smartcase " if there are caps, go case-sensitive
"Rope vim
"let $PYTHONPATH .= ":~/install/ropehg/rope:~/install/ropehg/ropemode:~/install/ropehg/ropevim"
"source ~/install/ropehg/ropevim/ropevim.vim
"let g:pymode_rope_goto_def_newwin = "new"
"let ropevim_vim_completion=1
"Use Ctrl + ] . to autocomple
inoremap <C-]> <C-R>=RopeCodeAssistInsertMode()<CR>
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>
" Load the whole plugin
let g:pymode = 1
" Load run code plugin
let g:pymode_run = 1
"add ctrlp.vim setting
""
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
let g:ctrlp_custom_ignore = 'tmp$\|\.git$\|\.hg$\|\.svn$\|.rvm$|.bundle$\|vendor'
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=25
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
let g:ctrlp_clear_cache_on_exit=0
"Vundle
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-surround'
Bundle 'Raimondi/delimitMate'
"coffee script"
Bundle 'kchmck/vim-coffee-script'
Bundle 'ack.vim'
Bundle 'matchit.zip'
Bundle 'kien/ctrlp.vim'
"Markdown"
"Bundle 'plasticboy/vim-markdown'
""Vim-scripts repo
"Bundle 'The-NERD-Commenter'
Bundle 'pep8'
""Bundle 'AutoClose'
Bundle 'desert-warm-256'
Bundle 'https://github.com/altercation/vim-colors-solarized.git'
filetype plugin indent on
nmap <leader>a <Esc>:Ack ""
"folding code
nnoremap <space> za
vnoremap <space> zf
" pep8
let g:pep8_map='<leader>8'
"coffee script"
call pathogen#infect()
let Tlist_Use_Right_Window = 1
"autocmd BufEnter * if &filetype == "" | setlocal ft=python | endif
"markdown https://github.com/plasticboy/vim-markdown/wiki"
"let g:vim_markdown_folding_disabled=1
"auto exec ruby and coffee script with F5 , remeber to save file before launching
autocmd FileType python map <leader>p :!python %<cr>
autocmd FileType ruby,rb map <leader>5 :w!<cr>:!ruby %<cr>
autocmd FileType * map <leader>e :qa!<cr>
"set extension .god as a Ruby file"
"au BufNewFile,BufRead *.god set filetype=ruby
"autocmd FileType coffee nmap <F5> :CoffeeCompile<cr>
"autocmd FileType coffee map <F5> :call SetCafeOptions()<cr>
"so ~/.vim/snippets/support_functions.vim
set re=1
autocmd Filetype gitcommit setlocal spell textwidth=72
" enable per-project .vimrc files
set exrc
" " Only execute safe per-project vimrc commands
set secure"
Here are a few tips that should definitely speed up ctrlp :
let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp'
if executable('ag')
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
In the above example, the first option tells ctrlp to persist the cache in the configured location, so when you launch vim again, it will read from there and load the cache (much faster).
The second option configures ctrlp to use ag (the_silver_searcher) instead of vim's native globpath() apis to search for files, this will drastically improve it's scanning speed, if you don't want to use ag, you can even use plain old grep and it still should be significantly faster. Check :h 'g:ctrlp_user_command' for more details.
As I explained here, if you type :help ctrlp-options and read a bit, you will find:
Note #1: by default, wildignore and g:ctrlp_custom_ignore only
apply when globpath() is used to scan for files, thus these options
do not apply when a command defined with g:ctrlp_user_command is
being used.
Thus, you may need to unlet g:ctrlp_user_command (possibly set to a default command) to actually use wildignore. For instance, in your ~/.vimrc, add:
if exists("g:ctrl_user_command")
unlet g:ctrlp_user_command
endif
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
...
After that, you need to refresh your ctrlp cache: in Vim, press F5 in ctrlp mode, or run :CtrlPClearAllCaches, or remove the cache directory directly in your shell:
rm -r ~/.cache/ctrlp/ # On Linux
As for the indexing part (which seems to be your problem), it should follow your ignore rules. You can check the indexed files in ~/.cache/ctrlp/%path%to%your%project%folder.txt.
Last resort for a quick startup
I tried everything I found in different places to improve the indexing speed of my ctrlp, but nothing helped.
At the end, I settled with this:
let g:ctrlp_clear_cache_on_exit = 0
It keeps the ctrlp cache after you close VIM, so the next start up will be fast. And you can update the cache manually by pressing F5 anytime you need.
Found this bit while looking around the interwebs, and it has made indexing and searching for files instant.
let g:ctrlp_user_command = ['.git/', 'git ls-files --cached --others --exclude-standard %s']
I'm not fully grasping what is happening here, so if anyone has a bit more knowledge to dissect this, I'd love to know what's happening behind the scenes.
If you have ripgrep (rg) installed you can use it with CtrlP. It is much faster than the default file search. This is the incantation you need to make it work:
if executable('rg')
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
h/t Elliot Jackson

Matchit not working

I am using Macvim 7.3 snapshot 57. I can't seem to get matchit to work in any of my files.
I press % on an opening tag. It doesn't take me to the closing tag...
My vimrc file:
" Pathogen settings
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
set nocompatible
set number
set ruler
set cursorline
syntax on
" Disable all blinking
set guicursor+=a:blinkon0
" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set expandtab
set cindent
set smartindent
set autoindent
set list listchars=tab:\ \ ,trail:·
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
" Status bar
set laststatus=2
" Start without the toolbar
set guioptions-=T
" Default gui color scheme
" "color default
" color molokai
color railscasts+
" Command-/ to toggle comments
map <D-/> :TComment<CR>j
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
" Thorfile, Rakefile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby
" Open split buffers below instead of above current buffer
set splitbelow
" Session options
let g:session_autoload = 1
let g:session_autosave = 1
" Buffer navigation
map <C-K> <C-W><C-K>
map <C-J> <C-W><C-W>
map <C-H> <C-W><C-H>
map <C-L> <C-W><C-L>
" Rails navigation options
nmap <leader>rc :Rcontroller
nmap <leader>rv :Rview
nmap <leader>rm :Rmodel
" Tab completion
" Also needed for better Rails navigation auto-completion
set wildmode=list:longest,list:full
" Open up side panel left (NERDTree) and right(Tagbar)
" nmap <leader>\ :NERDTreeToggle<CR> :TagbarToggle<CR>
nmap <leader>\ :call ToggleNERDTreeAndTagbar()<CR>
" Allow single click for NERDTree
let NERDTreeMouseMode = 3
let g:NERDTreeWinSize = 30
" autocmd VimEnter * NERDTree
" Tagbar options
let tagbar_singleclick = 1
let g:tagbar_sort = 0
let g:tagbar_width = 30
" autocmd VimEnter * nested TagbarOpen
" The Janus plugin sets this to noequalalways for the Zoominfo plugin
" However, we want to set this to equalalways instead, since we want to
" have equal window height when a new window is opened. i.e. via ctrl+w+s
set equalalways
" Matchit already installed in newer versions of vim.
" Don't need to add this onto pathogen bundle folder. We only need
" to configure it.
" Configure matchit so that it goes from opening tag to closing tag
au FileType html,eruby,rb,css,js,xml runtime! macros/matchit.vim
" Set backup and swp dir. Don't forget to clear tmp dir out once in a while
set backupdir=~/.vim/tmp/backup
set directory=~/.vim/tmp/swp
" Detect if a tab was closed, and ensure that height of main window fills the screen (100% height)
au TabEnter * let &lines = 100
" <leader>\ to open or close NERDTree and Tagbar, under the following conditions:
" 1) Only close both if NERDTree and Tagbar are both opened
" 2) Open both if NERDTree and Tagbar are closed OR if one is already opened
function! ToggleNERDTreeAndTagbar()
let w:jumpbacktohere = 1
" Detect which plugins are open
if exists('t:NERDTreeBufName')
let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
else
let nerdtree_open = 0
endif
let tagbar_open = bufwinnr('__Tagbar__') != -1
" Perform the appropriate action
if nerdtree_open && tagbar_open
NERDTreeClose
TagbarClose
elseif nerdtree_open
TagbarOpen
elseif tagbar_open
NERDTree
else
NERDTree
TagbarOpen
endif
" Jump back to the original window
for window in range(1, winnr('$'))
execute window . 'wincmd w'
if exists('w:jumpbacktohere')
unlet w:jumpbacktohere
break
endif
endfor
endfunction
Since Vim comes shipped with matchit plugin, all I needed to do was activate it:
vim ~/.vimrc
Then add the following into your .vimrc:
set nocompatible
filetype plugin on
runtime macros/matchit.vim
This line
runtime macros/matchit.vim
is the standard way of activating matchit and it works on all my machines.
Does matchit work after you type
:runtime macros/matchit.vim
in normal mode ?
The page of the matchit plugin says:
Make sure you have a line like
:filetype plugin on
in your vimrc file. This enables filetype plugins, many of which tell
matchit.vim which matching pairs to use.
FYI: in vim 8 runtime macros/matchit.vim becomes packadd! matchit.
I started having the same issue after I updated some of my vim plugings to the latest version for 7.3.
But when I run
:MatchDebug
it fixes the issue for me.
I had a problem with matchit finding the correct matching brace in C++/C when there were commented braces. The following steps, taken from this forum post written by this guy, solved it for me and also pretty much explained the way the whole thing works:
Create the folder ~/.vim/plugin if it is not already there:
mkdir ~/.vim/plugin
Create a file with the name
~/.vim/plugin/matchit.vim :
vi ~/.vim/plugin/matchit.vim
and the following contents:
runtime macros/matchit.vim
Create the directory ~/.vim/doc if it is not already there:
mkdir ~/.vim/doc
Copy /usr/share/vim/vim73/macros/matchit.txt to ~/.vim/doc/ :
cp /usr/share/vim/vim73/macros/matchit.txt ~/.vim/doc/
Open vi
vi
and execute the following in it:
:helptags ~/.vim/doc
Make sure that your ~/.vimrc includes one of the following:
source $VIMRUNTIME/vimrc_example.vim
or
runtime vimrc_example.vim
or
filetype plugin on
or
filetype plugin indent on
Add the following autocommand in your vimrc:
" make matchit work on C-like filetypes
" c and cpp are already handled by their ftplugin
au Filetype css,javascript
\ let b:match_words = &matchpairs
Restart Vim.
I've had similar problem. I've tried runtime macros/matchit.vim with VIM-provided script and it didn't work.
So I've downloaded this script in version 1.13.2 from http://www.vim.org/scripts/script.php?script_id=39, unzipped it into ~/vimfiles and it works!

Syntax highlighting in terminal vim but not gVIM

I am currently using VIM in the terminal and have perfect syntax highlighting happening. But then when I try to use gvim no matter what type of file or how many times I type: ":syntax on" I don't get any syntax highlighting. Any ideas anyone?
Thank you.
Here is my .vimrc for those who are interested:
" Turn on pathogen for all plug-ins installed after 9/13/2010
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
" My color theme for vim
colors sorcerer
" Disable line wrapping for now
set nowrap
" Enable the mouse even when vi is used in the terminal
set mouse=a
" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'
" This shows what you are typing as a command. I love this!
set showcmd
" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')
"Fix Vim's regex...
nnoremap / /\v
vnoremap / /\v
" Gimme some breathing room at the bottom please...
set scrolloff=5
" makes vim usable with screen
set restorescreen
" Disable the arrow keys... helps the learning
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
"Kill error bells
set noerrorbells
set visualbell
set t_vb=
" Turn on spell check
" set spell
" Thesaurus!!
set thesaurus+=/usr/share/myspell/dicts/mthesaur.txt
" Some NERDTree love
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
let NERDTreeShowBookmarks=1
let NERDTreeQuitOnOpen=1
let NERDTreeHighlightCursorline=1
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1
" Make swapping windows easier...
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Allow for buffers to be hidden so that they need not be closed to go to
" another file
set hidden
" Turn on incremental search
set incsearch
set smartcase
" Long history is long
set history=1000
set undolevels=1000
" No need for a vi backup file
set nobackup
" Colors!!
set t_Co=256
" Compatibility
set nocompatible
set formatprg=par
" Syntastic!!
let g:syntastic_enable_signs=1
let g:syntastic_auto_loclist=1
let g:syntastic_quiet_warnings=0
" For soft wrapping text
command! -nargs=* Wrap set wrap linebreak nolist
set showbreak=…
" Sandro spacing preferences here
set number
set expandtab
set autoindent
set smartindent
set softtabstop=4
set shiftwidth=4
set shiftround
" Sandro key mapping here
map <F2> :NERDTreeToggle<CR>
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
set showmode "show current mode down the bottom
"Setting the status line...
set statusline=%f "tail of the filename
"display a warning if the file format isn't Unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*
"display a warning if file encoding isn't UTf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*
set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag
"Syntastic!!
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" Auto completion options
set wildmode=list:longest "Change tab completion to be like Bash's
set wildignore=*.o,*.obj,*~,*.swp,*.pyc "Files to ignore on auto complete
"display tabs and trailing spaces
set list
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\•,extends:»,precedes:«,trail:•
let g:pydiction_location='~/.vim/after/ftplugin/pydiction/complete-dict'
set sm
set ai
let java_highlight_all=1
let java_highlight_functions="style"
let java_allow_cpp_keywords=1
set tags=~/.tags
set complete=.,w,b,u,t,i
command W w !sudo tee % > /dev/null
" IMPORTANT: win32 users will need to have 'shell slash' set so that latex
" can be called correctly.
"set shell slash
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
"set grepprg=grep\ -nH\ $*
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
" let g:tex_flavor='latex'
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plug-ins
syntax on
filetype indent on " OPTIONAL: This enables automatic indentation as you type.
" VIM 7.3 features here...
if v:version >= 703
set relativenumber
set undofile
endif
Use :let g:colors_name to see the name of the colourscheme that has been loaded, the value should be 'sorcerer', if it's not then something has gone seriously wrong
Type :hi Operator, you 'xxx' part should be coloured and you should see guifg=<color> in the output.
Put a new line at the top of your .vimrc containing just the word "finish", this will stop vim processing your .vimrc. Using :colors default and :syntax on should be enough to get syntax highlighting turned on. If this works then just move the finish line down through your .vimrc until you find the section that is breaking syntax highlighting.
On windows, gVim uses a file called _vimrc, so check for that as well.
When you type :version in gvim do you see +syntax listed in your features list?
Try comparing that to your regular Vim version. Maybe your gvim build didn't include the syntax highlighting feature.
The issue was fixed once I finally figured out how to get gvim 7.3. Then the syntax highlighting magically came.
Building on Thien's response, I also had the same experience (set syntax=on fails, the menu options succeed but only until Vim is restarted).
The menu option apparently triggers :syn=on, and adding that to _vimrc does enable syntax highlighting persistently where set syntax=on did not. I'll leave it to someone with more experience to explain the difference between those two.
set syntax=xxx was not working for me in gvim 7.3 on Windows XP although it did for vim in cygwin. To get syntax highlighting I had to go to Menu > Syntax > Show filetypes in menu > select syntax. I guess the menu command and the vim commands don't do the same thing with gvim on Windows.

Resources