Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
VIm fancy
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Xk2c
Apprentice
Apprentice


Joined: 17 Jul 2004
Posts: 240

PostPosted: Sun Jan 28, 2007 8:35 pm    Post subject: Reply with quote

Bushwack wrote:
Code:
nmap <silent> <C-V> :set paste<CR>"*p:set nopaste<CR>


Thanks. That i was looking for. :)
_________________
useful Xterm, Aterm and RXVT-Unicode features
Back to top
View user's profile Send private message
gAzo0o
n00b
n00b


Joined: 22 Feb 2006
Posts: 22

PostPosted: Sat Feb 10, 2007 9:42 pm    Post subject: Reply with quote

I would like to ask, if there is a way to set the tab key to produce let's say 4 spaces. I'm doing a little python coding and I preffer spaces, but it would more comfortable doing them with just the tab key - like i can in eric for example. I'm trying to switch from eric to vim, which I found more useful :)
Back to top
View user's profile Send private message
Mousee
Apprentice
Apprentice


Joined: 29 Mar 2004
Posts: 291
Location: Illinois, USA

PostPosted: Sat Feb 10, 2007 11:55 pm    Post subject: Reply with quote

gAzo0o wrote:
I would like to ask, if there is a way to set the tab key to produce let's say 4 spaces. I'm doing a little python coding and I preffer spaces, but it would more comfortable doing them with just the tab key - like i can in eric for example. I'm trying to switch from eric to vim, which I found more useful :)

Something like this should work:
Code:

set tabstop=4

The above sets the number of spaces that a <Tab> counts for.
Back to top
View user's profile Send private message
gAzo0o
n00b
n00b


Joined: 22 Feb 2006
Posts: 22

PostPosted: Sun Feb 11, 2007 10:29 am    Post subject: Reply with quote

Thanks, but that's still a tab, not spaces. I don't want to mix them.
Back to top
View user's profile Send private message
Xk2c
Apprentice
Apprentice


Joined: 17 Jul 2004
Posts: 240

PostPosted: Sun Feb 11, 2007 12:02 pm    Post subject: Reply with quote

gAzo0o wrote:
Thanks, but that's still a tab, not spaces. I don't want to mix them.


Code:
set tabstop=4
set expandtab

_________________
useful Xterm, Aterm and RXVT-Unicode features
Back to top
View user's profile Send private message
gAzo0o
n00b
n00b


Joined: 22 Feb 2006
Posts: 22

PostPosted: Sun Feb 11, 2007 2:40 pm    Post subject: Reply with quote

Xk2c wrote:

Code:
set tabstop=4
set expandtab

That's what I was looking for. Thanks.
Back to top
View user's profile Send private message
Dralnu
Veteran
Veteran


Joined: 24 May 2006
Posts: 1919

PostPosted: Mon Feb 12, 2007 12:46 am    Post subject: Re: VIm fancy Reply with quote

tactless wrote:
Slightly better way to do avoid this problem:
Code:
set bg=dark


That solves a major problem I had. Thanks.

I'm going to look through my "Learning the vi editor" book and see if I cann't come up with something handy...
_________________
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Back to top
View user's profile Send private message
Dralnu
Veteran
Veteran


Joined: 24 May 2006
Posts: 1919

PostPosted: Mon Feb 12, 2007 1:07 am    Post subject: Reply with quote

For the coders out there:


So when you go to overwrite a file, there is a backup saved
Code:
set backup


Save said backup to the same dir the file is in:
Code:
set backupdir=.


To see the line numbers next to the lines:
Code:
set number


If you have a thing for wordwraps:
Code:
set wrapmargin=?
Where ? == the point you want the line to break at.


yw
_________________
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Back to top
View user's profile Send private message
dashnu
l33t
l33t


Joined: 21 Jul 2004
Posts: 703
Location: Casco Maine

PostPosted: Mon Feb 12, 2007 1:27 am    Post subject: Reply with quote

emerge aspell aspell-en spellutils


Add this to vimrc

Code:
# Spell Check.
map ^T :w!<CR>:!aspell check %<CR>:e! %<CR>
map ^T \1\2<CR>:e! %<CR>
map \1 :w!<CR>
map \2 :!newsbody -qs -n % -p aspell check \%f<CR>


Those are control chars so you need to type ctrl v ctrl t


