![]() |
| | #1 |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| It's also the most poorly documented, so what I did want to do was start a new thread here in the "Product Review" board where people could ask stuff like "How can I see the value of a defined variable?" (the answer is here; "[i" works in escape mode) I'm sure there are some other programming software products around that could have an even more popular thread, but I'm not going to start any of them ![]() Here's the wikipedia entry for the curious: http://en.wikipedia.org/wiki/Vim_(text_editor) And the actual homepage is welcome home : vim online. I recommend against the use of the GUI. There is nothing wrong with it, but it is unnecessary and the functionality cannot be improved upon with tradition pull down menus and tabs (learn to use a keyboard, you are a computer programmer!). Plus, there is nothing like being able to use your absolute favourite tool even when you don't have a graphical desktop, and not have to remember how to get things done without a mouse to click and point things at. If you are new to the whole concept, two commands which work in escape mode that you might want to get to know are :split This splits the window in half horizontally, and if you include a filename loads it. You can also split the window unevenly (try ":help split"). To move back and forth, use ctrl-ww. :e # This will reload the last file, handy for flipping back and forth. Vim is standard on almost all unix derived operating systems including linux, and available for all of them (including MAC OS). There is even a windows and DOS version. However, the package included with your linux distro probably leaves a lot to be desired. It is easy to compile from source, however (choose the "huge" option to get the most functionality). A quick test of your installation is to try "vim --remote": you should be able to type: vim --remote mycode.c to send a file to the currently running (or first) instance of vim in any terminal anywhere on your desktop. This is very handy since you can add this command to your filebrowser, and just have one fullscreen, non-GUI vim in a terminal somewhere. If it doesn't work, your install doesn't have all the vim features and you should uninstall it and build from the source. Here's a simple ~/.vimrc that demonstrates some basic and essential configuration (the double quote " starts a comment): Code: " .vimrc
" syntax highlighting, line numbering, etc on by default
:syntax enable
set number
set nowrap
set bs=indent,eol,start " allow backspacing over everything in insert mode
" you probably want all the syntax colors to work in your terminal
" here's how to set them for contrast
" numbers and color names are interchangable
hi Statement ctermfg=7
hi LineNr ctermbg=0 ctermfg=4
hi Comment ctermbg=7 ctermfg=darkblue
hi PreProc cterm=bold
hi Type ctermfg=6
hi Identifier ctermfg=2
hi Number cterm=underline ctermfg=6
hi Conditional cterm=bold ctermfg=3
hi Repeat cterm=bold ctermfg=1
hi Constant ctermfg=3
hi StatusLine cterm=bold ctermfg=green ctermbg=darkmagenta
hi StatusLineNC ctermfg=darkgray ctermbg=white
" key bindings (these just print things in appropriate places to save typing)
" cmap works in escape (aka command) mode, eg, for when loading a file
:cmap <F2> /root/code/
" imap works in insert (aka editing) mode
:imap <F2> printf("\n"); fflush(stdout);
:imap <F3> 12345678901234567890
" that last one is for counting string lengths...
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge Last edited by MK27; 04-24-2009 at 09:57 AM. |
| MK27 is offline | |
| | #2 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,422
| > I recommend against the use of the GUI. Going against what the authors recommend? Why? They suggest gvim because of the 256 native colour support, along with various other things (encoding, the terminal doesn't get in the way etc). I'd suggest using gvim and turning off the menu / toolbar. That way it's exactly the same if you SSH into another box and cannot pipe X (who would anyway?). And it allows you to enjoy 256 colours in the mean time. Otherwise, +1 for spreading vi/m. And down with Emacs! Last edited by zacs7; 04-24-2009 at 09:48 AM. |
| zacs7 is offline | |
| | #3 |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| I wouldn't use it just for the colors, 16 seems enough for text (there's not that many syntax categories anyway), and you can make those 16 colors any combination of millions via the terminal (at least, most modern X terminals -- which also allow tabbing). Also, I really like a transparent background, which you can't get with the GUI. You know, no window borders, all see-thru: that classic linux power user look. Regarding "the terminal getting in the way", you may have to short circuit the esc key shortcut if there is one, but that's a fairly simple point and click task witht the terminal interface. I guess I should have added: Just don't use xterm! Emacs is definitely a creepy beast. But I never got into it.
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge Last edited by MK27; 04-24-2009 at 10:49 AM. |
| MK27 is offline | |
| | #4 |
| Registered User Join Date: Apr 2009
Posts: 1
| On large documents I've noticed a significant performance hit with gvim vs terminal vim when interacting with the mouse on blocks of text, and with scrolling. The extra colors can look really sharp, true, but as far as I can see the only true benefit to gvim is integration with system open/save dialogs -- and NERDTree is a great replacement for that even. Terminal Vim has tabs, splitscreen, and everything else. You can even turn on mouse control and be able to select dynamically, point/click to locate the cursor, resize the split windows, click an 'X' to close a tab, etc. It seems like every day I learn something new or a new way to do something in Vim. Programming auto-complete dropdowns, using ctags and taglist, etc. I don't know about best, but Vim is certainly in the upper echelon of best applications of all time. |
| birnam is offline | |
| | #5 | |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| Quote:
Anyway, all the things birnam mentions are pretty cool in so far as I am familiar with them. The i-mode ctrl-x autocompletion/autoreplace stuff is almost psychotic (if you have an IQ of like 160, it must be amazingly handy), which is why I thought I'd mention something essential to newbies that I didn't think of in the OP: :u vim undo! :redo vim redo! because it ain't hard to do crazy things by accident (I think they have run out of ctrl-alt-meta-shift combinations).
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge | |
| MK27 is offline | |
| | #6 |
| Registered User Join Date: May 2006
Posts: 161
| Being a Windows user, I was also raised with a silver mouse in my hand. Applications offering sleek GUI, animated tool-tips and decorated buttons are all around the place. These applications take eye-candy further and further, but forget one important thing: Efficiency. As Mad_Guy fanatically put it time and again, it all boils down to efficiency. VIM allows you just that, so I'll leave you to youtube VIM and see it in action rather than describe it in words. VIM is complete, yet minimalistic in nature. Gives you full control over your code, yet can automate all the boring chores. Takes time and effort to learn, yet pays off once you get to know it. Note: You should know proper touch-typing to actually be efficient. |
| glo is offline | |
| | #7 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,422
| Speaking of which, a little "question" Use ESC, Ctrl + C, Ctrl + [ or rebind capslock for Insert -> Normal mode? |
| zacs7 is offline | |
| | #8 |
| pwns nooblars Join Date: Oct 2005 Location: Portland, Or
Posts: 1,094
| Though I am no longer using VIM, I did use it for a long time and used capslock to go back to normal mode. |
| Wraithan is offline | |
| | #9 | |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| Quote:
If you are totally new to vim understanding those two modes (there are some other non-essential ones) is task #1. Here's my tips o' the day: You can read in (that is, have them processed, not read them into the text display) script files (like the sample .vimrc from my OP) with :source ~/vimscripts/somescript That includes ~/.vimrc itself, so you can reconfigure without restarting. In addition to just loading a set of imap/cmap macros, there is a whole language for vim scripts including loops, arrays, etc (and more internal functions than I want to count)*. You can set a "bookmark" to the current line while in command mode by pressing "m" and then another (upper or lower case) character, eg, "X". To return to that position, use ` (the backtick) and the same character. As long as the file remains in place, vim will remember your bookmarks between invocations; so for example if you have "mX" previously set in some other file, if you don't reset it, "`X" will take you to that line in that file. I have noticed the functionality with this is not perfect (eg, you can lose bookmarks if you mod the file enough) but it generally works. You can get a list of all your existing bookmarks with: :marks Here's a quite extensive and well written "Vim Reference" that is independent of the official documentation -- organized differently, etc, so it provides a good contrast (and is definately better indexed): VIM Reference Guide Remember, you can try consulting vim itself on some topic (eg, "recording") with: :help recording ![]() * this is actually how the syntax highlighting files are made. In addition to the hundred or so standard, included ones, there are also syntax files available for lots of C (etc) API's that can be added onto the top of the base language (eg, there's one for gtk and openGL). Those can be googled; one place to start is vim.org itself: http://www.vim.org/scripts/
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge Last edited by MK27; 04-29-2009 at 11:40 AM. | |
| MK27 is offline | |
| | #10 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,763
| Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is online now | |
| | #11 |
| pwns nooblars Join Date: Oct 2005 Location: Portland, Or
Posts: 1,094
| Capslock is closer in than ESC, I use several capslock keybindings and have the capslock function itself disabled. IF I NEED TO SHOUT I CAN JUST TYPE WITHOUT ONE OF MY PINKIES AND HOLD DOWN SHIFT. |
| Wraithan is offline | |
| | #12 | |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,422
| Quote:
Oh and you forgot to mention, turn of vi compatibility mode, because even the bugs are mimicked. Here's my .vimrc if anyone cares. Code: " zac's vimrc " Wed Feb 11 07:28:14 UTC 2005 " func set nocompatible " non vi compatible set nobackup " no backup files (~) set history=64 " command line history " searching set incsearch " incremental searching set ignorecase " case insenitive search set smartcase " if search has uppercase letters then search is case-sensitive " behaviour " backspace over everything in indent mode set backspace=start,indent,eol set mouse="" " no mouse support in X11 set confirm " always :confirm on exit " complete options set completeopt=menu,longest,preview " appearance set number " line numbers set ruler " ruler set showcmd " display incomplete commands set showmatch " show the matching bracket for the last ) set nowrap " no wrapping syn on " syntax highlighting set showtabline=2 " tab bar at the top " indenting set tabstop=3 " tab = 3 spaces set expandtab " space tabs set cindent set autoindent set smartindent " colour scheme colorscheme delek Last edited by zacs7; 04-29-2009 at 03:49 PM. | |
| zacs7 is offline | |
| | #13 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 11,317
| The thing everyone wants to know when they run it for the first time: :q Quit :w Save :wq Save and quit. :q! Quit without saving. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #14 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,044
| In addition to quzah's post, here are some other commands that everyone should know: i or a Enter insert mode. i will place the cursor before the currently selected character, and a will place the cursor after. ESC Go back to command mode. You may need to press esc twice if you are in some states (like the text search state). / Search for text * Search for occurences of the word that is currently under the cursor. n Go to the next search result. N Go to the previous search result. == Correctly indent the current line. =G Indent the from the cursor location to the end of the file. This command is great for when you paste some non-indented (or poorly indented) code into a vim buffer. |
| bithub is offline | |
| | #15 | |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| Quote:
<<works the opposite way. Multiple use of either one will, surprise surprise, add or remove more tab stops. Ie, you can shift entire blocks right or left this way.
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge Last edited by MK27; 05-02-2009 at 07:30 AM. | |
| MK27 is offline | |
![]() |
| Tags |
| "vi", vim |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| pthreads, I created the thread, passed a function, function never runs. | mr_coffee | Linux Programming | 2 | 02-26-2009 11:48 PM |
| Terminating secondary thread from another thread | wssoh85 | C++ Programming | 13 | 12-19-2008 05:14 AM |
| CreateThread ?! | Devil Panther | Windows Programming | 13 | 11-15-2005 10:55 AM |
| pointer to main thread from worker thread? | draegon | C++ Programming | 2 | 10-27-2005 06:35 AM |
| Critical Sections, destroying | Hunter2 | Windows Programming | 4 | 09-02-2003 10:36 PM |