You are not logged in.

#1 2007-08-18 01:25:39

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

vim/gvim plugins and scripts [solved]

I've been playing with gvim (and vim) and trying to configure it as my default development environment but I am  having all kind of problems getting things to work, particularly plug ins and scripts.
I spent loads of time in the vim web site and according to the instructions I read we must source plug ins and scripts. They also indicate that your preferences must be set in ~/.vimrc which I also created. Further the instructions seem to expect a ~/.vim directory where users would have a /scripts and a /plugins directory so I created them.
Now this is my results after having done all that:
1. if I use vim the ~/.vimrc file that should start my colorscheme it provides a different color scheme than if I use the   **same file** with gvim (and BTW I had to copy it under the name ~/.gvimrc or it would not work. I know, I know, the instructions in gvim say use ~/.vimrc but it does not work). And by the way the colors in gvim are **much nicer** !! mad

2. If I add scripts to the ~/.vim/scripts or plugin directories and source then I get no complaints but the scripts do not work at all. It is irrelevant if I put then in the scripts or plugins direcories the result is the same.
I also noticed in several web sites I visited that some call the directories script and plugin (singular) so unable to figure out what's correct I also created under my ~/.vim/ directory the directories with singular name and in plural with all the same scripts in them ... but to no avail.

3. I've created a vimrc with the following content:

set nu
set guifont=Liberation\ Mono\ 9
colorscheme darkblue
au Filetype html,xml,xsl source ~/.vim/scripts/closetag.vim

and I'm certain that it is working because I get numbers on the let hand side, the correct font, the darkblue color scheme (although I get variations on the color scheme depending of whether I use gvim or vim) and no complains about the closetag.vim on start up but neither does work when I'm running the program.
What gives!? roll

I really would like to be able to use gvim/vim for programming, its clean simple and fast but I'm getting frustrated with the erratic/inconsistent behavior of the program.

Is anyone here successfully using gvim/vim that can give me some help/direction to configure this editor/s?
I do mostly web development, python programming, php and mysql programming. Are there any recommended plugins that will improve efficiency while working in the environment?
What am I doing wrong that I do not seem to get this working? mad

Thanks for any help.

R

Last edited by ralvez (2007-08-19 23:20:56)

Offline

#2 2007-08-18 01:43:35

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: vim/gvim plugins and scripts [solved]

read the instructions distributed with the script. they'll tell you where to put it, either in ftplugin, plugin, whereever. Don't just dump them all in a particular directory. It's not inconsistent, each directory has a reason.

.vim/ftplugin for plugins specific to a filetype
.vim/plugin for general plugins.
.vim/syntax for syntax colouring
.vim/doc for plugin documentation

Ive never come across the need for a .vim/scripts directory, so that may be why thats not working.

Some plugins require manual activation, again, this will be detailed in it's documentation.

As for the gvimrc, thats something wierd with how arch have packaged it, it annoys me too.

James

Offline

#3 2007-08-18 01:50:48

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

James,

Thanks for the reply.
I actually did not name the directories capriciously, I followed the directions I found in the VMC site on the contributed plug ins. That's what I find confusing!
I'm very determined to get this thing working (it must be a programmers thing ... just do not know how to give up roll) so any other ideas are welcome.

What about plugins you use and are happy with?

R

Offline

#4 2007-08-18 02:28:31

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

James,

On further analysis I think there are inconsistencies in the configuration of this program.
I did a pacman -Sy vim-closetag and ended up with a script in /usr/share/vim/plugin/closetag.vim
Now on reading this file to better understand it, it says:

Install:
" To use, place this file in your standard vim scripts directory, and source
" it while editing the file you wish to close tags in.  If the filetype is not
" set or the file is some sort of template with embedded HTML, you may force
" HTML style tag matching by first defining the b:closetag_html_style buffer
" variable.  Otherwise, the default is XML style tag matching.
"
" Example:
"   :let b:closetag_html_style=1
"   :source ~/.vim/scripts/closetag.vim
"
" For greater convenience, load this script in an autocommand:
"   :au Filetype html,xml,xsl source ~/.vim/scripts/closetag.vim

As you can see (a) the file in Arch is placed in a totally different directory
(b) If I copy the file to the correct directory (as per install instructions) I get the following error when I start vim/gvim :

Error detected while processing FileType Auto commands for "html":
E484: Can't open file closetag.vim

(c) It does not run either if I point to the directory /usr/share/vim/plugin/closetag.vim as it says it cannot not read the file (??)

Does anyone have a script that you use and **works** that I can install to see if I can find what's wrong with my settings?

R

Offline

#5 2007-08-18 09:09:03

lang2
Member
Registered: 2006-02-10
Posts: 386

Re: vim/gvim plugins and scripts [solved]

