# vim



## graudeejs (Feb 9, 2009)

Today I had some time... i decided to dedicate it to study some vim.

Now after few hours of reading, I announce vim to be my favorite text editor.

It's so flexible.... uhhhh

How could i live without it so long????


----------



## hydra (Feb 9, 2009)

Better later than never


----------



## hitest (Feb 10, 2009)

I'm lazy, I use nano.   So what is so good about vim?  You now have me curious!


----------



## graudeejs (Feb 10, 2009)

I don't think words can express this....
but reading *usr_01.txt* to *usr_04.txt* is a thing i advise...

so many great features, so many ways to combine commands, so easy to do this and that..... i'm *shocked*

Tomorrow i'm removing [my so far default editor] *geany*, and never use *le* again (I used to like it)


----------



## gnemmi (Feb 10, 2009)

Here you can find some minor tricks, that I posted on a forum we have, to get an even better vim experience ..
The whole post is in spanish, but I think the examples are pretty simple to follow .. In case you need help on understanding what they mean, just mail me o sen a PM 

By the way ... I never leave without this ones on my .vimrc:


```
set textwidth=0    " Don't wrap words by default 
set ruler    " Show the line and column numbers of the cursor 
set nu    " Show line numbers
set ts=4       "Tab space == 4 whitespaces
set sw=4    
set et 
colorscheme murphy
```

Regards

PS: press "i", then ctrl+v and then press esc to get "^[" .. the scape sequence ..


----------



## mjguzik (Feb 10, 2009)

How about tricks in english? 

http://www.catswhocode.com/blog/100-vim-commands-every-programmer-should-know

http://linuxgazette.net/152/srinivasan.html


----------



## hitest (Feb 10, 2009)

killasmurf86 said:
			
		

> I don't think words can express this....
> but reading *usr_01.txt* to *usr_04.txt* is a thing i advise...
> 
> so many great features, so many ways to combine commands, so easy to do this and that..... i'm *shocked*
> ...



Okay.  Now you really have me curious, killasmurf86!  Thank you, I've got some reading to do.   I'm looking forward to this!


----------



## graudeejs (Feb 10, 2009)

hitest said:
			
		

> Okay.  Now you really have me curious, killasmurf86!  Thank you, I've got some reading to do.   I'm looking forward to this!



here's my vimrc :

```
[B]set nocompatible[/B]
[B]syntax on[/B]
set nomodeline
[B]set backspace=indent,eol,start[/B]
set ruler
[B]set history=50[/B]
set showcmd
set incsearch
set tabstop=4
set expandtab
set shiftwidth=4
set number
set scrolloff=5
set sidescrolloff=10
set incsearch
set wrapscan
set autoindent
set title
set hlg=en
set si
set backupdir=/home/killasmurf86/.bak
set backupext=.bak
set patchmode=.orig
set writebackup
set autoread
set enc=utf-8
set noautowrite
```

i made parts in bold that you want in your .vimrc already, especially syntax highlighting [you really want it, lot easier to read and navigate manual]


----------



## anemos (Feb 10, 2009)

```
set nocompatible
```

This is redundant when you do have a .vimrc file.

See this link for a biiiiiiig variety of nice schemes.


----------



## waterstof (Feb 10, 2009)

After installing vim , this will get you on your way:

```
vimtutor
```

a tutorial oriented towards praxis! A very good one.


----------



## gnemmi (Feb 10, 2009)

```
set ts=4  == set tabstop=4
set sw=4  == set shiftwidth=4
set nu    == set number
set et    == set expandtab
```

and so forth ... 

mjguzik: have you read my thread?? it has nothing to do with what you posted :s


----------



## fonz (Feb 11, 2009)

killasmurf86 said:
			
		

> Now after few hours of reading, I announce vim to be my favorite text editor.



Welcome to the club :beer Took you long enough though


----------



## hitest (Feb 11, 2009)

Thanks for the tips, gentlemen.


----------



## fonz (Feb 11, 2009)

gnemmi said:
			
		

> ```
> set ts=4  == set tabstop=4
> set sw=4  == set shiftwidth=4
> set nu    == set number
> ...



The set number thing is kinda debatable. I can imagine that people like it, but personally I don't.

One other thing: if you don't like the way vim's auto-indentation works with C code, disabling the _indentexpr_ variable (*:set indentexpr=*) might make your life easier.

Alphons


----------



## gnemmi (Feb 12, 2009)

I like "set nu" ...

Take this code .. main.c


```
1 #include<stdio.h>
  2
  3 int main(){
  4
  5 /* a comment in here ... */
  6
  7     int a = 1;
  8     char something{} = "Something to print";
  9
 10     printf("%s :%d\n", something, a);
 11
 12     return 0;
 13 }
 14
```

compile it and, of course ... it won't ... I forgot my finger pressing the "shift" key while I typed "[]" on line "8" ...


```
[gonzalo@inferna ~]% gcc -Wall -pedantic -O2 -o test main.c
main.c: In function 'main':
main.c:8: warning: ISO C forbids nested functions
main.c:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
main.c:8: error: expected expression before '=' token
main.c:10: error: 'something' undeclared (first use in this function)
main.c:10: error: (Each undeclared identifier is reported only once
main.c:10: error: for each function it appears in.)
```

now .. just issue:


```
[gonzalo@inferna ~]% vim +8 main.c
```

and vim will open main.c and position the cursor on line 8, all at once ... 

"set nu" helps me get a visual check on whether the cursor jumped straight to line 8 or not 

It might seem trivial in this example .. but on 670 lines of perl voodoo .. it really helps 

Regards


----------



## fonz (Feb 12, 2009)

gnemmi said:
			
		

> I like "set nu" ...
> [snip]
> now .. just issue:
> 
> ...



Like I said: I can imagine that you like it and you give a good example of why you do, but _personally_ I don't like it that much because all those line numbers are a tad too cluttering/distracting for my taste. I'd rather just "set ruler". But hey, to each his own and I'm sure some people will look at your example and go: "Hey, that's kinda neat!" I just won't be one of them, that's all.

Happy coding,

Alphons


----------



## cajunman4life (Feb 13, 2009)

As an alternative to "set nu", I have the following:

nmap <C-N><C-N> :set invnumber<CR>

So if I want line numbers, I press ctrl+n twice. To get rid of them again, ctrl+n twice again.


----------



## fonz (Feb 13, 2009)

cajunman4life said:
			
		

> As an alternative to "set nu", I have the following:
> 
> nmap <C-N><C-N> :set invnumber<CR>
> 
> So if I want line numbers, I press ctrl+n twice. To get rid of them again, ctrl+n twice again.



<SouthPark>You know, I think I learned something today.</SouthPark>

Alphons


----------



## lme@ (Feb 14, 2009)

gnemmi said:
			
		

> ```
> [gonzalo@inferna ~]% vim +8 main.c
> ```
> 
> ...



Even better is, when you have a Makefile in the working directory. You type :make and if you get an error, vim directly goes to the line where the error was found.


----------



## gnemmi (Feb 14, 2009)

Sure thing !
But that was harder to demonstrate in here


----------



## rliegh (Feb 21, 2009)

I prefer (n)vi any day of the week, myself.


----------

