Table of Contents
Eclipse Plugin
Available at market place.
1. vimrc
Vim shortcuts
- Tricks (also spell checking) http://xpressrazor.wordpress.com/2014/03/10/few-vim-tricks/
Diff opening windows
in each of the windows you want to diff type:
:diffthis
If you want to diff all of the open windows, you can do:
:windo diffthis
(windo will apply the command to all open windows)
To end diff mode:
:diffoff!
The ! makes diffoff apply to all windows of the current tab
Close buffer wo closing window
:b#|bd#
Upper case all input
- ctrl+V visual mode.
- multiple j to extend Visual mode to multiple line.
- g+U to make selection upper case.
v`[U * v: visual mode * '[: move from current position to last edited text. * U: make Uppercase
Multiline editting
Insert to same position in multiple lines:
- ctrl+V visual mode.
- multiple j to extend Visual mode to multiple line.
- I to insert mode in visual mode.
- ESC et voila!
Delete a rectangular area spanning over lines.
ctr+V --> select aread with hjkl --> X to delete.
Spell checking
Add following to your ~/.vimrc (add the language accordingly) your .vimrc.
set spelllang=en set spellfile=$HOME/Dropbox/vim/spell/en.utf-8.add
Activate spell:
:setlocal spell spelllang=en_us
Key mapping:
imap <F3> <C-o>:setlocal spell! spelllang=en_us<CR> nmap <F3> :setlocal spell! spelllang=en_us<CR>
After this, you can edit your text document are ready to see all your typing error press F3 (if you don’t mind errors while editing, you can use this key earlier too). Here are few commands, you can use to spell check.
z=: suggest words ]s, [s = jump to next, previous misspelled word zg: Add a word to the dictionary zw: Mark a word as incorrect
Spell check per filetype
It would be tedious to manually turn on spell-checking each time we need it. Luckily, we can guess by convention that we'll want to spell-check certain files.
We automatically turn on spell-checking for Markdown files based on their file extension with this line in our ~/.vimrc via thoughtbot/dotfiles:
autocmd BufRead,BufNewFile *.md setlocal spell
Another way to do it for certain filetypes is like this:
autocmd FileType gitcommit setlocal spell
Exclude words
syn match myExCapitalWords +\<\w*[A-Z]\K*\>\|'s+ contains=@NoSpell :h spell-syntax for more information. * http://tex.stackexchange.com/questions/9303/in-vim-how-to-enable-spellchecking-of-text-only-and-exclude-listings
Here are some more general spell-checking exception rules to put in .vim/after/syntax/{LANG}.vim files:
" Disable spell-checking of bizarre words:
" - Mixed alpha / numeric
" - Mixed case (starting upper) / All upper
" - Mixed case (starting lower)
" - Contains strange character
syn match spellingException "\<\w*\d[\d\w]*\>" transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\<\(\u\l*\)\{2,}\>" transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\<\(\l\+\u\+\)\+\l*\>" transparent contained containedin=pythonComment,python.*String contains=@NoSpell
syn match spellingException "\S*[/\\_`]\S*" transparent contained containedin=pythonComment,python.*String contains=@NoSpell
Change pythonComment,python.*String for your language.
- transparent means that the match inherits its highlighting properties from the containing block (i.e. these rules do not change the way text is displayed).
- contained prevents these matches from extending past the containing block (the last rule ends with \S* which would likely match past the end of a block)
- containedin holds a list of existing syntax groups to add these new rules to.
- contains=@NoSpell overrides any and all inherited groups, thus telling the spellchecker to skip the matched text.
tex.vim
cp tex.vim ~/.vim/after/ftplugin/
Download http://michaelgoerz.net/blog/2008/03/vim-syntax-file-for-tex/ and copy to ~/.vim/syntax/
Search & Replace
Basic search & replace
:%s/foo/bar/g
Find each occurrence of 'foo', and replace it with 'bar'.
:%s/foo/bar/gc
Change each 'foo' to 'bar', but ask for confirmation first.
:%s/\<foo\>/bar/gc
Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.
:%s/foo/bar/gci
Change each 'foo' (case insensitive) to 'bar'; ask for confirmation.
This may be wanted after using :set noignorecase to make searches case sensitive (the default).
:%s/foo/bar/gcI
Change each 'foo' (case sensitive) to 'bar'; ask for confirmation.
This may be wanted after using :set ignorecase to make searches case insensitive.
Search range
:s/foo/bar/g Change each 'foo' to 'bar' in the current line.
:%s/foo/bar/g Change each 'foo' to 'bar' in all lines.
:5,12s/foo/bar/g Change each 'foo' to 'bar' for all lines from line 5 to line 12 inclusive.
:'a,'bs/foo/bar/g Change each 'foo' to 'bar' for all lines from mark a to mark b inclusive.
:.,$s/foo/bar/g Change each 'foo' to 'bar' for all lines from the current line (.) to the last line ($) inclusive.
:.,+2s/foo/bar/g Change each 'foo' to 'bar' for the current line (.) and the two next lines (+2).
:%s/foo/bar/g Equivalent to :1,$s/foo/bar/g (change all lines).
:g/^baz/s/foo/bar/g Change each 'foo' to 'bar' in each line starting with 'baz'.
others
When searching:
., *, \, [, ], ^, and $ are metacharacters.
+, ?, |, {, }, (, and ) must be escaped to use their special function.
\/ is / (use backslash + forward slash to search for forward slash)
\t is tab, \s is whitespace
\n is newline, \r is CR (carriage return = Ctrl-M = ^M)
\{#\} is used for repetition. /foo.\{2\} will match foo and the two following characters. The \ is not required on the closing } so /foo.\{2} will do the same thing.
\(foo\) makes a backreference to foo. Parenthesis without escapes are literally matched. Here the \ is required for the closing \).
When replacing:
\r is newline, \n is a null byte (0x00). \& is ampersand (& is the text that matches the search pattern). \1 inserts the text of the first backreference. \2 inserts the second backreference, and so on.
Search visually selected text
put this line in your vimrc:
vnoremap // y/<C-R>"<CR>
The :vnoremap command maps \/\/ in visual mode to run the commands y/<C-R>“<CR> which copies the visually selected text, then starts a search command and pastes the copied text into the search. <C-R> represents Ctrl-R and <CR> represents carriage return (Enter).
To create this mapping for just one session, enter the following command (:vn is an abbreviation for :vnoremap):
:vn // y/<C-R>"<CR>
To use the mapping, visually select the characters that are wanted in the search, then type \/\/ to search for next occurrence of the selected text. Then press n to search for the next occurrence.
2. Folding
zf#j : fold from current line to 2 lines down.
select block of text with v-V then zf
zfa+} zfa+ {],>,etc.} :auto fold block
3. tbd
Folding html tag
I have found "zfat" (or, equally, "zfit") works well for folding with HTML documents. "za" will toggle (open or close) an existing fold. "zR" opens all the folds in the current document, "zM" effectively re-enables all existing folds marked in the document.
zf#j creates a fold from the cursor down # lines.
zf/string creates a fold from the cursor to string .
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero – all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.
Windows
open windows
:split filename :vsplit filename
Navigation
ctrl W = equal size :res -N ctrl W - reduce height by N :res +N ctrl W + increase height by N ctrl W _ ctrl W < decrease window width by N (default 1) ctrl W > increase window width by N (default 1)
Move window
CTRL-W r CTRL-W CTRL-R
CTRL-W R
CTRL-W x CTRL-W CTRL-X
CTRL-W K H J L move window l r u d
CTRL-W T move window to new tab
Close buffer without closing window
Open the buffer to be closed:
:b#|bd#
Tabs
Open tab
:tabedit filename
Navigation
:tabn(ext) gt #goto next tab. :tabp(rev) gT #goto previous tab.
General Navigation
Using marks
To jump to a mark enter an apostrophe (<tt>'</tt>) or backtick <tt>()</tt> followed by a letter. Using an apostrophe jumps to the beginning of the line holding the mark, while a backtick jumps to the line and column of the mark.
Using a lowercase letter (for example <tt>a</tt>) will only work if that mark exists in the current buffer. Using an uppercase letter (for example <tt>A</tt>) will jump to the file and the position holding the mark (you do not need to open the file prior to jumping to the mark).
*Each file can have mark '''a''' – use a lowercase mark to jump within a file.
*There is only one file mark '''A''' – use an uppercase mark to jump between files.
<code>
| ma || set mark '''a''' at current cursor location
|-
| 'a || jump to line of mark '''a''' (first non-blank character in line)
|-
| a || jump to position (line and column) of mark 'a'
| d'a | |
da || delete from current cursor position to position of mark '''a'''
|-
| c'a || change text from current line to line of mark '''a'''
|-
| ya |
|
| marks | |
| marks aB | |
</code>
Commands like <tt>d'a</tt> operate “linewise” and include the start and end lines.<br>
Commands like <tt>da</tt> operate "characterwise" and include the start but not the end character.
It is possible to navigate between lowercase marks:
{| class="wikitable"
!Command !! Description
|-
| <tt>]'</tt> || jump to next line with a lowercase mark
|-
| <tt>['</tt> || jump to previous line with a lowercase mark
|-
| <tt>]</tt> || jump to next lowercase mark
Special marks
Vim has some special marks which it sets automatically. Here are some of the most useful:
{| class=“wikitable” !Command !! Description
<tt>.</tt> || jump to position where last change occurred in current buffer
|-
| <tt>”</tt> |
|
<tt>0</tt> || jump to position in last file edited (when exited Vim)
|-
| <tt>1</tt> |
|
| <tt>''</tt> | |
| <tt>``</tt> | |
<tt>[</tt> or <tt>]</tt> |
|
<tt><</tt> or <tt>></tt> |
|
See the full list at '[ and following.
Paths
Buffer Path
%:p full path to buffer. %:p:h parent directory of buffer.
In Action: show content of parent dir of current buffer.
:!ls %:p:h
Tab(edit)
- convert tabs to spaces (useful for python programming)
:set tabstop=2 shiftwidth=2 expandtab or :set expandtab :retab ... works for current buffer...
Indenting XML
in .vimrc add:
au FileType xml exe ":silent 1,$!tidy --input-xml true --indent yes 2>/dev/null"
Usage:
gg=G ==