handy for mutt users.
_________________
write quit bang
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Mon Feb 12, 2007 8:00 am    Post subject: Reply with quote

Here is my vimrc =)

Code:

"show the 'ruler' in the status bar, that is always show current location.
set ruler

"Tell us what mode we are currently in =)
set showmode

"No auto break line plz
set textwidth=0

"Ignore case search
set ignorecase

"Mouse settings, no mouse window focus
set nomousefocus
"Hide mouse when printing
set mousehide
"xterm functionality
set mousemodel=extend

"No ugly bracketjumpingmatching, DIE EMACS DIE
set noshowmatch

"Expand tabs to 2 spaces, always!
set tabstop=2
set shiftwidth=2
set expandtab

"Use tab for autocompletion
set wildchar=<Tab>
"Allow command completion listing
set wildmenu
set wildmode=longest:full,full

"Replace unknown commands with hex values.
set display+=uhex

"Nice indentation
set autoindent

"I dont like auto saving.
set noautowrite

"No wrap around long lines, let them continue
set nowrap

"Search during type
set incsearch

"Make backspace behave normal
set backspace=2

"Report alot
set report=0

"Allow nice command prompt
set cmdheight=2

"Enable syntax highlightning and some nice filetype associations
syntax enable
filetype on
filetype plugin on
filetype indent on

" Paste with ctrl+v
nmap <silent> <C-v> :set paste<CR>"*p:set nopaste<CR>

" You can use - to jump between windows
map - <c-w>w

",v brings up my .vimrc
",V reloads it -- making all changes active (have to save first)
map ,v :sp ~/.vimrc<CR><C-W>_
map <silent> ,V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>

"Highlight trailing backspaces =)
highlight WhiteSpaceEOL ctermbg=Red guibg=Red
match WhiteSpaceEOL /\s\+$/
autocmd WinEnter * match WhiteSpaceEOL /\s\+$/<CR>

" Load xml fold settings
let g:xml_syntax_folding = 1


Now to my question.

Does anyone know how to make page up/down work and behave like normal? on my laptop they are next to my arrow keys and I hate when i accidently thouch page down when i'm reaching for an arrow key because the marker don't remember where it was when I press page up again.
_________________
From Gentoo with love
Back to top
View user's profile Send private message
Dralnu
Veteran
Veteran


Joined: 24 May 2006
Posts: 1919

PostPosted: Mon Feb 12, 2007 8:07 pm    Post subject: Reply with quote

Remap them to the cursor keys you mean? I'd think that would be fairly simple, I just don't remeber how...
_________________
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Mon Feb 12, 2007 11:15 pm    Post subject: Reply with quote

Dralnu wrote:
Remap them to the cursor keys you mean? I'd think that would be fairly simple, I just don't remeber how...


That would kill the functionality of the keys.. I still want to be able to use them just that if I accidentily press one of them I want to press the other one and be back where I was.
_________________
From Gentoo with love
Back to top
View user's profile Send private message
Dralnu
Veteran
Veteran


Joined: 24 May 2006
Posts: 1919

PostPosted: Tue Feb 13, 2007 12:08 am    Post subject: Reply with quote

Sedrik wrote:
Dralnu wrote:
Remap them to the cursor keys you mean? I'd think that would be fairly simple, I just don't remeber how...


That would kill the functionality of the keys.. I still want to be able to use them just that if I accidentily press one of them I want to press the other one and be back where I was.


Hrm. Best I could say would be see if you cann't remap them in the program (sorry if I wasn't clear).
_________________
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Tue Feb 13, 2007 8:11 am    Post subject: Reply with quote

Dralnu wrote:
Sedrik wrote:
Dralnu wrote:
Remap them to the cursor keys you mean? I'd think that would be fairly simple, I just don't remeber how...


That would kill the functionality of the keys.. I still want to be able to use them just that if I accidentily press one of them I want to press the other one and be back where I was.


Hrm. Best I could say would be see if you cann't remap them in the program (sorry if I wasn't clear).


hmm ok, will have to look at it some more then :/
_________________
From Gentoo with love
Back to top
View user's profile Send private message
numerodix
l33t
l33t


Joined: 18 Jul 2002
Posts: 743
Location: nl.eu

