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
Related
I want to open the taglist window only specifically for the C files
If I put the following command in my .vimrc then the window opens for all the files
let Tlist_Auto_Open=1
However, when I used autocmd based on filetype, it does not open. Is there any kind of dependency that I need to check for ?
autocmd FileType c,cpp,h,py let Tlist_Auto_Open=1
A part of my .vimrc looks like below -
" Install pathogen
execute pathogen#infect()
set number " Display Line Numbers
set autoindent " Auto-indenting
set showmatch " Highlight Matching brackets
set tabstop=4 " Default tabstop value
set shiftwidth=4
set smarttab " Enable smart tab
set hlsearch " highlight searched items
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
" set scrolloff=999 "Start scrolling when we're 8 lines away from margins
" No annoying sound on errors
set noerrorbells
set novisualbell
set timeoutlen=500
filetype plugin on
filetype plugin indent on
set ic
autocmd filetype python set expandtab
" Remove the trailing white-spaces in the C-file
autocmd FileType c,cpp,h,py autocmd BufWritePre <buffer> %s/\s\+$//e
" Unmap the tab-key in the taglist window.
:autocmd BufEnter __Tag_List__ silent! nunmap <buffer> <Tab>
" Syntax higlight for Groovy
au BufRead,BufNewFile *.atc set filetype=groovy
""""""""""""""""""""""""""""""""""
" Taglist configuration
""""""""""""""""""""""""""""""""""
"
" To automatically close the tags tree for inactive files.
" let Tlist_File_Fold_Auto_Close = 1
" Display only one file in taglist.
let Tlist_Show_One_File = 1
" Taglist window size
let Tlist_WinWidth = 30
" Open Taglist by default
autocmd FileType c,cpp,h,py let Tlist_Auto_Open=1
" Close VIM when only taglist window is open
let Tlist_Exit_OnlyWindow = 1
This is a timing problem. The taglist plugin evaluates the Tlist_Auto_Open configuration during its load. At that point in time, your ~/.vimrc has been read, but no file has yet been opened. Your :autocmd only activates after such file has been :edited, and by then, the taglist initialization is over. Also, until you only edit one [type of] file in a Vim session, your approach would have resulted in all subsequent files opening the taglist!
So, you cannot use the taglist-provided config feature, but fortunately it is very easy to implement an automatic triggering of the plugin via the :TlistOpen command. Just modify your autocmd to this:
:autocmd FileType c,cpp,h.py TlistOpen
When I open vim, I have to press the esc key before working w/ what is in the file because it assumes a 'c' was pressed.
It hasn't always been like this but I am unsure how to troubleshoot it.
When I run vim -u NONE or vim --noplugin, it doesn't assume 'c' has been pressed, but when I comment out the last two plugins that I installed (typescript-vim and ag.vim), it does assume 'c' was pressed.
Can anyone see any other setting that might be the culprit?
set t_Co=16
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle.vim
call vundle#begin()
Bundle 'gmarik/vundle.vim'
" vim-snipmate dependencies
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'vim-scripts/tlib'
Plugin 'ToadJamb/vim_test_runner'
Plugin 'garbas/vim-snipmate'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-rake'
Plugin 'tpope/vim-endwise'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-scripts/DeleteTrailingWhitespace'
Plugin 'altercation/vim-colors-solarized'
Plugin 'ervandew/supertab'
Plugin 'kchmck/vim-coffee-script'
Plugin 'slim-template/vim-slim'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-markdown'
Plugin 'vim-scripts/Align'
Plugin 'ToadJamb/vim_alternate_file'
Plugin 'ToadJamb/vim_tab_number'
Plugin 'Keithbsmiley/swift.vim'
Plugin 'vim-multiple-cursors'
Plugin 'leafgarland/typescript-vim'
Plugin 'rking/ag.vim'
call vundle#end()
filetype plugin indent on
" Plugin settings
let g:instant_markdown_autostart = 0
autocmd BufNewFile,BufRead Capfile setf ruby
autocmd BufNewFile,BufRead Gemfile setf ruby
" System-level settings
set noswapfile " Turn off the use of swap files - seems to use them anyway
"set dir='' " Really turn off the use of swap files
" Behavior
set expandtab " Expand tabs to spaces
set tabstop=2 " Set tabs to two spaces (No conversion - just display)
set shiftwidth=2 " Use 2 spaces when shifting with '>' or '<'
set ignorecase " Ignore case in patterns.
set smartcase " Case-sensitive matching for patterns with an uppercase letter
set backspace=2 " Make backspace/delete work in insert mode.
set showcmd " Show current command
" Presentation - always visible
syntax on " Syntax highlighting
set number " Show line numbers in margin
set cursorline " Highlight the line the cursor is on
set fillchars=stl:-,vert:\| " Set the characters used to fill borders
let &stl='%t %([%R%M]%) %L %l,%c ' " Status line format
" Presentation - conditional
set nowrap " Do not wrap text
set hlsearch " Highligh search text
set laststatus=2 " Always show the status bar
set listchars=trail::,tab:-> " How trailing spaces & tabs should be represented (tabstop matters for tab)
set list " Required in order for listchars to work
set colorcolumn=80 " Right margin at 80 characters
" Performance - Primarily for Ruby - Any file around 200 lines has a problem.
" Solution found here:
" http://stackoverflow.com/questions/16902317/vim-slow-with-ruby-syntax-highlighting
"set ttyfast " When playing with these 3 options, this one seemed to have no effect.
"set re=1 " Use the old regex engine (default is 0).
set lazyredraw " Don't redraw the screen for every little thing.
" Features
set foldmethod=indent " Enable folding based on language syntax
set nofoldenable " Open files with all folds expanded
" Toggle folding using the space bar.
nnoremap <silent> <Space> #=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
:let mapleader = ","
" Toggle buffers using leader
map <leader><leader> :b#<cr>
" Enter clears highlighting
nnoremap <cr> :nohlsearch<cr>
" Open alternate files
command AF :execute OpenAlternateFile()
map <silent> <leader>s :call OpenAlternateFile() <CR>
" Run tests
map <silent> <leader>t :call TriggerTest()<CR>
map <silent> <leader>r :call TriggerPreviousTest()<CR>
" Binding for Ag
map <leader>/ :Ag<space>
" Quickfix bindings
map <ENTER> :cn<CR>
" *** No Color Scheme ***
"hi! String ctermfg=00
"hi! LineNr ctermfg=04
"hi! CursorLine ctermfg=none ctermbg=07 cterm=none
" *** Miscellaneous ***
"let g:solarized_termcolors=16 " Local
"let g:solarized_termcolors=256 " Remote
"set background=light
color solarized
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
I have some erb code:
... some code
<%= yield %>
When I try to type <%= in line next to yield one, vim freezes for a second before outputing %, the same with =. When I try it line above yield it outputs all characters without any delay.
I'm not sure, but it looks like it's working this way only in this file.
Any idea what's wrong?
My .vimrc file:
set nocompatible " be iMproved
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 'gmarik/Vundle.vim'
Plugin 'altercation/vim-colors-solarized'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-surround'
Plugin 'flazz/vim-colorschemes'
" 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
" basic settings
syntax enable
set hidden " hide buffer instead of closing it
set number " line numbers
set laststatus=2 " display the status line always
set cursorline " highlight the line of the cursor
" Whitespace
set nowrap " don't wrap lines
set tabstop=2 shiftwidth=2 " a tab is two spaces (or set this to 4)
set expandtab " use spaces, not tabs (optional)
set backspace=indent,eol,start " backspace through everything in insert mode
" set list " display unprintable characters with '^' and put $ after the line
set scrolloff=3 " have some context around the current line always on screen
" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letterset nocompatible
set noswapfile
set clipboard=unnamedplus " alias unnamed register to the + register, which is the X Window clipboard
:nnoremap <CR> :nohlsearch<cr> " clear the search buffer when hitting return
set t_Co=256
set background=dark
colorscheme solarized
"http://askubuntu.com/questions/392573/how-do-i-get-vim-to-indent-all-html-tags
let g:html_indent_inctags = "html,body,head,tbody"
I added set re=1 to my .vimrc and it works much better now.
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!