Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Vim users: post your cool/useful config tips!
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
dingo
n00b
n00b


Joined: 18 Aug 2002
Posts: 58

PostPosted: Fri Dec 17, 2004 9:59 am    Post subject: Vim users: post your cool/useful config tips! Reply with quote

I Saw alot of topics on vim here, and thought i'd throw in my own .vimrc, its a few years old. I mostly code in C, bash, and python on openbsd

Code:

" key mappings
au BufNewFile,BufRead *.c,*.cpp map <F7> :!make %:r<cr>
au BufNewFile,BufRead *.py map <F7> :!python %<cr>
au BufNewFile,BufRead *.php map <F7> :!php %<cr>
au BufNewFile,BufRead *.c map <F6> :!cc % -o %:r<cr>
au BufNewFile,BufRead *.cpp map <F6> :!g++ % -o %:r<cr>
au BufNewFile,BufRead *.py map <F6> :!python % 
au BufNewFile,BufRead *.c,*.cpp map <F5> :!./%:r<cr>
au BufNewFile,BufRead *.sh,*.py,*.pl map <F5> :!./%<cr>
au BufNewFile,BufRead sshd_config map <f7> :!pkill -HUP sshd
au BufNewFile,BufRead sshd_config,ssh_config map <f6> :!ssh
au BufNewFile,BufRead inetd.conf map <f7> :!pkill -HUP inetd
au BufNewFile,BufRead inetd.conf map <f7> :!telnet localhost
au BufNewFile,BufRead pf.conf map <F7> :!pfctl -f /etc/pf.conf<cr>
au BufNewFile,BufRead pf.conf map <f6> :!pfctl -
au BufNewFile,BufRead pf.conf map <f5> :!tcpdump -ttt -vvv -X -s256 -e -i pflog0

" Terminal Output Filtering
colorscheme desert
au BufNewFile,BufRead *.c,*.cpp set list listchars=tab:·.,trail:·
au BufNewFile,BufRead *.py,*.html,*.sh set list listchars=tab:..,trail:·,extends:»
au BufNewFile,BufRead *.c,*.cpp,*.h set tw=79
au BufNewFile,BufRead *.c,*.cpp,*.h,*.py,*.php set tabstop=3
au BufNewFile,BufRead *.sh,*.html set tabstop=3
au BufNewFile,BufRead *.txt if &tw == 0 | set tw=78 | endif
au BufNewFile,BufRead *.txt set linebreak
au BufNewFile,BufRead *.py set expandtab " write spaces instead of tabs

" Interactive
au BufNewFile,BufRead *.c,*.cpp,*.h,*.py,*.html,*.sh,*.php set autoindent
au BufNewFile,BufRead *.c,*.cpp,*.h,*.py,*.html,*.sh,*.php set smartindent
au BufNewFile,BufRead *.c,*.cpp,*.h,*.py,*.html,*.sh,*.php set backspace=indent,start
au BufNewFile,BufRead *.c,*.cpp,*.py,*.php set shiftwidth=3
au BufNewFile,BufRead *.py set smarttab   " backspace over expandtab
au BufNewFile,BufRead *.sh,*.html set shiftwidth=2
au BufNewFile,BufRead *.sh,*.py,*.html set nowrap
au BufNewFile,BufRead *.sh,*.py,*.html set go+=b " horizontal scrolling
au BufNewFile,BufRead *.txt set joinspaces " wo spaces after punctuation on J

"set expandtab

" reading Ms-Word documents, requires antiword
au BufReadPre *.doc set ro
au BufReadPre *.doc set hlsearch!
au BufReadPost *.doc %!antiword "%"

" Terminal Input
set nocompatible      " Use Vim defaults

" Terminal Output
set ttyfast         " fast terminal connection, redaws cleaner
set lazyredraw         " slow terminal
set showcmd
set ruler
" Colors
syntax on

"set backup                         " Keep a backup file

"Scratch Pad - enable/disable as needed
"
"set tw=79                         " force oldschool text width
"set tabstop=2
"set shiftwidth=2
"set softtabstop=2
"set pastetoggle=<F11>              " f11 for pasting or turning on/off indent
"set list listchars=tab:»·,trail:·  " Highlights tabs
"set list listchars=trail:»
"set list listchars=trail:·
"set viminfo='999,\"999             " Read/write a .viminfo file
"set history=9999                   " 50 lines of command history
"set modelines=0                    " Gentoo security advisory

" Searching   
"nnoremap <CR> :noh<CR><CR>   " Un-highlight text after when enter
set hlsearch         " highlight searches
set ignorecase         " case insensitive searches
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
  set fileencodings=utf-8,latin1
endif