(1) There is a concept of VIMRUNTIME directory, which is a set of directories that vim looks for scritps.
Doing ':set rtp?' inside vim will tell you yours. By default, it is:

  runtimepath=~/.vim,/usr/share/vim/vimfiles,/usr/share/vim,/usr/share/vim/vimfiles/after,~/.vim/after

(2) Any files that is under <rtp>/plugin will be 'sourced' for any file you edit. So droping the closetag.vim under ~/.vim/plugin will work.

(3) Doing ':scriptnames' once vim is started and you have loaded your file will tell you what files has been 'sourced' by vim. Mine includes ~/.vimrc and ~/.gvimrc and a whole bunch of others.

(4) vim can run in 'compatible mode', in which it tires to simulate plain 'vi'. If that's your problem, add a line:

set nocp

in your ~/.vimrc file will fix it.

Offline

#6 2007-08-18 14:29:31

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

@ lang2

Thank you! That was great learning.
I noticed that running set rtp? gives me also a host of directories including ~/.vim/after so that's good.
The scriptnames command indicates that ~/.vim/plugin/closetag.vim is found but I have no explanation as to why yesterday it was giving me an error :

Error detected while processing FileType Auto commands for "html":
E484: Can't open file closetag.vim

because today it seems to be working. At least I open an html file and get no complain. lol it however does not seem to be "closing tags" when I type html. Eg: if I purposely type "<p> something" with no closing tag nothing happens (??) May be I misunderstood the way the program is supposed to work?
I wonder if part of my problems were due to the fact that I created two start up files: (1) ~/.vimrc and (2) ~/.gvimrc
I actually did so because gvim will not read ~/.vimrc at start time so all my settings (like  set nu, set guifont=Liberation\ Mono\ 9, etc.) were ignored. Once I put them in gvimrc they worked. cool
I do not think that the compatible mode is a problem, but I'll keep that card under my sleeve just in case smile

I think I'm beginning to get "the hang" of vim and I like it ! smile yesterday I learned how to test my python programs right from the same spot I am coding by mapping a key to save my code and run it through the python interpreter ... that's cool.

Thanks for the help!!

R

Offline

#7 2007-08-18 14:56:09

nj
Member
Registered: 2007-04-06
Posts: 93

Re: vim/gvim plugins and scripts [solved]

If you use both vim and gvim, I would recommend linking .gvimrc to .vimrc:

$ rm .gvimrc
$ ln -s .vimrc .gvimrc

If you want some commands to run only for gvim, check for gui_running. For instance, I use the ps_color colorscheme in the gui but another scheme in the terminal.

if has("gui_running")
    set background=dark
    color ps_color
else
    color my_default
endif

The closetag plugin does not automatically close tags. You must hit C-_ (ctrl-shift-hyphen for us keyboards) to complete the tag. Take a look at the xmledit plugin if you want tags to be autocompleted.

I personally find C-_ annoying to type, so I have redefined it to shift-enter:

autocmd Filetype html,xml,xsl,php,smarty,htmldjango imap <S-CR> <C-R>=GetCloseTag()<CR>

Offline

#8 2007-08-18 15:16:23

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

@ nj

I appreciate your comments. Great tips!!
I'll make a symlink to ~/.vimrc .
I was pressing Ctrl + - (dash) and it would move the cursor up every time lol, somehow I did not understand the explanation in the program the way you just indicated. But sure enough, doing what you say it works.

I may re-map the keys if I find it annoying too.

Thanks!!

R.

Offline

#9 2007-08-18 20:48:26

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

Is there a way to bind keys (perhaps using something like the "if has()" example above ) to activate a particular interpreter based on the file extension?
Mi idea is to bind say F2 to !python % if I'm working on a py file and PHP if my file has a .php extension and so on.

Just to be clear, I already know how to bind keys I did this for python:

map <f2> :w\|!python %<cr>

but what I would like to do is use F2 for python if I'm working with a python file but if I'm working on PHP I would like to use the same key to start the php interpreter and so on.

Thanks in advance !!!

Offline

#10 2007-08-18 22:31:36

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: vim/gvim plugins and scripts [solved]

hrm, if you want to activate plugins depending on filetype, thats what ~/.vim/ftplugin is for. I've got a ~/.vim/ftplugin/python.vim that's automatically loaded when i deal with a python file.

James

Last edited by iphitus (2007-08-18 22:31:52)

Offline

#11 2007-08-18 23:36:30

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

James,

I think you did not understand my question. I know how to do what you say I do it too:

au Filetype py source ~/.vim/ftplugins/python.vim

Trust me I've been reading a loooooooooot roll about gvim/vim in the last 24 hours and I've learned a good bit of it.

I'm talking about binding a key, (always the same key) to an interpreter based on a file type.
I guess in code form I mean something like:

if (extension py){
map <f2> :w\|!python %<cr>
au Filetype py source ~/.vim/plugin/python.vim
} else if (extension php){
map <f2> :w\|!php %<cr>
  au Filetype php source ~/.vim/plugin/python.vim
}

