2

Vim safe copy paste without bad indentation

The Horror

One thing that was always great with Linux desktop X11 (and continued with Ubuntu 12.10) was copying text with a mouse selection and just pasting it with the middle button. That’s why I became horrified when it started to not work with Vim!

I was evaluating a Perl Module and when I copy/pasted a block of an example code this happened

 

Borked Paste

It has to be a way to have a clean copy/paste again!

The Solution

Fortunately Vim has the notion of paste and so has a mode to activate it and ignore indentations and other features. You just activate it with :set paste

normal-set-paste-500

paste-mode-500

Change to insert mode

paste-mode-insert-500

and now just paste the text the way it was supposed.

Paste Ok

Hurray! Now press Esc and get back to our helpful indentations with :set nopaste.

paste-set-nopaste-500

normal-set-nopaste-500

Less typing, may I ?

Of course there’s a pragmatic way of doing all these. We can define a keyboard key to just make the copy/paste a safe operation. I’m using key F12.

:set pastetoggle=

In insert mode you can toggle the paste mode so you don’t despair with the wrong indentation. Add it to your .vimrc

Another way it’s to just paste what you want into the line you are at in visual mode.

map  :r! xsel

xsel is a command line X11 tool to manipulate its “clipboard”.
This mapping reads into Vim the output of xsel which is the clipboard copy buffer. I’m using this one.

You may need to install it but it’s simple

$ sudo apt-get install xsel

Conclusion

Vim customization and plugins broke a plain simple copy/paste. However we got a no brain and fast solution with our F12 key.

5

Using an SMB share from Mountain Lion in Linux

Or can’t connect via SAMBA from my Linux to Mountain Lion

I went from Mac OS X Snow Leopard to Mountain Lion. I read that this affects Lion too. After the upgrade my mount point on the Linux machine stop working. I couldn’t copy anything to my Mac Mini that way.

You now need to use additional security options: nounix,sec=ntlmssp. Like this:

$ mount.cifs //192.168.1.xxx/osxshare /mnt/mymac/ \
  -o user=******,password=******,nounix,sec=ntlmssp

Or if you mount it automatically through fstab like I do:

$ tail -1 /etc/fstab
//mac-mini.local.lan/linux.backup /home/biafra/Mounts/mac-mini/ cifs
credential=/etc/samba/auth,uid=biafra,gid=biafra,nounix,sec=ntlmssp 0 0

Hope it will help you.

0

How to create a quick presentation with Markdown in Ubuntu

Why the need for presentations in Markdown

I’m used to Markdown to write down some documentation and procedures at work.

It would be awesome to continue using it for quick presentations, when you want to introduce the team to new concepts or fast learning sessions. Therefore I can write them in plain text wherever I am, even with a mobile, instead of opening Impress.

Fortunately there are tools to make you do that.

What do I need then ?

Using Perl for most of our tools I’m very used to TIMTOWTDI. So, this is just one way of implementing what I want.

So, I’ll choose Markdown Presenter to display the presentation. It’s a javascript and CSS combination to simply show your file in a browser. You then use left and right keys to turn forth or back. You separate your slides in the .md file using exclamation marks bordered by single lines.

The Presentation 
================

> My first slide

!

Second slide title
------------------

* Item 1
* Item 2

!

Another slide just to repeat
my self without any doubt.

You may put these all in a site of your own. However as most often I need to have it locally due to network restrictions, I’ll install a small and simple local web server that’s already bundle with Ubuntu: webfsd.

Last but not the least, we should have a nice way to edit markdown files in vim.

Let’s just build stuff ok ?

This is a quick way and I haven’t installed anything you may say :-)

$ sudo apt-get install git webfsd

Yes, yes, *please* install git if you haven’t done so yet ;-)

After installed the web server create a zone for your presentations and get Markdown Presenter

$ mkdir ~/Documents/MyPresentations/
$ cd ~/Documents/MyPresentations/
$ git clone https://github.com/chrishulbert/MarkdownPresenter.git

Now, let’s start the web server on port 8888 with root ~/Documents/MyPresentations/MarkdownPresenter/ defaulting its index page to MP page.

$ webfsd -F -p 8888 \
-r ~/Documents/MyPresentations/MarkdownPresenter/ -f Presenter.html

If you go to http://localhost:8888/ on your web browser you will see a default presentation.

Now just copy your .md file to ~/Documents/MyPresentations/MarkdownPresenter/presentation.pm and reload the browser page. Voilà!

This is the simple and quick way. Adapt it the way you like better for your needs.

Last but not the… well

It maybe “least”. It’s not necessary but more of a visual aid.

Vim has a basic support for Markdown since version 7.3. As my .md files were identified as “modula2” I just added this line to my .vimrc

au BufRead,BufNewFile *.md set filetype=markdown

If you need a more capable plugin install PlasticBoy‘s vim-markdown.

And as you already are using vim-pathogen (You are, aren’t you ?)

$ cd ~/.vim/bundle/
$ git clone https://github.com/plasticboy/vim-markdown

You must change the previous line I told you to add to .vimrc because this plugin uses a different identifier for markdown files:

au BufRead,BufNewFile *.md set filetype=mkd

I don’t like the way it highlights the 2 spaces at an end of line. I saw here how to change it for an underline which I prefer.

hi link mkdLineBreak Underlined

I must warn you there are no great markdown plugin for Vim. Even forks from plasticboy’s don’t highlight well block elements within other block elements (e.g. sub headers, sub blockquotes)

So, and now ?

Now ? Be productive! :-) You just have simple tools to quickly and simply produce that presentation you were in need for yesterday.