Vim and Python

Embed Size (px)

Citation preview

  • 1. VIM and Python - Tips and Trickshttp://xkcd.com/378/

2. Getting Aroundh/j/k/lgg and G start/end of buffer^ - first non-blank character in current line$ - last character on current lineCTRL-u / CTRL-d page up / page down:n go to line number n.H/M/L go to first/middle/last line on screen*% - jump to corresponding bracket [] {} () 3. Marksm followed by a letter to set a mark` followed by the letter jump to that mark:marks will list current marksVim has some special marks (a few examples):`. - jump to position where the last change occured`` - jump back to position where you jumped fromlots more found in :help ` 4. Making Changesy/d/c yank/delete/changeY/D/C same as above, but specifies line*p/P paste before/aftercombine with movements:dw delete wordcw change worddG delete from cursor to end of filec`a change from cursor to mark a 5. Making Changesy/d/c yank/delete/changeY/D/C same as above, but specifies line*p/P paste after/beforex/r delete/replace single charactercombine with movements:dw delete wordcw change worddG delete from cursor to end of filec`a change from cursor to mark ause the . character to repeat last command 6. Visual Modev enter visual modeV enter visual mode, but operate on a lineCTRL-v -enter visual mode, operate on a columnUse I to change all columns at oncecombine with y/d/c for even more fun 7. Text Objectsused after an operator or visual modei inner / a ambienta / i operate on block of a( / i( - operate of block of ()a{ / i{ - operate of block of {}at / it operate of html or xml tags 8. Search/ or ? - for a basic search (forward or backward)I recommend :set ignore case, :set smartcase and :set incsearchn to repeat search, or N to repeat in oppositedirection*/# - find next/previous of word under cursor[I list lines with word under cursorset up a map to make this easier::map f [I:let nr = input("Which one:")exe "normal " . nr ."[t" 9. Undosu undo, CTRL-R redosee also: undo-branchestime travel:earlier Ns, m, h:later Ns,m,hCant jump to the future when the code is already done, sorry. Hoping for that feature in Vim 8 10. Splitting Windows:sp -horizontal split:vs vertical split:newCTRL-w + movement to move between windowsI remap spacebar for easier commands 11. Configuration.vimrc global settings.vim directory - plugins, color schemes, syntaxdefinitions, etcbrowse github for ideas, or just fork one you like:set see your current settingsdont be afraid to consult :help to see what things do 12. Config Examplesfiltype plugin on recoginize .py as pythonfiltype indent on proper indentation (more on this later)set nu turn line numbers onset ruler see where you are in the fileset t_Co=256 256 colorscmap w!! %!sudo tee > /dev/null %made changes to a read-only file? This mapping allows you to use :w!! to save using sudo 13. More Config Examplesau BufReadPost * if line(""") > 0 && line(""")