LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Vim with Python support? (https://www.linuxquestions.org/questions/slackware-14/vim-with-python-support-4175436517/)

astanton 11-10-2012 01:18 AM

Vim with Python support?
 
I wanted to be able to do quick pasties from vim so I installed codepad.vim to ~/.vim/plugin/

The docs at http://www.vim.org/scripts/script.php?script_id=2298 said, "This requires +python support in vim."

When I'm editing a file and I do a :CPP I get the following:

Code:

~                                                                                                                                           
E354: Invalid register name: '+'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 37, in codepadPaste
vim.error
Press ENTER or type command to continue

Does this indicate that I have Python support compiled into my (stock) version of vim as distributed w/Slackware?

If not, what are some of the preferred ways to add python support to vim?

There's a tool called AAp on the vim.org website, there's downloading and compiling from source, like the website recommends as the best method, and then there's the Slackware logical extension of that, getting the sources for the package from the Slackware repo and running the SlackBuild.

The vim.SlackBuild Here shows the following:

Code:

config_vim() {
CFLAGS="$SLKCFLAGS" \
./configure \
  $* \
  --prefix=/usr \
  --enable-pythoninterp \
  --with-python-config-dir=/usr/lib${LIBDIRSUFFIX}/python$PYVER/config \
  --enable-perlinterp \
  --disable-tclinterp \
  --enable-multibyte \
  --enable-cscope \
  --with-features=huge \
  --with-compiledby="<volkerdi@slackware.com>" \
  --build=$ARCH-slackware-linux

  # I had been adding this, but got 100% complaints and 0% kudos:
  #  --enable-rubyinterp
}

So to me it appears that Python support is compiled in (I suppose I should recompile anyway to add the Ruby support too).

So what might I look at next? Basically, I'm just wanting to paste directly to a pastebin quickly from within vim.

Thanks.

markush 11-10-2012 05:15 AM

You can check vim's compile-options with
Code:

vim --version
in this case
Code:

vim --version | grep pyt
it seems that vim is compiled with python-support.

Markus

astanton 11-10-2012 07:36 AM

Yes it seems Python support is compiled in. I went ahead and re-compiled enabling Ruby, which is something I figured I would like to have, but I'm still wondering how to handle the error below:

Quote:

Originally Posted by astanton (Post 4826302)

When I'm editing a file and I do a :CPP I get the following:

Code:

~                                                                                                                                           
E354: Invalid register name: '+'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 37, in codepadPaste
vim.error
Press ENTER or type command to continue


Any ideas as to how I can address this issue, and what to do next?

audriusk 11-10-2012 10:42 AM

I checked the source of this plugin and the error is happening in line 67:
Code:

  vim.command("call setreg('+', '%s')" % url)
  vim.command("call setreg('*', '%s')" % url)

The plugin is trying to set "+ and "* registers which are called selection registers in Vim and represent selection ("*) and clipboard ("+) in X11. In other words, it copies the value of url variable into the clipboard for your convenience.

This works for me in GVim, but doesn't work in console Vim. According to Vim help, "for Unix systems the clipboard is only available when the +xterm_clipboard feature is present", which isn't in my case (:echo has('xterm_clipboard') returns 0). I build Vim myself, but my guess is that the same applies to Slackware's Vim as well.

astanton 11-10-2012 11:26 AM

Quote:

Originally Posted by audriusk (Post 4826544)
This works for me in GVim, but doesn't work in console Vim. According to Vim help, "for Unix systems the clipboard is only available when the +xterm_clipboard feature is present", which isn't in my case (:echo has('xterm_clipboard') returns 0). I build Vim myself, but my guess is that the same applies to Slackware's Vim as well.

Okay that explains it then. It's not satisfactory but it is the answer.

on my system :echo has('xterm_clipboard') returns a 0 in vim and a 1 in gvim. This really doesn't do all that much from me though. I tested pasting via :CPP with the plugin and it worked fine in gvim - but that's not an app I actually use. Typically, I'll use geany or bluefish or kate when I want a gui, and yet I know that I can just launch gvim, I tend to always have a terminal open and invoke the regular console vim there and use it almost exclusively for most things.

Well I'll look around to see if there's any pastie plugins that will work w/regular vim, and thanks so much for your help in determining what the problem was :)

I'll mark this solved now but if anyone has any suggestions for something that works for a pastebin from console vim I'd appreciate hearing about it.

T3slider 11-10-2012 12:33 PM

I haven't tested it, but couldn't you just get rid of the two instances of
Code:

vim.command("call setreg('+', '%s')" % url)
vim.command("call setreg('*', '%s')" % url

in the .vim file? You wouldn't get the URL copied into the system buffer but the webbrowser.open(url) line should open the page up in your browser anyway, so you could get the URL from there. Alternatively, you could rebuild vim. Note this line in the SlackBuild:
Code:

config_vim --without-x --disable-gui
You would have to remove --without-x (and possibly change it to --with-x if it isn't the default). Not sure about --disable-gui and I won't bother downloading the source to check just now.

astanton 11-10-2012 12:44 PM

Yes!

Here's mention of that in the Vim wiki: http://vim.wikia.com/wiki/Script:2298

Essentially, There's three lines in each function to be commented out and then it works in both vim and gvim :)

I commented out those three lines and the only gripe I have now is that there's no syntax highlighting for shell scripts, but that's a minor issue. I'm able to quickly post text to a pastebin and like you suggested I can just copy the URL from the browser to paste in an IRC channel or share it some other way.

I haven't tried with commenting just the two lines you suggest and don't know what more that would get me. It works now and I'm pretty happy.

T3slider 11-10-2012 02:47 PM

Quote:

Originally Posted by astanton (Post 4826604)
I haven't tried with commenting just the two lines you suggest and don't know what more that would get me. It works now and I'm pretty happy.

Commenting the three lines is more appropriate -- 'import vim' imports vim bindings in python to set the registers, but since they aren't being used anyway importing vim is superfluous. It would work identically either way but importing vim would waste RAM and isn't necessary so what you've done is the best method.


All times are GMT -5. The time now is 03:02 PM.