I know what I wrote about does not work in gvim/vim but I mean it as an example of what I'm trying to do.
Thanks again for the help ... and  BTW what does hrm mean?

I really like the vim thing... and it has a built in spell checker too !! cool

R

Last edited by ralvez (2007-08-18 23:47:21)

Offline

#12 2007-08-19 01:47:53

nj
Member
Registered: 2007-04-06
Posts: 93

Re: vim/gvim plugins and scripts [solved]

In your .vimrc:

au FileType python map <buffer> <F2> :echo "python"<cr>
au FileType php map <buffer> <F2> :echo "php"<cr>

Or as iphitus said, create the files in your ~/.vim/ftplugin. Files in ftplugin are automatically sourced depending on the filetype so there is no need to source them manually.

# ~/.vim/ftplugin/python.vim
map <buffer> <F2> :echo "python"<cr>

# ~/.vim/ftplugin/php.vim
map <buffer> <F2> :echo "php"<cr>

The <buffer> modifier is needed to bind the key for each buffer, not globally. Otherwise, opening a python file then a php file would bind the key to the php command for the python file as well.

Offline

#13 2007-08-19 01:57:07

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

@ nj

Thanks Again!
Gee you guys (I mean James, lang2 and you) seem to have bee putting a lot of time into understanding this software. I've spent loads of time in the last 2 days and find it difficult to get reliable information about this program.

Today I found a book called "Hacking Vim" by Kim Schulz. Does any of you know of it? Is it worth?
I think I'm going to order it from Amazon, the sample chapter I read seems good.

@ James

I guess you did understand my question then ... I just did not get your answer. lol

I really appreciate all the help from all of you guys!!

Rick

Offline

#14 2007-08-19 09:53:14

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: vim/gvim plugins and scripts [solved]

ralvez wrote:

@ nj

Thanks Again!
Gee you guys (I mean James, lang2 and you) seem to have bee putting a lot of time into understanding this software. I've spent loads of time in the last 2 days and find it difficult to get reliable information about this program.

I was fortunate enough to be introduced to one of the few people I really consider a guru.

Today I found a book called "Hacking Vim" by Kim Schulz. Does any of you know of it? Is it worth?
I think I'm going to order it from Amazon, the sample chapter I read seems good.

No idea. Havn't read it myself

I really appreciate all the help from all of you guys!!

you're welcome smile Vim can be frustrating at first, but once you learn it, it often becomes second nature.

Offline

#15 2007-08-19 10:05:43

lang2
Member
Registered: 2006-02-10
Posts: 386

Re: vim/gvim plugins and scripts [solved]

The book is fairly new and I haven't read it yet. But vim is a wonderfully self-documented. Simply type in :help command to see yourself.

Offline

#16 2007-08-19 23:20:29

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

Yesssssssss big_smile
I finally got it!! I've got the whole thing customized for all my most used programming languages: HTML, Python, PHP, XML.
I got the "Hot Key" set up to activate the correct interpreter (in the case of html it runs firefox) and custom colours all figured out.

Thank you all for the wonderful help!!

Rick

Offline

#17 2007-09-04 16:13:23

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: vim/gvim plugins and scripts [solved]

@ralvez
I am kind of interested in how you got your hotkey setup for interpreter.. could you post your config?


The ultimate Archlinux release name: "I am your father"

Offline

#18 2007-09-04 17:30:45

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: vim/gvim plugins and scripts [solved]

@jinn,

It's actually really easy:
1. go to ~/.vim/plugin and create "python_settings.vim" (that's what I called it you can call it whatever makes sense to you)
2. In that file enter:

" General Settings // set line numbers, font type and color scheme
set nu
set guifont=Liberation\ Mono\ 10
colorscheme darkblue
" Set tab stop
set tabstop=4
" Use < and > to block indent/unindent regions
set shiftwidth=4
" Use swiftwidth for inserting <TAB> instead of tabstop
set smarttab
" Insert spaces instead of <TAB> character when <tab> key is pressed.
" This is the preferred method when coding in Python
set expandtab
" This will make sure that since we do not use <TAB> it the backspace and
" delete will remove the 4 spaces we use to substitue <TAB>
set softtabstop=4
" Set auto-indentation (it is better for Python)
set autoindent
" When a file with extension .py is open use "python.vim"  and apply
" smartindent to all the following keyworkds
au Filetype py source ~/.vim/plugin/python.vim
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
" If a file with extension .py is open when F2 is pressed  save it 
" and process it with the python interpreter
map <f2> :w\|!python %<cr>

The vary last line has the code that maps the key to an interpreter.

You can create a different file for each of your desired file/interpreter associations.

Hope this helps.

R

Last edited by ralvez (2007-09-04 21:33:09)

Offline

Board footer

Powered by FluxBB