Skip to content

Instantly share code, notes, and snippets.

@darcyparker
Created December 7, 2011 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darcyparker/1441318 to your computer and use it in GitHub Desktop.
Save darcyparker/1441318 to your computer and use it in GitHub Desktop.
Boston Vim Meetup December 5, 2011 Talk Notes
Boston Vim Meetup December 5, 2011
----------------------------------
Title : Harmonizing your text editing and shell work in vim
Speaker : Darcy Parker
github : @darcyparker
gmail : darcyparker at gmail.com
( Friendly reminder for new users when reading this in Vim:
:help fold-commands
:set foldmethod=marker
then use zo and zc to open and close the folds respectively... )
Overview Short Description: {{{
Editing text is an important piece of work that we
do. But we also need to efficiently interact with other tools outside
our favourite text editor, vim. In this talk I will survey and
compare different methods for integrating your text editing work
inside vim with other types of tools you may use in your daily work. }}}
A little more detail for the overview... {{{
- Common use cases involving OOTB shell functionality built into vim
- Running a terminal inside a vim buffer using the ConqueTerm plugin
- Running vim and other tools inside a terminal multiplexer
such as tmux or screen
- Specialized integrations with plugins like Fugitive (for git) and
Syntastic (for checking syntax and code standards) }}}
Talk Notes: {{{
Vim OOTB shell related functionality{{{
! filter {{{
variants for ex and vi modes
filter command ! in ex mode: {{{
:!command
:!wc %
:n,m!command //lines n to m
:'a,'b!command //mark a to mark b
:%!command //current buffer
:r !command //reads result of command and inserts it
:.!command //like above, but inserts in current line
}}}
filter operator ! in vi/vim: {{{
!<motion>command
!!command //current line
n!!command
}}}
Some example commands to try with !: {{{
sort // usually prefer vim sort command :h :sort
date
wc
awk // awk is great for transforming/filterings data
// example: awk '{print $1}'
grep
beautifiers: {{{
fmt -n //reformat text to fit n columns wide
xmlformat //nice program for formating xml...
//configurable too. Side note: I find it
//better than xslt approach because it
//doesn't it doesn't loose doctype/dtd
//info via the xml parser on os x, brew
//install xmlformat, otherwise look at
//http://www.kitebird.com/software/xmlformat/
uglifyjs -b //beautify javascript (strips comments...) consider other beautifiers too
:%!nl -ba //Number all lines
:%!cat -n //Number all lines
tr '[a-z]' '[A-Z]' //there are other methods to do this in vimscript, but
nroff/groff
}}}
}}}
}}}
system() vimscript function (like using backticks ` in bash) {{{
Examples:
:echo system("wc -w ".expand("%"))
:let @a=system("ls -l") // assign result to the a register
note: vim also supports backticks ` in ex in some situations :help backtick-expansion
}}}
Shell commands in Insert mode: {{{
Ctrl-R = //access vimscript while in insert mode... can call system() and other vimscript functionality
Note: = is the special expression register. Very cool way to evaluate vimscript expressions on the fly
Can also use it as a simple calculator.
In insert mode, try:
Ctrl-R = system('ls -l')
}}}
Shell commands output to a scratch buffer: {{{
:R
http://vim.wikia.com/wiki/Append_output_of_an_external_command
}}}
Comment about OOTB ! filter and system() functionality:
Filter command and system() are useful for transforms/filters or reading in results
but not useful for interactive commands.
}}}
Accessing a shell with OOTB functionality: {{{
:sh
open a subshell
:!bash
Ctrl-Z, fg
when you are running vim in a terminal... does not apply to gvim/mvim
}}}
Terminal inside vim {{{
ConqueTerm plugin {{{
http://code.google.com/p/conque/
Conque NerdTree plugin example
See my gist: https://gist.github.com/1441083, a fork of an example by scrooloose
FYI my vimrc settings for ConqueTerm: {{{
"ConqueTerm
"I found ConqueTerm only works with 32bit version of python on windows
"If you have a 64 bit version installed, point to the correct python executable
"explicitly. (If it's in the path and it is 32bit version, no need for this)
if has("gui_running") && has("gui_win32")
let g:ConqueTerm_PyExe='d:\opt\Python27\python.exe'
endif
let g:ConqueTerm_CloseOnEnd = 1 " close ConqueTerm buffer and delete it when the program inside it exits
" if you don't set this, then you have to manually :bw to wipe the buffer
let g:ConqueTerm_ReadUnfocused = 1 " Necessary if you want dynamic updates when you move to a new window
let g:ConqueTerm_ExecFileKey = '<F11>'
let g:ConqueTerm_SendFileKey = '<F10>'
let g:ConqueTerm_SendVisKey = '<F9>'
}}}
Comments about ConqueTerm: {{{
- you can manipulate the buffer and yank from ConqueTerm
- you can send text from other vim buffers into ConqueTerm
- descent but not perfect terminal emulation (handles color, but not always)
- Function keys... and ESC key... Ctrl-C... Ctrl-O in insert mode, others?
- slower than other terminals
- not dynamic when it is not the active buffer
- unless you let g:ConqueTerm_ReadUnfocused = 1
- as an example, try running top or tail a log file
}}}
}}}
ConqueTerm alternative: http://www.wana.at/vimshell/ {{{
I haven't tried this, but it could be interesting. I am mentioning it as an fyi...
}}}
}}}
vim inside a Terminal Multiplexer (Screen or Tmux) {{{
slime {{{
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/
Note: Only demoed tmux and tslime. Did not look at slime.
}}}
tslime {{{
http://www.vim.org/scripts/script.php?script_id=3023
https://github.com/kikijump/tslime.vim
Note: to make it work with pathoden etc, put I put tslime.vim in bundles/tslime/plugin folder...
The git repository didn't have it in a plugin folder...
FYI: useful function and cmap for tslime users {{{
" see http://www.candland.net/2011/11/23/send-commands-from-vim-to-tmux-pane/
" (A small syntax error in the url above is fixed below...)
function! To_Tmux()
let b:text = input("tmux:", "", "custom,")
call Send_to_Tmux(b:text . "\n")
endfunction
cmap tt :call To_Tmux()<CR>
}}}
}}}
screen.vim (an alternate to slime and tslime) works in both tmux and screen {{{
I haven't tried it... but it looks interesting.
https://github.com/vim-scripts/Screen-vim---gnu-screentmux
}}}
Comments about terminal multiplexers like tmux/screen: {{{
- Can access tmux/screen from both vim and gvim/mvim but note tmux/screen will be in a separate
window in your OS. So you need to manage switching windows in your OS, and then windows/panes
in tmux/screen in your terminal, and also windows mvim/gvim...
Too much to juggle around in my opinion.
- seems to be best when vim is running inside tmux. This way you only have to manage moving around
inside tmux and vim.
- a terminal inside vim seems nicer when in mvim/gvim... but unfortunatley ConqueTerm isn't a perfect
terminal. As a result, I am leaning towards only using vim inside a terminal with tmux.
}}}
}}}
Specialized plugins {{{
A shell in a terminal is more general of course, but Vim has some well designed plugins that in
many ways are better than going to a shell. So be sure to look for specialized plugins
Examples:
fugitive https://github.com/tpope/vim-fugitive
Be sure to look at the many screencasts on fugitive here:
http://vimcasts.org/
syntastic github.com/scrooloose/syntastic.git
}}}
}}}
There was a question about some of my favourite onilne resources for keeping up on vim and plugins. {{{
I monitor a number of RSS feeds. Here are some of my favourites {{{
http://www.reddit.com/r/vim/
http://stevelosh.com/blog/
http://got-ravings.blogspot.com/
http://technotales.wordpress.com/
http://lococast.net/?s=vim
http://vimcasts.org/feeds/ogg/
https://github.com/vim-scripts.atom
http://stackoverflow.com/questions/tagged/?tagnames=vim&sort=active
http://groups.google.com/group/vim_mac/topics?pli=1
}}}
Some plugins I was using/talked about: {{{
https://github.com/kenkov/openurl.vim
https://github.com/kana/vim-fakeclip
Side note...If you use snipmate, have a look at this fork.
https://github.com/garbas/vim-snipmate
}}}
}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment