SlideShare a Scribd company logo
VIM and Python - Tips and Tricks




                          http://xkcd.com/378/
Getting Around

h/j/k/l
gg and G – start/end of buffer
^ - first non-blank character in current line
$ - last character on current line
CTRL-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 [] {} ()
Marks

m followed by a letter to set a mark
` followed by the letter – jump to that mark
:marks will list current marks
Vim has some special marks (a few examples):
  `. - jump to position where the last change occured
  `` - jump back to position where you jumped from
lots more found in :help `
Making Changes

y/d/c – yank/delete/change
Y/D/C – same as above, but specifies line*
p/P – paste before/after
combine with movements:
  dw – delete word
  cw – change word
  dG – delete from cursor to end of file
  c`a – change from cursor to mark a
Making Changes
y/d/c – yank/delete/change
Y/D/C – same as above, but specifies line*
p/P – paste after/before
x/r – delete/replace single character
combine with movements:
  dw – delete word
  cw – change word
  dG – delete from cursor to end of file
  c`a – change from cursor to mark a
use the . character to repeat last command
Visual Mode

v – enter visual mode
V – enter visual mode, but operate on a line
CTRL-v -enter visual mode, operate on a column
  Use I to change all columns at once
combine with y/d/c for even more fun
Text Objects

used after an operator or visual mode
i – inner / a – ambient
  a' / 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
Search

/ or ? - for a basic search (forward or backward)
  I recommend :set ignore case, :set smartcase and
     :set incsearch
  n to repeat search, or N to repeat in opposite
    direction
*/# - find next/previous of word under cursor
[I – list lines with word under cursor
  set up a map to make this easier:
  :map <space>f [I:let nr = input("Which one:
    ")<Bar>exe "normal " . nr ."[t"<CR>
Undos

u – undo, CTRL-R – redo
see also: undo-branches
time travel
  :earlier Ns, m, h
  :later Ns,m,h
  Can't jump to the future when the code is already
   done, sorry. Hoping for that feature in Vim 8
Splitting Windows

:sp -horizontal split
:vs – vertical split
:new
CTRL-w + movement to move between windows
I remap spacebar for easier commands
Configuration

.vimrc – global settings
.vim directory - plugins, color schemes, syntax
  definitions, etc
browse github for ideas, or just fork one you like
:set – see your current settings
don't be afraid to consult :help to see what things
 do
Config Examples

filtype plugin on – recoginize .py as python
filtype indent on – proper indentation (more on
   this later)
set nu – turn line numbers on
set ruler – see where you are in the file
set t_Co=256 – 256 colors
cmap w!! %!sudo tee > /dev/null %
  made changes to a read-only file? This mapping
   allows you to use :w!! to save using sudo
More Config Examples

au BufReadPost * if line("'"") > 0 && line("'"") <=
 line("$")|execute("normal `"")|endif
  jumps cursor to last edited position on file open
set pastetoggle=<F10>
  easy way to shift to paste mode to not screw up
   indentation
nmap <silent> <F6> :set number!<CR>
  turn line numbers on/off
set iskeyword-=-
  use dash as a word seperator
Indentation

My biggest hang-up when I started with python
Found a python indent file that works pretty well
  Found in .vim/after/indent/
  Autoindents/unindents around keywords
Various other indent definitions available
 (djangohtml is another I use)
= command will re-indent
use > and < to indent keys
Autocomplete

<tab> invokes autocomplete
  Use options wildmode and wildmenu to change how
   this works (I use list:longest,full)
Also work on filenames/directories (:e <tab>)
There are other forms of autocomplete:
  Omnicomplete – Heuristics based completion, I
   haven't had much luck
  pydiction plugin – keyword/modules
tags

I map F4 to rebuild tags file using ctags
CTRL-] - jump to tag under cursor
CTRL-T – return to where you came from
:tag <tagname> - jump to a tag
If there are multiple matches, you select from a
   list
taglist is another useful plugin to view the tags in
  the current file
NERDtree

Popular file explorer
Opens in a new window, which can be re-sized
 and customised
Supports bookmarks
I prefer to just use :e + <tab>
SelectBuf


Similar to a file explorer, but limited to buffers
  already open
A must-have if you normally operate many
 buffers at once
flake-8

wrapper for flake8 (must install seperately)
  PyFlakes
  PEP8
  complexity checker
Can configure to ignore errors
I map to F5, as I also use makeprg for other
  languages using the same key
Doxygen

Generate comment skeletons
  :DoxLic - License
  :DoxAuth - Author
  :Dox - function/class block headers
  Works well out of the box, but config options available
Other Plugins to Check Out

vimpdb
commandT
project
vcscommand
OScan
snippets
netrw
scratch
Resources

http://www.tuxfiles.org/linuxhelp/vimcheat.html
http://www.vim.org/scripts/index.php
http://www.pixelbeat.org/vim.tips.html
http://www.catswhocode.com/blog/100-vim-command
http://www.reddit.com/r/vim/

More Related Content

PDF
Open source projects with python
PPTX
How to deliver a Python project
PPTX
Go. Why it goes
PPTX
Go Programming Language (Golang)
PDF
Golang
PDF
10 reasons to be excited about go
PPT
Go lang introduction
PDF
Introduction to Programming in Go
Open source projects with python
How to deliver a Python project
Go. Why it goes
Go Programming Language (Golang)
Golang
10 reasons to be excited about go
Go lang introduction
Introduction to Programming in Go

What's hot (20)

PPTX
The GO Language : From Beginners to Gophers
PDF
Writing multi-language documentation using Sphinx
PDF
Introduction to go language programming
PDF
A Python Tutorial
PDF
Go. why it goes v2
PDF
PyCon Taiwan 2013 Tutorial
PDF
Happy Go Programming Part 1
PDF
Introduction to Clime
PDF
Dive into Pinkoi 2013
PDF
Learning Python from Data
PDF
A Look at Command Line Swift
PDF
Practicing Python 3
PDF
Fluentd Hacking Guide at RubyKaigi 2014
PDF
System Programming and Administration
PDF
Debugging concurrency programs in go
PDF
Learning Git with Workflows
PPT
Practical Example of grep command in unix
PDF
Python debugging techniques
PDF
Building robust and friendly command line applications in go
PPTX
Python Programming Essentials - M25 - os and sys modules
The GO Language : From Beginners to Gophers
Writing multi-language documentation using Sphinx
Introduction to go language programming
A Python Tutorial
Go. why it goes v2
PyCon Taiwan 2013 Tutorial
Happy Go Programming Part 1
Introduction to Clime
Dive into Pinkoi 2013
Learning Python from Data
A Look at Command Line Swift
Practicing Python 3
Fluentd Hacking Guide at RubyKaigi 2014
System Programming and Administration
Debugging concurrency programs in go
Learning Git with Workflows
Practical Example of grep command in unix
Python debugging techniques
Building robust and friendly command line applications in go
Python Programming Essentials - M25 - os and sys modules
Ad

Viewers also liked (17)

PDF
06 chapter 1
PPTX
Evaluación de centros educativos
PDF
الكتاب المقدس العهد الجديد - رسالة بطرس الرسول الاولى
PPTX
Los espiritus del bosque
PDF
Slides day two
PPTX
Facebook
PDF
The sacrament of penance
PPTX
SCCE Processors and GDPR
DOCX
Financial & mgt. accounting
PPT
Ack prez mlrng
PDF
Taiwan (2016)
PDF
Inv pres q22014_-_final
PDF
M2M Framework December 2012
PPTX
Ciri-ciri Ikan Hiasan
PPTX
Ag 1 source-FWAA
PPTX
Later People of the Fertile Crescent
PPTX
iEnglish workshop 4
06 chapter 1
Evaluación de centros educativos
الكتاب المقدس العهد الجديد - رسالة بطرس الرسول الاولى
Los espiritus del bosque
Slides day two
Facebook
The sacrament of penance
SCCE Processors and GDPR
Financial & mgt. accounting
Ack prez mlrng
Taiwan (2016)
Inv pres q22014_-_final
M2M Framework December 2012
Ciri-ciri Ikan Hiasan
Ag 1 source-FWAA
Later People of the Fertile Crescent
iEnglish workshop 4
Ad

Similar to Vim and Python (20)

PDF
VIM for Programmers
PDF
Tuffarsi in vim
KEY
VIM for the PHP Developer
PDF
PDF
Vim For Php
PPT
PDF
VIM for (PHP) Programmers
PDF
Mission vim possible-full
PPTX
Presentacion vim
PDF
Vim Cheat Sheet.pdf
PPTX
andrew's guide to vim
PDF
PPTX
Vi editor
PDF
Vi reference
PDF
Vi reference
KEY
Vim week
PPT
VI Editors
PDF
Rubizza #1 | Special Lecture. Vim
PDF
3.8.a how to - vim course book
PDF
101 3.8.1 vim course book
VIM for Programmers
Tuffarsi in vim
VIM for the PHP Developer
Vim For Php
VIM for (PHP) Programmers
Mission vim possible-full
Presentacion vim
Vim Cheat Sheet.pdf
andrew's guide to vim
Vi editor
Vi reference
Vi reference
Vim week
VI Editors
Rubizza #1 | Special Lecture. Vim
3.8.a how to - vim course book
101 3.8.1 vim course book

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Electronic commerce courselecture one. Pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Monthly Chronicles - July 2025
MYSQL Presentation for SQL database connectivity
Electronic commerce courselecture one. Pdf
Modernizing your data center with Dell and AMD
Advanced methodologies resolving dimensionality complications for autism neur...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation

