What is the easiest way to swap occurrences of two strings in Vim?

I’d do it like this: :%s/\v(foo|bar)/\={‘foo’:’bar’,’bar’:’foo’}[submatch(0)]/g But that’s too much typing, so I’d do this: function! Mirror(dict) for [key, value] in items(a:dict) let a:dict[value] = key endfor return a:dict endfunction function! S(number) return submatch(a:number) endfunction :%s/\v(foo|bar)/\=Mirror({‘foo’:’bar’})[S(0)]/g But that still requires typing foo and bar twice, so I’d do something like this: function! SwapWords(dict, …) let … Read more

What are the vim commands that start with g?

Vim’s documentation is http://vimdoc.sourceforge.net/. If you go for the HTML docs, you will find |reference_toc| More detailed information for all commands, which includes |index.txt| alphabetical index of all commands, which — due to an unfortunate quirk with the doc file named index.txt and linked as index.html — doesn’t actually lead to where you would expect … Read more

Move adjacent tab to split?

The problem with your problem is that a tab is not tied to a specific buffer. You can have 10 windows with as many buffers in a tab so “moving a tab into a split” doesn’t make much sense. What makes more sense is “show buffer x into a split” which can be done with … Read more

What’s the meaning of ‘inoremap’ in vimrc

For more on why the command has such a bizarre name see this excellent description between the difference between map and noremap. Really good to know! To summarise that article, here’s a choice quote: One downside of the *map commands is the danger of recursing… Vim offers another set of mapping commands that will not … Read more

How to configure Syntastic with JSHint?

Here is a more updated info, there is a configuration to associate a file extension to a checker, in your .vimrc let g:syntastic_javascript_checkers = [‘jshint’] Also to get info about what’s going on run this command in vim :SyntasticInfo And you’ll get an output similar to this: Syntastic info for filetype: javascript Available checkers: gjslint … Read more