Permalink
Browse files

Add VIM Server/Sessions post

  • Loading branch information...
1 parent 390f09e commit 02df82639f2b0f124396da48df35b0cbec6d87db @crodjer committed Apr 15, 2012
Showing with 92 additions and 0 deletions.
  1. +92 −0 posts/2012-04-15-yet-another-vim-productivity-post-server-client.mkd
@@ -0,0 +1,92 @@
+---
+title: Yet another Vim productivity post: Server-Client
+slug: yet-another-vim-productivity-post-server-client
+tags: vim, server, productivity
+author: crodjer
+---
+
+There are 10 text editors in this world: One is *Vim* and the other *Emacs*.
+Now, when it all began I chose Vim. I know there is no need for me to sell it to
+you. It does that itself. I rely heavily on the Vim *server-client* feature and
+thought that it should share it with everyone.
+
+#Vim Server, ZSH and Tiles
+A Vim instance behaves as a server in which files can be opened through remote
+applications. Read `:help client-server` of Vim to know more about this. I
+generally keep multiple Vim sessions running, described by task they are related
+to.
+A typical workspace has one instance of Vim running and multiple terminals
+around it. Lets call this workspace for project *foo*. So the name of Vim
+instance server will be *foo*:
+
+ vim --servername foo
+
+And any file will be open in this server, using this command:
+
+ vim --servername foo --remote-silent bar.hs
+
+
+ +-----------------------+
+ | |~$ |
+ | | |
+ | |-----------+
+ | Vim |~$ |
+ | Server | |
+ | |-----------+
+ | |~$ |
+ | | |
+ +-----------------------+
+
+
+How this helps:
+
+ - Lets me keep a well defined separation on various projects I am working on.
+ The list of files in the buffer per instance remains short and manageable.
+
+ - Also each instance can have its own project specific environment - current
+ directory, python virtual environments etc.
+
+For easing all this up, I use a set of helper functions in my *zshrc*:
+
+```sh
+# Set the name of vim session the terminal is tied up to
+eset(){
+ export VI_SERVER=$1
+}
+
+# Fire up a new server according to the argument supplied
+vs(){
+ eset $1
+ vim --servername $VI_SERVER
+}
+
+# Open up the files in the environment Vim server.
+es(){
+ vim --servername $VI_SERVER --remote-silent $*
+}
+
+# Reuse Vim ZSH completions for vim completions
+compdef _vim es
+
+```
+
+#Vim Sessions
+Having multiple instances is great, but I don't want to set each up every time
+I need resume working. For this I use *Vim Sessions*, which allow the current
+Vim state to be stored over the disk.
+
+[vim-session][vim-session] plugin will help you manage sessions easily. It is
+well integrated with Vim client-server.
+
+From docs:
+
+> When you start Vim with a custom server name that matches one of the existing
+> session names then the matching session will be automatically restored.
+
+#tldr;
+Checkout `:help client-server` in vim and [vim-session][vim-session], to boost
+your productivity some more with Vim.
+
+[vim-session]: https://github.com/xolox/vim-session
+[zshrc]: https://github.com/crodjer/vimfiles
+[vimconfig]: https://github.com/crodjer/configs/blob/master/zshrc

0 comments on commit 02df826

Please sign in to comment.