Tuesday, November 14, 2006

vimrc

Post best viewed from here

Ahh what a day. I've spent most of my time ether on the forums or in my beloved editor of choice (vim). I desided for some odd reason to rewrite my vim resource files. I've more or less completed my ~/.vimrc file and will worry about my ~/.gimvrc file later. Really I rarly use the GUI off win32. I basically like using vim in konsole because I can quickly step in and out of editing, ether by forcing vim into the background (control+z, type fg to return to it). Yet because cmd.exe is the worst terminal I have ever used, poor if any support for cut, copy, and paste. Ignores the mouse for the most part and Windows has the tab completion of a fart in the wind. I'm kinda getting used to zsh's after using tcsh so much hehe.

Heres my vimrc file so far, edited for a few things. The syntax is about as simple as a shell script or "vim script" but the " double quote works like the # and // comments in most languages. White space it doesn't care for but it does care about line endings. Since I share most things between Windows XP, PC/Free BSD, and GNU/Linux + several computers I have to be portable in many ways. I started the file on Windows with my file format set for Win/DOS end of lines (:set ffs=dos), vim detects it and uses whats there. I usually set mine as "ffs=dos,unix,mac" so I don't have to convert my files End of Lines (EoL) when I send some one a text file. If I use UNIX eols theres no carriage returns in Notepad, it's too dumb to figure it out unlike many many other editors. Sad through is you can always count on some one to have notepad or a simular editor. Gnomes editor and KDE's KWrite are actually rather nice though. When I tried to run my now complete vimrc on PC-BSD I got a zillion errors and I new I didn't screw it up that bad, infact only one entry was wrong. I quickly figured out it must have been the line feeds, the fact that I had just setup a keybind to strip off the pesky ^M's you get in some files helped hehe. I couldn't find any quick ways to convert the EOLs so I looked them up in Wikipeda and found a way to do it with pearl, I now have a pdos2unix and punix2dos script to do the job when given an input file name and an output file name.

I've been told customizing Vim can be bad b/c of having to work with standard vim/vi but I'm a fruit -> If I want Vim I call vim and if I want Vi I call vi. FreeBSD uses nvi for vi, not vim like some GNU/Linuxes do. If some Linux Distro doesn't make vim start as vi compatible without special changes it's not my problem. I learned to use vim with just the example vimrc file. After that using Vi was easy after an hour or two. I also remember which I'm using by the fact that I call vi as vi and vim as vim + the status line I keep around.

Lines that start with two "'s are comments just for this post
"Terry M. P***** personal vimrc file

"""""""""""""""""""""""""""""""
"Editing Options
"""""""""""""""""""""""""""""""

"Don't be VI compatible - Keep this at top of file !
set nocompatible
""Setting vim to be vi compatible makes changes to make it more pure Vi, I don't care for
""this as this is VIM not VI, if I wanted a pure Vi clone I'd use one.

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
""This makes life a lot easier, just trust me.

" Wrap text at n chars with a line break
set textwidth=80
set wrap
set lbr
"" To keep console portability I used to break my lines around 76~78 char
"" I'm trying this to make Vim more like other editors. Out of the box when  you write
"" a line two long for the screen it continues on the line below and is numbered as one
"" line. With these settings it breaks them like most other editors at my specified
"" 80 chars. Not sure if I will keep it but worth a test. -> Prolly good for Vim newbies

" Use spaces instead of tabs
set expandtab 
set tabstop=6
""I generally like spaces and monospace fonts more for indentation and coding.
""I do like using tabs for manually aligning data in a table in ASCII.

"set min # of spaces for numberwidth. It grows as needed
set numberwidth=2
""This keeps down the size used for the thing /w the line numbers. Defualt is 4.

      """"""""""""""""""""""""""""""
      "Tabbed Editing
      """""""""""""""""""""""""""""""
      set showtabline=1
""Only show the list of tabs when theres more then one. 2=always, 0=never

"set prefered line enders
set ffs=unix,dos,mac
""Type :help ffs for more info, can be set in GVIM via options menu.
"enable filetype detection
filetype on
"turn off ft plugin and indent
filetype plugin off
filetype indent off

"Enable syntax highlighting
syntax on
"" Syntax highlighting is very good, does stuff like making comments blue, keywords green
"" strings red e.t.c. Very nice for markup, scripting, config files, and programming.

"""""""""""""""""""""""""""""""
" Keybindings
"""""""""""""""""""""""""""""""