if &term=="xterm"
  set t_RV=          " don't check terminal version
  set t_Co=8
  set t_Sb=^[4%dm
  set t_Sf=^[3%dm
endif

if has("gui_running")
  if has("gui_gtk2")
    set guifont=Courier\ New\ 29
  elseif has("x11")
   " You may want to lower the font size or change font types.
    "I run 1280x1024 or higher, and this is the largest terminal-like
    "font i can stand.
    set guifont=-adobe-courier-*-r-*-*-12-*-*-*-*-*-*-*
  else
    set guifont=Courier_New:h20:cDEFAULT
  endif
endif

" Jump to last cusor location
au BufReadPost *
      \ if line("'\"") > 0 && line ("'\"") <= line("$") |
      \   exe "normal g'\"" |
      \ endif
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 16102
Location: Colorado

PostPosted: Fri Dec 17, 2004 6:22 pm    Post subject: Reply with quote

This is likely to become a repository where people post their .vimrc files. While not a bad thing, it isn't really appropriate for DT&T.


Moved from Documentation, Tips & Tricks.
_________________
lolgov. 'cause where we're going, you don't have civil liberties.

In Loving Memory
1787 - 2008
Back to top
View user's profile Send private message
dingo
n00b
n00b


Joined: 18 Aug 2002
Posts: 58

PostPosted: Fri Dec 17, 2004 7:24 pm    Post subject: Reply with quote

All kinds of tips and tricks in there, ah well.
Back to top
View user's profile Send private message
rezza
Guru
Guru


Joined: 09 Apr 2003
Posts: 434
Location: Edinburgh, UK

PostPosted: Fri Dec 17, 2004 7:43 pm    Post subject: Reply with quote

A few good ideas in there. Mine is here, but I'm gonna merge some of your stuff into mine soon.
_________________
screenshots
blog
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Sat Dec 18, 2004 2:16 am    Post subject: Reply with quote

8O Woah that's pretty hefty.

Anyway, here's mine:
Code:
:se nu
:set printoptions=number:y
:set nocompatible
:set tabstop=2
:set expandtab
:set shiftwidth=1
:set autoindent
:set autowrite
Then again, I likely have yet to do more than scratch the surface of Vim's capabilites.
:)
_________________
~~ Peter: Brony, GNU/Linux geek, caffeine addict, and Free Software advocate.
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
Irom
Tux's lil' helper
Tux's lil' helper


Joined: 07 Oct 2003
Posts: 91
Location: am arsch..

PostPosted: Sat Dec 18, 2004 11:43 am    Post subject: Reply with quote

Here are a few vim-things I can't live without anymore:

Code:
  nnoremap <silent><F12> :set hls!<cr>
  inoremap <silent><F12> <Esc>:set hls!<cr>a
  nnoremap <silent>n :set hls<cr>n
  nnoremap <silent>N :set hls<cr>N
  nnoremap <silent>* :set hls<cr>*
  nnoremap <silent># :set hls<cr>#
  nnoremap <silent>/ :set hls<cr>/
  nnoremap <silent>? :set hls<cr>?
This toggles the highlighting of the last search with F12. It's automatically turned on again with a new search.

Code:
  nmap <silent><F6> :m+<CR>
  nmap <silent><F5> :m-2<CR>
  imap <silent><F6> <esc>:m .+1<CR>a
  imap <silent><F5> <esc>:m .-2<CR>a
  vmap <silent><F6> :m '>+<CR>gv
  vmap <silent><F5> :m-2<CR>gv
This moves the current line or selection one line up/down with F5/F6

Some small maps:
Code:
" toggle "list" with F10
  noremap  <silent><F10>      :set list!<cr>
  inoremap <silent><F10> <ESC>:set list!<cr>a

" toggle "paste" with F11
set pastetoggle=<F11>

" switch between buffers with F7 and F8
  nnoremap <silent><F8>  :bn<cr>
  inoremap <silent><F8> <Esc>:bn<cr>
  nnoremap <silent><F7>  :bp<cr>
  inoremap <silent><F7> <Esc>:bp<cr>


My full configuration is here. Comments in German, sorry. But there is always :help.
_________________
http://ftp.fukt.bsnet.se/pub/movies/stallman/ (Please watch this before you form an opinion about GNU)
http://apfelboymchen.net/gnu/


Last edited by Irom on Sat Jan 08, 2005 1:13 am; edited 1 time in total
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Dec 18, 2004 12:05 pm    Post subject: Reply with quote

on a related note, if you edit ebuilds with vim you'll like:
Code:
emerge gentoo-syntax

I have a feeling it's gonna become a lot longer once I have time to look through all of yours', but here's my extremely newbish setup:
Code:
map <F1> <ESC>
map! <F1> <ESC>
nmap <F1> <ESC>
vmap <F1> <ESC>
omap <F1> <ESC>
cmap <F1> <ESC>
imap <F1> <ESC>
set nohlsearch
filetype plugin on
filetype indent on

basically I got sick and tired of hitting F1 instead of ESC on my laptop and of the persistent search highlighting.

vim is awesome; thanks to all who post.
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Tue Dec 27, 2005 6:40 pm    Post subject: Vim users: post your cool/useful config tips! Reply with quote

I apologize if this has been posted before, but I searched via the forums search tool and Google's "site:forums.gentoo.org" query and did not find anything similar....

Vim users, what "cool," "nifty," or other useful options do you use in your .vimrc files? Mine (Windows at work) consists of:
Code:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin


set nu
set noexpandtab
set tabstop=4
colorscheme koehler
set guifont=Bitstream_Vera_Sans_Mono:h11
Ok so it's nothing special, but it works lovely.

Share yours! :)
_________________
~~ Peter: Brony, GNU/Linux geek, caffeine addict, and Free Software advocate.
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
Chaosite
Guru
Guru


