I'm using Vim with Syntastic and JSHint, and there are a few bits of glitchy behavior that I'd like to fix.
Whenever I modify the last character on a line of text and save (:w), I momentarily see "^M" flash after the text before (sometimes) vanishing. Sometimes it sticks around and I have to manually delete it. What's the deal with this and how do I prevent it?
When there is an error in the quickfix view, how do I toggle focus between the quickfix view and the Vim editor window?
Vim crashes maybe once per minute, and I haven't the slightest clue as to why, but it's extremely annoying. The error typically reads "Vim: Caught deadly signal ABRT Vim: Finished. [1]6099 abort vi gulpfile.js" How do I prevent this?
Here is my .vimrc file:
set nocompatible " be iMproved, required
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')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
"Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Avoid a name conflict with L9
"Plugin 'user/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" React.js/JSX syntax highlighting
"Plugin 'mxw/vim-jsx'
"
"JSHint
Plugin 'wookiehangover/jshint.vim'
"Syntastic
Plugin 'scrooloose/syntastic'
"Syntastic configuration
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_html_tidy_exec = 'tidy5'
let g:syntastic_javascript_checkers = ['jshint']
let g:JSHintHighlightErrorLine = 0
syntax on
set t_Co=256
set ai
set shiftwidth=4
set tabstop=4
set number
"colorscheme monokai
colorscheme skittles_berry
Thanks for any help you can provide.
I have no idea where your ^M issue and your crashing issue come from but you don't need such a huge plugin for such a simple task.
Create ~/.vim/after/ftplugin/javascript.vim if it doesn't exist and paste the lines below:
errorformat for jshint
setlocal errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m,%-G%.%#
tell Vim to use jshint for the :make command
setlocal makeprg=jshint
add an autocommand to run :make on the current file upon write, the | silent wincmd p at the end switches the focus back to the editing window once the quickfix window is opened
autocmd! BufWritePost <buffer> silent make % | silent redraw! | silent wincmd p
I've never experienced a single crash with that simple setup, or that ^M issue.
With that in place you should get something like that after :w:
To move the focus from/to the quickfix window, use <C-w>p.
To jump to the previous/next error without using the quickfix window, use :cprevious/:cnext.
Reference:
:help 'errorformat'
:help 'makeprg'
:help autocmd
:help bufwritepost
:help :silent
:help :redraw
:help :wincmd
:help quickfix
Also, check out this great post: The Power of Vim
Related
I recently activated auto-complete and syntax color in Vim. However, a red highlighting color appeared.
I tried to disable syntax color with syntax off, but this highlighting color is still there.
Here's my ~/.vimrc
syntax on
set nocompatible " be iMproved, required
filetype on " 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')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'ycm-core/YouCompleteMe'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
:set number
It's hard to see my code with color highlights. I want to keep the syntax color, but without the highlighting. I couldn't find the setting in ~/.vimrc. How do I disable this ?
Apparently, this is from auto-completion. As mentioned in YouCompleteMe github about Diagnostic UI,
This turns on YCM's diagnostic display features including like the gutter signs, text highlighting, diagnostic echo and auto location list population. To disable this, I put :
let g:ycm_show_diagnostics_ui = 1
and the highlights are gone.
Have you tried googling first? Highlighting can be turned off easily with :noh, alternatively you can use :let #/="", as mentioned here, one of the first google search results... You can map these commands to some shortcuts in your .vimrc (I personally use ,/ combination to disable highlighting)
:noh command does not affect syntax colouring. Is this what you need?
EDIT:
I am sorry, I didn't see the pictures, as they are blocked on network I am currently connected to. This looks more like the syntax check. Try :set nospell instead :)
I have the following problem with Vim: When I open a file, I can't delete any char/word if I'm in insert mode except what was not already written before opening the file.
In normal mode, every word/char delete command like x or dw work.
My .vimrc:
" Vundle configuration
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" ck the engine.
Plugin 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plugin 'honza/vim-snippets'
" colorsheme theme
Bundle 'altercation/vim-colors-solarized'
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<S-tab>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
set history=100
set number
set tabstop=3
set expandtab "use space instead of tab
set shiftwidth=3 "number of space char inserted for identation
syntax on
set background=dark
let g:solarized_termcolors = 256
colorscheme solarized
"Build Latex
autocmd FileType tex setlocal makeprg=pdflatex\ --shell-escape\ '%'
function CompileXeTex()
let oldCompileRule=g:Tex_CompileRule_pdf
let g:Tex_CompileRule_pdf = 'xelatex -aux-directory=F:/Vim/my_latex_doc/temp --synctex=-1 -src-specials -interaction=nonstopmode $*'
call Tex_RunLaTeX()
let g:Tex_CompileRule_pdf=oldCompileRule
endfunction
map <Leader>lx :<C-U>call CompileXeTex()<CR>
" Use fd as escape
:imap fd <Esc>
Thank you in advance for your help.
From Vim help manual, backspace default is "":
When the value is empty, Vi compatible backspacing is used.
Vi compatible backspacing works like <Left>. So set backspace:
" set the backspace to delete normally
set backspace=indent,eol,start
VIM starts with a message "Press ENTER or type command to continue", it happens for VIM, but not GVIM, GVIM starts without showing "Press ENTER or type command to continue”.
The Vundle settings in my .vimrc file, OS is windows 7.
"""""""""""""""""""""""""""Vundle start"""""""""""""""""""""""""""""""""
" set the runtime path to include Vundle and initialize
set rtp+=C:/Users/penpan/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Avoid a name conflict with L9
Plugin 'user/L9', {'name': 'newL9'}
"NERDTree
Plugin 'https://github.com/scrooloose/nerdtree.git'
"color scheme molokai
Plugin 'tomasr/molokai'
"Match Tag
Plugin 'Valloric/MatchTagAlways'
"ctags
Plugin 'szw/vim-tags'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
""""""""""""""""""""""""""""End Vundle"""""""""""""""""""""""""""""""""
I comment this line:
call vundle#end() " required
Then it is ok! VIM starts without showing press enter prompt. so I believe this call makes the prompt happening. I add silent! in front of it as below:
silent! call vundle#end()
but no use, VIM still show the prompt.
and add below in .vimrc:
set shortmess+=T
set cmdheight=2
does not work.
I tried to find answer in google, fine many suggestions, but none of them work :(
Vundle is a common plugin, has anyone have the same question with me?
Appreciate if you can help.
only if I remove below, the press enter prompt disappears:
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
""""""""""""""""""""""""""""End Vundle"""""""""""""""""""""""""""""""""
colorscheme molokai "because molokai is installed by Vundle, so it only work after Vundle is lunched!
=================================fixed====================================
after I remove plugin MatchTagAlways in vundle config, issue fixed.below is the steps I find the issue:
firstly, you need to know what config area cause the issue, for me, it is the config of Vundle.
add :redraw! after call vundle#begin() and call vundle#end()
open vim, it will show the error message above the press enter message
before:
Press ENTER or type command to continue
after:
MatchTagAlways unavailable: requires python.
Press ENTER or type command to continue
now we get the root cause. fix it, or remove the plugin.
ps: gvim has +python3/dyn support, but vim haven't. so vim have the error if plugin MatchTagAlways installed.
set shortmess=a in your .vimrc should stop that.
This wiki appears to be the authority on the issue:
http://vim.wikia.com/wiki/Avoiding_the_%22Hit_ENTER_to_continue%22_prompts
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
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!