Vim inoremap for specific filetypes

You need to do 2 things: create a mapping local to a specific buffer by using the <buffer> option for inoremap. load the mappings for just a specific filetype. This can be done via an autocommand in your .vimrc like so: autocmd FileType php inoremap <buffer> ( ()<Esc>i The other way option is by creating … Read more

Remove everything except regex match in Vim

This effect can be accomplished by using sub-replace-special substitution and setreg() linewise :let @a=”” :%s//\=setreg(‘A’, submatch(0), ‘l’)/g :%d _ :pu a :0d _ or all in one line as such: :let @a=””|%s//\=setreg(‘A’, submatch(0), ‘l’)/g|%d _|pu a|0d _ Overview: Using a substitution to append each match into register “a” linewise then replace the entire buffer with … Read more

Mapping in vimrc causes bizarre arrow behaviour

The mapping nnoremap <esc> :noh<return><esc> will conflict with so called “grey keys” and I believe that it should be used either in GVim only or in terminal Vim by someone who does not use special keys like arrows. From what I know (and guess) how Vim processes keys, I would say that it’s impossible to … Read more

Why does vim not obey my expandtab in python files?

The problem is that your settings are being overridden by a filetype plugin that’s part of Vim. The issue is in ftplugin/python.vim: ” As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 The python plugin attempts to setup your source code to be PEP8 compliant by default, so it’s adjusting the tabstop. You’ll want some … Read more

How to do JSLint in Vim

The best-practice way IMO is: Install Syntastic Vim plugin – Best syntax-checker around for plenty of languages, plus it integrates with Vim’s location-list (==quickfix) window. I recommend cloning from the GitHub repo and installing using a plugin manager like Vundle or Pathogen, since it’s more frequently updated. Choose one of the two options below: JSLint … Read more

What is in your .vimrc? [closed]

You asked for it 🙂 “{{{Auto Commands ” Automatically cd into the directory that the file is in autocmd BufEnter * execute “chdir “.escape(expand(“%:p:h”), ‘ ‘) ” Remove any trailing whitespace that is in the file autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif ” Restore cursor position to where it was … Read more

tech