Joined: 13 Dec 2003
Posts: 540
Location: Right over here.

PostPosted: Tue Dec 27, 2005 6:57 pm    Post subject: Reply with quote

Well... Every vimrc discussion should probably include ciaranm's huge-ass one.

Thar be dragons.

URL tag fixed up. --codergeek42
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Tue Dec 27, 2005 6:59 pm    Post subject: Reply with quote

Chaosite wrote:
Well... Every vimrc discussion should probably include ciaranm's huge-ass one.
8O

Holy jeebus. *goes off to try to understand it*
_________________
~~ Peter: Brony, GNU/Linux geek, caffeine addict, and Free Software advocate.
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
syscrash
Guru
Guru


Joined: 14 Apr 2003
Posts: 541

PostPosted: Tue Dec 27, 2005 7:05 pm    Post subject: Reply with quote

Code:
version 6.0
if &cp | set nocp | endif
let s:cpo_save=&cpo
set cpo&vim
map! <S-Insert> *
map! <xHome> <Home>
map! <xEnd> <End>
map! <S-xF4> <S-F4>
map! <S-xF3> <S-F3>
map! <S-xF2> <S-F2>
map! <S-xF1> <S-F1>
map! <xF4> <F4>
map! <xF3> <F3>
map! <xF2> <F2>
map! <xF1> <F1>
map Q gq
map <xHome> <Home>
map <xEnd> <End>
map <S-xF4> <S-F4>
map <S-xF3> <S-F3>
map <S-xF2> <S-F2>
map <S-xF1> <S-F1>
map <xF4> <F4>
map <xF3> <F3>
map <xF2> <F2>
map <xF1> <F1>
let &cpo=s:cpo_save
unlet s:cpo_save
set autoindent
set background=dark
set backspace=2
set fileencodings=ucs-bom,utf-8,default
set guifont=Bitstream\ Vera\ Sans\ Mono\ 8
set guioptions=agimrLt
set history=50
set hlsearch
set nomodeline
set mouse=a
set mousemodel=popup
set ruler
set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.info,.aux,.log,.dvi,.bbl,.out
set termencoding=utf-8
set viminfo='20,\"500
if has("gui_running")
colorscheme brookstream
endif
set nu
set nohlsearch