Vim and Python

  • 1. VIM and Python - Tips and Tricks http://xkcd.com/378/
  • 2. Getting Around h/j/k/l gg and G – start/end of buffer ^ - first non-blank character in current line $ - last character on current line CTRL-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. Marks m followed by a letter to set a mark ` followed by the letter – jump to that mark :marks will list current marks Vim has some special marks (a few examples): `. - jump to position where the last change occured `` - jump back to position where you jumped from lots more found in :help `
  • 4. Making Changes y/d/c – yank/delete/change Y/D/C – same as above, but specifies line* p/P – paste before/after combine with movements: dw – delete word cw – change word dG – delete from cursor to end of file c`a – change from cursor to mark a
  • 5. Making Changes y/d/c – yank/delete/change Y/D/C – same as above, but specifies line* p/P – paste after/before x/r – delete/replace single character combine with movements: dw – delete word cw – change word dG – delete from cursor to end of file c`a – change from cursor to mark a use the . character to repeat last command
  • 6. Visual Mode v – enter visual mode V – enter visual mode, but operate on a line CTRL-v -enter visual mode, operate on a column Use I to change all columns at once combine with y/d/c for even more fun
  • 7. Text Objects used after an operator or visual mode i – inner / a – ambient a' / 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 incsearch n to repeat search, or N to repeat in opposite direction */# - find next/previous of word under cursor [I – list lines with word under cursor set up a map to make this easier: :map <space>f [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[t"<CR>
  • 9. Undos u – undo, CTRL-R – redo see also: undo-branches time travel :earlier Ns, m, h :later Ns,m,h Can't 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 :new CTRL-w + movement to move between windows I remap spacebar for easier commands
  • 11. Configuration .vimrc – global settings .vim directory - plugins, color schemes, syntax definitions, etc browse github for ideas, or just fork one you like :set – see your current settings don't be afraid to consult :help to see what things do
  • 12. Config Examples filtype plugin on – recoginize .py as python filtype indent on – proper indentation (more on this later) set nu – turn line numbers on set ruler – see where you are in the file set t_Co=256 – 256 colors cmap 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 Examples au BufReadPost * if line("'"") > 0 && line("'"") <= line("$")|execute("normal `"")|endif jumps cursor to last edited position on file open set pastetoggle=<F10> easy way to shift to paste mode to not screw up indentation nmap <silent> <F6> :set number!<CR> turn line numbers on/off set iskeyword-=- use dash as a word seperator
  • 14. Indentation My biggest hang-up when I started with python Found a python indent file that works pretty well Found in .vim/after/indent/ Autoindents/unindents around keywords Various other indent definitions available (djangohtml is another I use) = command will re-indent use > and < to indent keys
  • 15. Autocomplete <tab> invokes autocomplete Use options wildmode and wildmenu to change how this works (I use list:longest,full) Also work on filenames/directories (:e <tab>) There are other forms of autocomplete: Omnicomplete – Heuristics based completion, I haven't had much luck pydiction plugin – keyword/modules
  • 16. tags I map F4 to rebuild tags file using ctags CTRL-] - jump to tag under cursor CTRL-T – return to where you came from :tag <tagname> - jump to a tag If there are multiple matches, you select from a list taglist is another useful plugin to view the tags in the current file
  • 17. NERDtree Popular file explorer Opens in a new window, which can be re-sized and customised Supports bookmarks I prefer to just use :e + <tab>
  • 18. SelectBuf Similar to a file explorer, but limited to buffers already open A must-have if you normally operate many buffers at once
  • 19. flake-8 wrapper for flake8 (must install seperately) PyFlakes PEP8 complexity checker Can configure to ignore errors I map to F5, as I also use makeprg for other languages using the same key
  • 20. Doxygen Generate comment skeletons :DoxLic - License :DoxAuth - Author :Dox - function/class block headers Works well out of the box, but config options available
  • 21. Other Plugins to Check Out vimpdb commandT project vcscommand OScan snippets netrw scratch