PostPosted: Fri Mar 09, 2007 11:22 am    Post subject: Reply with quote

How do I remap <F2> to save the file regardless of what mode I am in? So far I have
Code:
map! <F2> <ESC>:w<RETURN>i


But this only works in insert mode. I would like it to work in command mode as well.
_________________
undvd - ripping dvds should be as simple as unzip
Back to top
View user's profile Send private message
clock_cycles
n00b
n00b


Joined: 04 Nov 2006
Posts: 47

PostPosted: Tue Mar 13, 2007 5:05 pm    Post subject: C comments Reply with quote

:%s/\(.*\)\(\/\/\)\(.*\)/\1\/\*\3 \*\//

That will make comments like "//" change to C comments like "/* ... */".

\(.*\)
That is any region of text. The \1 and \3 represent regions one and three respectively.

Correct me if I'm wrong.
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Tue Mar 13, 2007 7:44 pm    Post subject: Reply with quote

you know you can use something else than the default delimiter '/', and just FYI there is no need to escape the * at the right side of the second delimiter
so shorter version would be
Code:
%s://\(.*\):/* \1 */:

_________________
The End of the Internet!
Back to top
View user's profile Send private message
numerodix
l33t
l33t


Joined: 18 Jul 2002
Posts: 743
Location: nl.eu

PostPosted: Sat Mar 24, 2007 4:57 pm    Post subject: Reply with quote

numerodix wrote:
How do I remap <F2> to save the file regardless of what mode I am in? So far I have
Code:
map! <F2> <ESC>:w<RETURN>i


But this only works in insert mode. I would like it to work in command mode as well.


Found this out myself by just trying it. :?

Code:
map! <F2> <ESC>:w<RETURN>a
map  <F2> :w<RETURN>
map! <F3> <ESC>:tabnew<RETURN>
map  <F3> :tabnew<RETURN>

_________________
undvd - ripping dvds should be as simple as unzip
Back to top
View user's profile Send private message
w98
n00b
n00b


Joined: 14 Oct 2004
Posts: 20
Location: Los Angeles, CA

PostPosted: Mon Mar 26, 2007 7:49 am    Post subject: Reply with quote

Wow, kinda surprised nobody here has mentioned more about folding, one of my favorite aspects of vim:

Code:
set fdm=marker fmr=[[[,]]]


This essentially turns this code (simple php as an example):
Code:
<?php
function blah ($param1,$param2) //[[[
{
  // my code goes here
  // etc
} //]]]
?>

into something easier to read when wrapped all around a series of functions when you open the file:
Code:
<?php
+--  8 lines: function do_query($sql)//-----------------------------------------
+-- 14 lines: function do_sql($sql,$db=0) //------------------------------------
+-- 22 lines: function save_new_data($tablename,$details) //--------------------
+-- 22 lines: function save_old_data($tablename,$details,$where_clause) //------
+-- 13 lines: function clean_array($array) //-----------------------------------
+-- 11 lines: function get_fields($tablename) //--------------------------------
?>

To expand a folded piece of code, just move your cursor over it, and hit 'zo' for open, or 'zc' to close ... it's awesome for really huge pieces of code. I tend to put these markers around large loops, entire functions, etc.

The square braces can be replaced ... the default is {{{ and }}} respectively, but since most of my (current) scripting work is PHP/Perl, I decided something that wouldn't make it harder to use the '%' key to find matching braces.

For the record, my full .exrc file is
Code:
set tabstop=2 shiftwidth=2 ai ignorecase fdm=marker fmr=[[[,]]] nohls
syntax on

nohls turns off the highlighting during searches, 'ai' is the auto-indent ("set noai" turns it off for pasting), ignorecase obviously forces case-insensitive text searches, and tabstop/shiftwidth have been covered a lot already.

My other favorite, for re-indenting code, is to open a source file, and type
Code:
gg=G
which if I recall calls the 'indent' application to reindent code as best as it can.
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Mon Mar 26, 2007 9:16 am    Post subject: Reply with quote

Instead of using folding markers I would recommend setting up some folding syntax. I have done this once for an xml file. By this way you get around the extremly anoying part of having to insert folding markers in your code (really ugly with bloat). It's a little bit harder to get exactly what you want but alot nicer. If you have ever worked in a project with people not using vi you will know why folding markers is a bad way to go.