Nothing special in there, just the colorscheme part (which only takes effect in gvim so that your command-line vim won't have crazy colours.)
_________________
Play ET? Come by #gentoo.et on freenode!
http://syscrash.ca
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Thu Jan 05, 2006 11:13 pm    Post subject: Reply with quote

No one else uses (g)vim? How disheartening. :(
_________________
~~ Peter: Brony, GNU/Linux geek, caffeine addict, and Free Software advocate.
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
jakamaka
Apprentice
Apprentice


Joined: 17 Jun 2004
Posts: 266
Location: My self-sustainable fusion of thought

PostPosted: Thu Jan 05, 2006 11:27 pm    Post subject: Reply with quote

codergeek42 wrote:
No one else uses (g)vim? How disheartening. :(


I can actually work faster with plain old vim.
_________________
It would be more interesting to learn from children, than try to teach them how to behave, how to live and how to function. - U.G. Krishnamurti
Back to top
View user's profile Send private message
Zepp
Veteran
Veteran


Joined: 15 Mar 2004
Posts: 1246
Location: Ontario, Canada

PostPosted: Fri Jan 06, 2006 2:04 am    Post subject: Reply with quote

codergeek42 wrote:
No one else uses (g)vim? How disheartening. :(


I usually use gvim, but I just started using vim so I still got a get a handle on it all :P
_________________
Every iPhone is a gift from God.
Back to top
View user's profile Send private message
Fenster
Apprentice
Apprentice


Joined: 26 Oct 2004
Posts: 172
Location: Purgatory

PostPosted: Fri Jan 06, 2006 2:22 am    Post subject: Reply with quote

Code:
set guifont=Bitstream_Vera_Sans_Mono:h11
set textwidth=150
set formatoptions-=t
set mouse=a
set ruler


My settings are as they are because I use vim to write drafts of documents which I later clean up using OO.

Same font as codergeek too, hah. :D
_________________
photography - geekery
Back to top
View user's profile Send private message
hermes_jr
l33t
l33t


Joined: 26 Feb 2004
Posts: 702
Location: Moscow, Russia

PostPosted: Fri Jan 06, 2006 2:37 am    Post subject: Reply with quote

Code:

set whichwrap=b,s,<,>,[,]
startinsert
colorscheme desert
set guioptions=agimrLt
set ignorecase
set nohlsearch
set tabstop=4
set number
set mousef
set nowrap
set tildehide

As for startinsert, ignorecase and whichwrap - all clear, just simulating common text editors behaviour. And tildehide... Well this one is more like useless, but on the other side is something unusual (so I guess it worth posting here :lol:)
_________________
registered linux user #347998, киботеизм во веки веков
Back to top
View user's profile Send private message
TNorthover
Guru
Guru


Joined: 25 Jan 2004
Posts: 434
Location: Edinburgh, UK

PostPosted: Fri Jan 06, 2006 10:53 am    Post subject: Reply with quote

jakamaka wrote:
I can actually work faster with plain old vim.


I use gvim, but only because I think it looks better than plain vim (the fonts I like for coding are different ones than for shell-work). I can't remember the last time I used the mouse in it.
Back to top
View user's profile Send private message
rezza
Guru
Guru


Joined: 09 Apr 2003
Posts: 434
Location: Edinburgh, UK

PostPosted: Fri Jan 06, 2006 11:26 am    Post subject: Reply with quote

Mine. I use vim 7.
_________________
screenshots
blog
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Fri Jan 06, 2006 11:29 am    Post subject: Reply with quote

you can use
Code:
:x
instead of
Code:
:wq
to save and exit. ;)
Back to top
View user's profile Send private message
Butts McCokey
Advocate
Advocate


Joined: 23 Apr 2004
Posts: 3327

PostPosted: Fri Jan 06, 2006 12:41 pm    Post subject: Reply with quote

how do you set it to use ctrl+v and ctrl+c etc that normal ones use?
_________________
Since the bible and the church are obviously mistaken about where we came from, how can we trust them with where we're going?

"An eye for an eye will make us all blind" - Gandhi

Cold is gods way to tell us to burn more Catholics
Back to top
View user's profile Send private message
mark_alec
Bodhisattva
Bodhisattva


Joined: 11 Sep 2004
Posts: 6066
Location: Melbourne, Australia

PostPosted: Fri Jan 06, 2006 12:49 pm    Post subject: Reply with quote

allucid wrote:
Code:
:x
Or you can
Code:
ZZ

_________________
www.gentoo.org.au || #gentoo-au
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Fri Jan 06, 2006 4:28 pm    Post subject: Reply with quote

That's cool, rezza. Thanks. :)
_________________
~~ Peter: Brony, GNU/Linux geek, caffeine addict, and Free Software advocate.
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
Butts McCokey
Advocate
Advocate


Joined: 23 Apr 2004
Posts: 3327

PostPosted: Sat Jan 07, 2006 12:13 am    Post subject: Reply with quote

how do i make all the weird controls work like other editors? I'm too lazy to learn.
_________________
Since the bible and the church are obviously mistaken about where we came from, how can we trust them with where we're going?

"An eye for an eye will make us all blind" - Gandhi

Cold is gods way to tell us to burn more Catholics
Back to top
View user's profile Send private message
TNorthover
Guru
Guru


Joined: 25 Jan 2004
Posts: 434
Location: Edinburgh, UK

PostPosted: Sat Jan 07, 2006 9:53 am    Post subject: Reply with quote

cokehabit wrote:
how do i make all the weird controls work like other editors? I'm too lazy to learn.


Probably the easiest way:
Code:
su
rm /usr/bin/vim
ln -s /usr/bin/nano /usr/bin/vim
Back to top
View user's profile Send private message
sn4ip3r
Guru
Guru


Joined: 14 Dec 2002
Posts: 325
Location: Tallinn, Estonia

PostPosted: Sat Jan 07, 2006 10:03 am    Post subject: Reply with quote

TNorthover wrote:
cokehabit wrote:
how do i make all the weird controls work like other editors? I'm too lazy to learn.


Probably the easiest way:
Code:
su
rm /usr/bin/vim
ln -s /usr/bin/nano /usr/bin/vim


No, :wink:
Code:
echo "set insertmode" >> ~/.vimrc
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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