"Use the ";" as a duplicate of ":" makes life so much easier
"for some odd reason it cannot be followed with a comment on it's line!
:nma ; :
"" I personally think typing ; instead of pressing shift + : is the way it should be

"F1 turns on spellchecking in current buffer
map  :setlocal spell spelllang=en_us
"" I only want spell checking for certain files so this lets us turn it on when we want it
"" and just in the current buffer (like file)

"F2 turn on line numbering
map  :set number
""I don't want line numbering unless it's a source file or a big document. Pressing this
"" key we turn it on when wanted.

"F10 rids us of ^M after carriage returns
map  :%s/^M/ /g
""You have to make the ^M by pressing control+v control+m for this to work.
"" Some times you'll get pesky ^M at all the EOLs and it annoys me - strip them
 
"""""""""""""""""""""""""""""""
"User Interface Options
"""""""""""""""""""""""""""""""
"Always show the status bar with file name e.t.c.
set laststatus=2
"" 0=never, 1=only if more then one file/buffer/tab
"Show %of file remaining in statusbar
set ruler 
"" I use thse two this b/c I like knowing what line/column I'm on un obtusivly + file name
"" and how far into the file overall I am.

    """""""""""""""""""""""""""
    " MOUSE
    """""""""""""""""""""""""""
    "Start with mouse support
    set mouse=a
    "Make pointer an I-Beam in insert mode
    set mouseshape=i:beam
    "Hide the mouse when typing text (GUI only)
    set mousehide 
"" I'm used to being able to scroll around with my mouse wheel :)
"" Try :help mouseshape to look at what you can do with the mouse pointer. X11 supports
"" more options then Windows.

"""""""""""""""""""""""""""""""
"General Preferences
"""""""""""""""""""""""""""""""

"Command history
set history=50
"" Remebers the last 50 commands entered via :command

"automatic re-reading of changed open files
"set autoread
"" Gotta test this, basically if you edit in vim and edit with another app. It will try
"" to re-read the file.

" Switch on search highlighting - use :noh to turn it off after a search
set hlsearch
""highlights all matches to a /search

"ingore case when searching
set ignorecase
"" just like grep -i "I guess"

"set cmd line size
set cmdheight=2
""This makes the command line at the bottom, where you see the ":" when entering commands
"" be 2 lines high. Not really important IMHO
__________________________________________________

Some changes I plan, if it's starting with the GUI I'll have it set it so I can right click on miss spelled words and correct them. you can move the cursor to the word and press z= for a list of corrections, and use ]s and [s to search forward/back. Some times I just scroll with the mouse when proof reading so this helps. You can do a :set "mousemodel=popup_setpos" to get it after you turn on spell checking. I want to set it up so I can quickly convert a files format between DOS and UNIX via F11 and F12, should be possible.

I've downloaded a few things from http://www.vim.org/scripts/ that I want to toy with. One was a pack of 140 themes for gvim gotta sort that hehee. Another was a Matrix screen saver. It's pretty nice if you speed it up but on my system it makes me use like 50~60% CPU judging by GKrellm2 my favorite GTK Krell system monitoring app.

One of the reasons I love vim very much is it's very relaxing to us. Since I play games often as I can get a good tactical one /w my team mates. I do plenty of running. Once the tangos know your there you gotta get moving quickly (Dynamic). So in the intertests of moving as fast as is safe and doing proper B and CB entries (Bang & Breach Bang clear). I have my pinky jutted out to hold shift many times. B/C Usually I don't run all the time, I try to sneak about unless I plan on being Dynamic. So that and using my pinky to make capital letters puts alot of strain on my, now couple that with Escape Meta Alt Control Shift (EMACS) style editing. When I use my pinky to deal with capslock (hate that key), shift, control, z, and Windows. It's nice not to have to strain my fingers or wrists. I find using vim very comfortable for long edits. It's also so dang effective that I can't stand many other editors. Its like the speed and power of Vi/Vim ruins you for other editors once you learn it. I don't claim to be no Vim Master or any thing but to me its gotta be the worlds greatest editor. Vi is in the top 10 in my book but Vim >= #1 xD

The only bad thinkg is some times I press # instead of $. The $ key moves to end of line in normal/visual modes. While the * and # keys searches forward and backwards for the word under the cursor. One thing I'm looking at is a C Refernce that can be ran in Vim, might help me write files on Win32 again. Usually I prefer BSD for doing C work because I can quickly look up a routine via the system manual. After all Unix was written in C and so is largly FreeBSD and I'd reckon most of GNU/Linux which is infact made up of many languages afaik.

No comments:

Post a Comment