LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   vim acting strange (https://www.linuxquestions.org/questions/debian-26/vim-acting-strange-231463/)

littlemidget 09-16-2004 03:56 PM

vim acting strange
 
So i found some helpful vim-hints on a page. Mostly stuff for .vimrc

I found out that i didn't have a .vimrc, so i made one, with this in it:

Code:

set nocompatible
syntax on
set pastetoggle=<F10>
set showmatch
set ignorecase
set incsearch

" autocomplete
function! CleverTab()
  if strpart( getline('.'), 0, col('.')-1 ) =~ '^s*$'
      return "<Tab>"
  else
      return "<C-N>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>

i am not sure how the pastegoogle is supposed to act, so i don't know if that's failing. I did notice that "syntax on" (highlighting) isn't working, at all, neither is the autocomplete-script at the bottom.

I write, for example, this:

Code:

$hi
$bye
$night

Then this happens when i write $ni hit tab:
Code:

$ni<C-N>
Another example:
Code:

*you
sme
^us

some words with tab, this is what i get:
Code:

^u<C-N>
*y<C-N>
s<Tab>

- Does anyone know why the highlighting and the tabcomplete-script is failing?

EDIT:Whenever i press tab, i get "<C-N>". The text i found (in norwegian, or else i would have linked to it) said that i would be able to "tab" as normal..

gypsy_rabbi 09-16-2004 06:16 PM

Re: vim acting strange
 
Code:

" autocomplete
function! CleverTab()
  if strpart( getline('.'), 0, col('.')-1 ) =~ '^s*$'
      return "<Tab>"
  else
      return "<C-N>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>

The s in ^s*$ needs to be \s, <Tab> needs to be \<Tab>, <C-N> needs to be \<C-N> -- ie. in all three cases you need a real backslash. This tells vim that the five characters you're typing out as "<Tab>", for instance, need to be interpreted as a tab (not as the five literal characters).

In vim, :help completion will give you details (including the code-snippet above).

Quote:

i am not sure how the pastegoogle is supposed to act, so i don't know if that's failing
:help paste or :help pastetoggle

Quote:

I did notice that "syntax on" (highlighting) isn't working, at all, neither is the autocomplete-script at the bottom.
Did you just start typing in a fresh vim window or did you open a file? vim needs the file extension (or some pattern in the filename) to know what kind of file it is and which syntax-highlighting "kit" it needs to use. So if you ask vim to open foo.sh or foo.pl which contains your code it should do the highlighting appropriately. Or pick Syntax->Show Filetypes from the menu, and then whichever type you want.

Look at the syn*.vim and filetype.vim files in your vim installation if you want to see how all this is done (most likely in /usr/share/vim/...)

littlemidget 09-17-2004 01:09 AM

Re: Re: vim acting strange
 
Did you just start typing in a fresh vim window or did you open a file? vim needs the file extension (or some pattern in the filename) to know what kind of file it is and which syntax-highlighting "kit" it needs to use. So if you ask vim to open foo.sh or foo.pl which contains your code it should do the highlighting appropriately. [/B][/QUOTE]

I tried to open/make foo.cpp - no colors though =\

I just copied .vimrc from my friends box, but the highlighting still don't work..

gypsy_rabbi 09-17-2004 01:49 AM

I think vim by default does not associate .cpp with C++. .C is C++, .c is C (as far as vim knows -- or at least as far as vim knows as far as I know :)). You can change what it thinks is a C++ file either in /usr/share/vim/filetype* or in your .vimrc Or try .sh or .pl, I know it recognizes those.

littlemidget 09-17-2004 09:49 AM

AFAIK, vim does take C++ by default. And .sh didn't work either. Thanks for trying to help, though :-)

gypsy_rabbi 09-17-2004 12:45 PM

One last idea: is this a nonstandard install at all? In vim, what does your $VIM variable contain? (:echo $VIM) $VIM/vim*/ should contain your syntax and other files. If it doesn't, that could be the problem. You might be able to reset $VIM in your .vimrc but I'm not sure about that.

littlemidget 09-17-2004 12:52 PM

Quote:

Originally posted by gypsy_rabbi
[B]One last idea: is this a nonstandard install at all? In vim, what does your $VIM variable contain? /B]
I get this: /usr/share/vim

and about the install: I installed vim with apt-get ..


All times are GMT -5. The time now is 02:21 AM.