Here is an example for an xml file (far from optimal though).
~/.vim/after/syntax/xml.vim
Code:
syn sync fromstart
set foldmethod=syntax
"This variable sets the fold level that you start in
set foldlevel=1
"This variable tells vim depth of nesting to use
set foldnestmax=3
"This sets the color of the folds to distinguish them from
"the rest of the text
highlight Folded ctermbg=DarkGrey ctermfg=DarkCyan

Then add "let g:xml_syntax_folding = 1" to your ~/.vimrc file.

This was taken from the openbox wiki page, go there for more info. http://gentoo-wiki.com/Openbox#Manual_Configuration
_________________
From Gentoo with love
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Tue May 08, 2007 7:04 pm    Post subject: Reply with quote

To everyone who is interested in folding I found this nice little peace of code in the tip section at vim.sourceforge.org

Quote:
Just a note to all fold users,
:set fmr={,}
:set fdm=marker
Is a quick and easy way to allow folding of anything between angle brackets.

then zM closes all folds and zR opens them all.
so I don't know why you need this elaborate solution...


Does someone know a way to determine what kind of file I'm currently viewing in vim? that way one could add this to his/hers vimrc and instant joy will follow. :D

EDIT!

And to follow up on this. I was tipped about a much better way to do it.

put the set's in cpp.vim and put that file in ~/.vim/ftplugin/ and it will load automaticly. =)
_________________
From Gentoo with love


Last edited by Sedrik on Tue May 08, 2007 7:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
Xk2c
Apprentice
Apprentice


Joined: 17 Jul 2004
Posts: 240

PostPosted: Tue May 08, 2007 7:16 pm    Post subject: Reply with quote

Sedrik wrote:
Does someone know a way to determine what kind of file I'm currently viewing in vim? that way one could add this to his/hers vimrc and instant joy will follow. :D


(%R%Y,%{&encoding},%{&fileformat})
_________________
useful Xterm, Aterm and RXVT-Unicode features
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Tue May 08, 2007 7:55 pm    Post subject: Reply with quote

Xk2c wrote:
Sedrik wrote:
Does someone know a way to determine what kind of file I'm currently viewing in vim? that way one could add this to his/hers vimrc and instant joy will follow. :D


(%R%Y,%{&encoding},%{&fileformat})


I found out that this was a little bit of an overkill.. se my previous post (the edited part)
_________________
From Gentoo with love
Back to top
View user's profile Send private message
Sedrik
l33t
l33t


Joined: 08 Apr 2005
Posts: 655
Location: Uppsala, Sweden

PostPosted: Wed May 09, 2007 4:18 pm    Post subject: Reply with quote

A friend of mine tipped me today about this plugin for firefox, checck it out I find the hints (f) quite usefull =)

http://vimperator.mozdev.org/
_________________
From Gentoo with love
Back to top
View user's profile Send private message
smlgbl
Guru
Guru


Joined: 10 Feb 2005
Posts: 305

PostPosted: Wed May 09, 2007 10:40 pm    Post subject: Reply with quote

Sedrik wrote:

Now to my question.

Does anyone know how to make page up/down work and behave like normal? on my laptop they are next to my arrow keys and I hate when i accidently thouch page down when i'm reaching for an arrow key because the marker don't remember where it was when I press page up again.


You could map the keys to make a mark whenever you press them. To retain their original functionality though, it would probably be difficult to use just the opposite key for jumping back to that location. I think of a mapping like this: (I take it you know the mark-feature of vim)
Code:

imap <PageUp> <ESC>mp<C-B>a
nmap <PageUp> mp<C-B>
imap <PageDown> <ESC>mp<C-F>a
nmap <PageDown> mp<C-F>


Then, whenever you press Page-Up or Down, it will set a mark by the name of "p". If you intended to use the Page-Buttons, then it will reset that mark continually, rendering it useless, but you don't care as you anyway wanted to jump around your file. But if you actually wanted to use your normal arrow keys, then you can just press "`p" (without the quotation marks, but with the apostrophe, whatever it's called, the one left of the "1" key and "p") Then you will jump to the mark that you left. You might as well set another mapping for jumping back, if "`p" is to strenuous.
I hope this helped.
_________________
samuel.
'Do not let one girding on boast about himself like one unfastening'
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum