Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
astr0man
Feb 21, 2007

hollyeo deuroga
It's been a really long time since we have had a vim thread, but seeing as how it is the greatest text editor in existence I think we need one. Feel free to make any suggestions and I will add them to the OP.

vim.org posted:

What Is Vim?

Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.

Vim is often called a "programmer's editor," and so useful for programming that many consider it an entire IDE. It's not just for programmers, though. Vim is perfect for all kinds of text editing, from composing email to editing configuration files.

What Vim Is Not?

Vim isn't an editor designed to hold its users' hands. It is a tool, the use of which must be learned.

How do I use vim?
  • Install vim and then run vimtutor. Also, see the basic tutorial post after the OP.
  • Set up a not terrible .vimrc (see the end of the OP for recommendations).
  • Unplug your mouse (not really, but you should really get used to not relying on using your mouse).
  • Also remember that :he(lp) is your friend!

In TYOOL 2013 why don't you just use an IDE

IDE's are great and all, but there are times when some people have to SSH into a headless box and edit code. When that happens you will be thankful that you know vim instead of having to fight through using nano or something. Also, it may be hard to believe, but not having to ever touch your mouse may actually increase your productivity as a developer.

A properly configured vim will provide you with almost all of the functionality of a modern IDE. Tagfiles give you the basic functionality to jump to function/object/class declarations just like an IDE does. Other plugins will let you do fancier things like add autocompletion, and auto updating of your tagfiles.

Resources

Recommended Plugins

Plugin Management
  • vundle - It's basically like Ruby's bundler, as in it uses a "Gemfile"-like directives to download your plugins automatically for you.
  • vim-pathogen - In practical terms, pathogen.vim makes it super easy to install plugins and runtime files in their own private directories.
vundle and pathogen do essentially the same thing. If you like managing git stuff yourself pathogen works fine. If you want something that will do all the work for you use vundle.

General
  • vim-sensible - Basic vim settings that everyone should use. If you don't have a vimrc this is a good place to start.
  • vim-taglist - Provides a vim window with a navigable list of available tags.
  • NERDTree - File system browser that works from inside vim. Preview here.
  • pyclewn - Use vim as a frontend to GDB
  • ctrlp - I can't live without this any longer. Fuzzy searching is amazing and completely removes the need for any kind of folder navigation if your work is contained to one folder.
  • vimwiki - personal wiki written in markdown. Dump it in Dropbox and you have all your notes always available anywhere. I switched from OneNote/Evernote to this because I dislikep proprietary formats.
  • vim-commentary - language-agnostic commenting out of any block of code. Incredibly useful.
  • vim-textobj-user, vim-textobj-entire, vim-repeat - a few generic utilities that are pretty mandatory
  • vim-matchit - smart jumping between opening and closing tags with <C-5>, very useful in HTML editing
  • syntastic - Syntax checker
  • vim-indent-guides — useful when you deal with layout-based languages
  • vim-unimpaired — some useful mappings like inserting new lines above/below or moving text blocks up/down
  • Tabular — aligning text (e.g. :Tab /^[^=]*\zs=/l1l1 to align assignments)
  • vim-powerline — a good statusline thing

Language specific
  • python.vim - Improved Python syntax handling. The default python syntax stuff in vim is OK, but if you do any serious Python work you should use this instead.
  • vim-flake8 - PyFlakes integration. Provides Python syntax and pep8 checking from within vim.
  • clang-complete - Intellisense for C, C++ and Objective-C!
  • vim-coffee-script - amazing plugin for CoffeeScript editing. The live compiled CS code buffer is very nice.
  • vim-fireplace / paredit - Clojure specific, make developing Clojure without Emacs fairly tolerable.

Source Control
  • vim-fugitive - A git wrapper. Provides easy access to git commands from within vim. Also, vim-fugitive will make vim look for tagfiles inside .git/ if you are inside a git repo, so you don't have to worry about relative paths and crap for your tags.
  • git-ctags - This isn't actually a vim plugin, but if you are using vim-fugitive you should also use this anyways. It will auto-update your tagfiles when you make a git commit.

IDE integration
  • VsVim - Vim Emulation for Visual Studio 2010 and later. Free!
  • ViEmu - Another vim emulation thing for Visual Studio. Costs $100, but supports older VS versions and MS Word.
  • Eclim - Some thing that integrates Eclipse into vim. I've never used this but I think a lot of people like it?

Goon .vimrc's

astr0man fucked around with this message at 21:54 on Jun 20, 2013

Adbot
ADBOT LOVES YOU

astr0man
Feb 21, 2007

hollyeo deuroga
:eng101: Basic Tutorial :eng101:

This was shamelessly stolen from an archived vim thread

Modes
The aspect of vim that most shocks newcomers is that is modal - that is, the program has various different modes of operation, and you will find it extremely hard to avoid them if you want to use vim to its full potential.

By default, vim will start in normal mode. In this mode, you simply navigate the text using the h, j, k and l keys - or the normal arrow keys if you want- and press other keys to perform operations on the text. You cannot insert text in this mode. It's often best to think of normal mode as a baseline state for the editor - it's easy to get back to. If you get mired, stuck, don't know what to do, just press the Escape key until vim starts beeping at you, and you're back in normal mode, ready to try again. Remember that - the escape key is your escape key

By pressing the i or insert key, you can enter insert mode. In fact, there are a number of ways to do this starting from normal mode. To place the cursor before the current character, press i. To place it after, press I. To place it at the start of the current line, press A. To place it at the end of the line, press a. To create a new line above the cursor and move to the beginning, press O - below the cursor, press o. The text -- INSERT -- will appear at the bottom of the vim screen and you will be able to type away to your heart's content.

The third major mode is visual mode. This is usually entered from normal mode in a variety of ways, although it is possible to enter from insert mode if you wish. However, we'll focus on entering from normal mode - it is this way that the greatest magic can be peformed. Visual mode, in essence, allows you to select regions of text to perform actions on.

Absolute basics
So let's try something out. Open up vim, and have a look. If you haven't already customised vim, you'll see something similar to the screenshot above, and be in normal mode. The first thing we're going to do is exit vim - one of the things that has caught out many a UNIX newbie on the command line. In the GUI age it's not quite as relevant, but always worth knowing. To do this, from normal mode, type :q<enter>(colon qthen press the enter key). This will exit vim. Simple! You can also type :q!<enter> to exit and abandon any changes you've made to the document without prompting.

Now let's take a quick look at the help file. Again in normal mode type :he - short for :help which also works. This is something to note - any command you type starting with a colon is usually short for something else. If you want to know what it's short for, press Tab and vim will complete the command for you. Now , we should be looking at a split window- one a blank document, and the other showing some documentation. It's a good idea to read this. If you want help on a specific topic and know how to refer to it, type :he topicname and vim will take you right there if it knows the topic. To exit the help, type :q. You'll be back at your blank document again.

Now let's type and edit something. Enter insert mode, and type out anything you like. Make it a few lines long by pressing <enter> a few times as you would in any other editor. Make a few typos. Next, choose a typo. Imagine, for a moment, you've tried to type the wort emacs, but ended up with rtmacs. This is, of course, wrong. But easy to correct. Return to normal mode, and navigate to the start of the word. In normal mode, the w and b move the cursor forward and backward by one word at a time respectively. Place the cursor on the start of the word rtmacs, and still in normal mode type x. Your delete and backspace keys will also still work, though backspace will only work in insert mode usually. x is the key to delete the text under the cursor, so you should be left with the word tmacs. Now we need to replace that errant t. Place the cursor on the t, then press r, then type E. The t will be replaced by a capital E, and all will be well.

You can also repeat normal-mode commands easily. If you've just performed a command such as this and want to do it again, move to the place where you want to repeat it and press . (dot, full stop, period - whatever you call it). This is especially useful when you run a command consisting of many keystrokes. Another way to repeat command sequentially is to prefix it with a number - to delete 5 lines starting with the current one, type 5dd - 5 is the number of times to perform the command, the first d is the command (delete) and the second d tells the delete command to operate on whole lines. Ergo, 5 lines (if that many exist) will be deleted. You might want to delete 3 words including the current word - the command would be 3daw for completeness. You may have deciphered the format of vim commands of this type now - optional count, followed by the command, followed by the 'motion'. In this case, 'delete 3 entire words', or '3 times delete entire word'. To delete the two words after the current one, but leave half of the current word intact, place the cursor on earliest letter you wish to delete, and type 2dwp - see the difference? aw is the motion to represent entire words, regardless of the cursor position, and w represents from the cursor until the end of the word.

Vim contains a multitude of commands such as these for all sorts of purposes. I'll not go into them all here because this is already getting long-winded.

Visual mode and the ex line
Now we'll take a quick look at visual mode. Return to normal mode, and we'll start.

To enter visual mode in the simplest way, press the v key, and move the cursor about. Some text will be highlighted as you do so. This represents the range of text that any future commands will act upon until visual mode is cancelled. To exit visual mode without doing anything is simple - press Escape as usual.

There are two more ways to enter visual mode - V (note the case) and ^V (ctrl-v). V will enter Visual Line mode (which selects entire lines as you move up and down), and ^V enters Visual Block mode, which allows you to select an arbitrary rectangle of text.

To run a command on text selected this way, simply do as you already know how to from the Absolute Basics section, or type an ex-mode command. ex-mode? Ah, yes. Remember when we were learning to exit vim and look at the help? Those commands that start with a colon are ex-mode commands, typed into the ex line. If you have selected text in visual mode, then that selection is preserved and acted on.

Perhaps the most useful ex-mode command you'll ever use is the :s command - where s is short for substitute - the search-and-replace command. The format of this will be familiar to anyone who uses regular expressions - because it runs a regular expression. The pitfall here is that vim regular expressions are similar to Perl and POSIX ones, but not quite the same. :he pattern and :he patterns are relevant commands at this point, if you ever get stuck or want to learn a little about vim's regular expressions.

We'll just do a simple substitution here. Let's say we want to substitute the word cat for the word dog - just once - in our visual selection range. Once you've selected some text any old how, type :s/dog/cat - the first found instance of the word dog will be replaced with cat. To replaces ALL occurrences of dog, we use :s/dog/cat/g. What will happen is that vim will automatically realise that you want to work in the selection, and add some range indicators to the command as soon as you type that initial colon - so what you'll see before pressing Enter is, in fact, :'<,'>s/dog/cat/g. This only happens when there is a visual selection.

To replace only on the current line, don't select anything, but type :s/dog/cat anyway - by default, single ex-mode commands concerned with text manipulation work only on the current line. To replace within the entire document, select nothing and type :%s/dog/cat/g

Finding what you want
Now we move on to finding text in a file. This is simple. In normal mode, press / (slash), and type the text you want to find, then press <enter>. To repeat the search, just type / on its own. You can move from one match to the next by pressing n. To search backwards, type ? then the text you want to find, or to repeat a search type ? on its own. Pressing n will then move backwards through the document. To make searches ignore the case of text, in normal mode type :set ignorecase. To make searches case-sensitive again, :set noignorecase.

Conclusion

Now, we've written a lovely text file, or program or something. It's time to go to dinner, and we need to save our work and shut the computer down. We do this by entering normal mode and using the :w command. If you've started totally from scratch, use :w /path/to/filename.ext, to save the file as /path/to/filename.ext. If you've been adding to an existing file, simply type :w to save it. This command can also be combined with the :q command easily - :wq to save the file and quit. :wq filename.whatever to save the file as filename.whatever and exit.

And in all this, I've barely scratched the surface of what vim can do. I'm so very sorry. It is a fact that vim is guilty of virtually everything that is said about it. It is not imediately user-friendly, it is obtuse for only casual use, it's old, it's archaic, it's weird. It's also extremely powerful, fast, small, efficient, customisable, modern, up-to-date, and available just about everywhere. If you ever find yourself on a UNIX system, it's pretty much a foregone conclusion that at least one Vi derivative, perhaps vim itself will be present. There is a whole lot more that vim can do that I've not managed to cover in this whole introduction, and I hope to be able to cover more soon. And fear not - if this scares you, there is a script bundled with vim that allows you to change some of the behaviour to be more like MS Windows until you get more used to things.

astr0man fucked around with this message at 01:35 on Jun 5, 2013

Slanderer
May 6, 2007
You're like that grandpa engineer who keeps around a slide rule because, "it's so much quicker!"

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Vim thread, awesome!

What are some vim plugins that completely revolutionized your productivity? I'd love to know what you swear by. For me, the big language-agnostic ones were:

  • vundle - It's basically like Ruby's bundler, as in it uses a "Gemfile"-like directives to download your plugins automatically for you. I hear it's a step up from pathogen, which I haven't used myself.
  • ctrlp - I can't live without this any longer. Fuzzy searching is amazing and completely removes the need for any kind of folder navigation if your work is contained to one folder.
  • vimwiki - personal wiki written in markdown. Dump it in Dropbox and you have all your notes always available anywhere. I switched from OneNote/Evernote to this because I dislikep proprietary formats.
  • vim -commentary - language-agnostic commenting out of any block of code. Incredibly useful.
  • vim-textobj-user, vim-textobj-entire, vim-repeat - a few generic utilities that are pretty mandatory
  • vim-matchit - smart jumping between opening and closing tags with <C-5>, very useful in HTML editing
  • vim-coffee-script - amazing plugin for CoffeeScript editing. The live compiled CS code buffer is very nice.
  • vim-fireplace / paredit - Clojure specific, make developing Clojure without Emacs fairly tolerable.

In other news, tpope is God. I feel like I owe this guy a few thousands of hours of productivity.

Btw, OP, you really need to add Practical Vim to mandatory readings for anybody serious about vim. It's a fantastic resource written by a guy who knows his stuff. It's an entry-to-intermediate level book that should cover 95% of use cases out there.

DreadCthulhu fucked around with this message at 19:08 on Jun 4, 2013

No Safe Word
Feb 26, 2005

That viemu poo poo in the OP is wack as hell, use vsvim: http://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329

It's free and very good.

astr0man
Feb 21, 2007

hollyeo deuroga
I'll add all that stuff to the OP when I get back to my desk. Does VSVim support versions older than 2010?

Dicky B
Mar 23, 2004

DreadCthulhu posted:

  • ctrlp - I can't live without this any longer. Fuzzy searching is amazing and completely removes the need for any kind of folder navigation if your work is contained to one folder.
I switched from Command-T to ctrlp for a while because I read somewhere that it's apparently faster, but whenever I try to use it in a large project it doesn't work properly and some files just don't show up at all.

Command-T is essentially the same but seems more robust in my experience, though you'll need to build vim with ruby support enabled.

No Safe Word
Feb 26, 2005

astr0man posted:

I'll add all that stuff to the OP when I get back to my desk. Does VSVim support versions older than 2010?

Doesn't appear to, though I think there was a version of it back in the 2005/2008 days, but it was iffy at the time. It's quite good now. And free!

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!

Dicky B posted:

I switched from Command-T to ctrlp for a while because I read somewhere that it's apparently faster, but whenever I try to use it in a large project it doesn't work properly and some files just don't show up at all.

Command-T is essentially the same but seems more robust in my experience, though you'll need to build vim with ruby support enabled.

I've had 0 problems with it in my experience, both as far as speed and functionality is concerned. I actually had the opposite experience with Command-T, it was super slow for me. Go figure.

With regards to files disappearing, watch out for newly added files to the folder tree, they don't automatically get added to the cache. Press F5 from within the ctrlp buffer to refresh the cache.

astr0man
Feb 21, 2007

hollyeo deuroga
I'm stuck using 2005 :downs:. But hey, I got my work to expense the $100 for viemu.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Dicky B posted:

I switched from Command-T to ctrlp for a while because I read somewhere that it's apparently faster, but whenever I try to use it in a large project it doesn't work properly and some files just don't show up at all.

Command-T is essentially the same but seems more robust in my experience, though you'll need to build vim with ruby support enabled.

What really sold me on ctrl-p is that basic insert-mode navigation commands (like ^W for deleting one word back) work on the search term input.

Dicky B
Mar 23, 2004

DreadCthulhu posted:

I've had 0 problems with it in my experience, both as far as speed and functionality is concerned. I actually had the opposite experience with Command-T, it was super slow for me. Go figure.

With regards to files disappearing, watch out for newly added files to the folder tree, they don't automatically get added to the cache. Press F5 from within the ctrlp buffer to refresh the cache.
Yea I'm aware of that, and I also had zero problems using it in small-to-medium sized projects, but I've found it gets increasingly unreliable the more files there are in the tree. It certainly seemed a little faster but unfortunately it just didn't work :(

More plugins!
clang-complete - Intellisense for C, C++ and Objective-C!
YouCompleteMe - An alternative to the above which I haven't tried.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
What do you guys use for something like renaming a ubiquitous variable across an entire project? I know there's a way of telling vim to do a substitute with confirmation across all the open buffers. Would you use that or perhaps the shell instead?

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

DreadCthulhu posted:

What do you guys use for something like renaming a ubiquitous variable across an entire project? I know there's a way of telling vim to do a substitute with confirmation across all the open buffers. Would you use that or perhaps the shell instead?

I would just use sed.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

DreadCthulhu posted:

I've had 0 problems with it in my experience, both as far as speed and functionality is concerned. I actually had the opposite experience with Command-T, it was super slow for me. Go figure.

With regards to files disappearing, watch out for newly added files to the folder tree, they don't automatically get added to the cache. Press F5 from within the ctrlp buffer to refresh the cache.

Turning off the cache is not as awful as it sounds. For me, a "large" project is around 100k LOC, maybe 500 source files or so, but even on a normal hard drive, the performance impact is barely noticable.

astr0man
Feb 21, 2007

hollyeo deuroga

DreadCthulhu posted:

What do you guys use for something like renaming a ubiquitous variable across an entire project? I know there's a way of telling vim to do a substitute with confirmation across all the open buffers. Would you use that or perhaps the shell instead?

Yeah, this is what sed is for.

I added everything people have posted to the OP.

Dicky B
Mar 23, 2004

Sailor_Spoon posted:

Turning off the cache is not as awful as it sounds. For me, a "large" project is around 100k LOC, maybe 500 source files or so, but even on a normal hard drive, the performance impact is barely noticable.
I didn't try just disabling the cache entirely; perhaps that might help. I'll give it a try at work tomorrow.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I made this thing a while back and someday I will actually finish it and add all the features I want to add just as soon as I have some free time oh god why am I so busy...

http://www.vimtax.com/

It helps make colorschemes.

astr0man
Feb 21, 2007

hollyeo deuroga
You guys should post your vimrc's because mine sucks.

No Safe Word
Feb 26, 2005

I mean mine sucks too but that's because I don't use vim as an IDE :v:

(this is for Windows)
code:
syntax on

set guifont=Consolas:h11

set expandtab
set shiftwidth=4
set tabstop=4
set smartindent

set backspace=2

colorscheme wombat
wombat owns y'all

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
This is a wonderful read and helped me really understand writing stuff in my vimrc: http://learnvimscriptthehardway.stevelosh.com/

astr0man
Feb 21, 2007

hollyeo deuroga
Oh yeah, if any of you feel like owning a really :spergin: keyboard with vim commands instead of letters on it you can get the same one as me from wasd: http://www.wasdkeyboards.com/index.php/wasd-v1-custom-keyboard.html?kt=1&k=1&s=7cdc41a18e757810db84d26f5875626f

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!

astr0man posted:

Oh yeah, if any of you feel like owning a really :spergin: keyboard with vim commands instead of letters on it you can get the same one as me from wasd: http://www.wasdkeyboards.com/index.php/wasd-v1-custom-keyboard.html?kt=1&k=1&s=7cdc41a18e757810db84d26f5875626f

No Topre? I'm outta here :P

chunkles
Aug 14, 2005

i am completely immersed in darkness
as i turn my body away from the sun
I like the syntastic syntax checking plugin. Just make to bind a key to turn it off. I had to edit a multiple-GB xml file once (don't ask) and it took forever.

Keebler
Aug 21, 2000
vimrc? Here's mine, shamelessly stolen from someone else.

I've been using VIM for coding for a while now, my only complaint over using an IDE is that I don't have a nice visual debugger available to use. Does anything like the MSVC debugger exist that might run in this environment? I tend to use C/C++.

Aw crap, meant to put that image in as a thumbnail :-(

code:
set nocompatible
set encoding=utf-8

filetype off

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

Bundle 'gmarik/vundle'
Bundle 'Lokaltog/vim-powerline'
Bundle 'w0ng/vim-hybrid'
Bundle 'scrooloose/syntastic'

" Easy Plugin Install
call pathogen#infect()

filetype plugin indent on
syntax on

set backspace=2 " enable <BS> for everything
set completeopt-=preview " don't show preview window
set cursorline " highlight the line where the cursor is
set fcs=vert:&#9474;,fold:- " solid instead of broken line for vert splits
set hidden " hide when switching buffers, don't unload
set laststatus=2 " always show status line
set lazyredraw " don't update the screen when executing macros
set mouse=a " enable mouse scroll
set nowrap " disable word wrap
set number " show line numbers
set showcmd " show command on last line of screen
set showmatch " show bracket matches
set textwidth=0 " don't break lines after some maximum width
set title " use file name in window title
set wildmenu " enhanched cmd line completion
set spelllang=en_US
set clipboard=autoselect
set ttymouse=xterm2

" Folding
set foldignore= " don't ignore anything when folding
set foldlevelstart=99 " no folds closed on open
set foldmethod=marker " collapse code using markers

" Tabs
set autoindent " copy indent from previous line
set expandtab " replace tabs with spaces
set shiftwidth=4 " spaces for autoindenting
set smarttab " <BS> removes shiftwidth worth of spaces
set softtabstop=4 " spaces for editing, e.g. <Tab> or <BS>
set tabstop=4 " spaces for <Tab>

" Searches
set hlsearch " highlight search results
set incsearch " search whilst typing
set ignorecase " case insensitive searching
set smartcase " override ignorecase if upper case typed

" Colors
set t_Co=256
let g:hybrid_use_Xresources = 0
colorscheme hybrid

" Toggle spellcheck
nnoremap <leader>s :set spell!<CR>

" Check file for errors
nnoremap <leader>c :SyntasticCheck<CR>

" Show Quickfix window for Syntastic errors
nnoremap <leader>e :Errors<CR>

" Search for trailing whitespace
nnoremap <leader>w /\s\+$<CR>

" Fancy Tingies
let g:SuperTabDefaultCompletionType = "context"
let g:Powerline_symbols = 'fancy'
let g:syntastic_mode_map = { 'mode': 'passive' }

" Functions {{{
"
" -----------------------------------------------------------------------------

function! ToggleFoldMethod()
if &foldmethod == 'indent'
  set foldmethod=marker
  echo "foldmethod=marker"
else
  set foldmethod=indent
  echo "foldmethod=indent"
endif
endfunction

function! ToggleRelativeNumber()
if &relativenumber
  set number
else
  set relativenumber
endif
endfunction

"}}}

Only registered members can see post attachments!

Keebler fucked around with this message at 20:34 on Jun 4, 2013

astr0man
Feb 21, 2007

hollyeo deuroga

Keebler posted:

I've been using VIM for coding for a while now, my only complaint over using an IDE is that I don't have a nice visual debugger available to use. Does anything like the MSVC debugger exist that might run in this environment? I tend to use C/C++.

If you're comfortable using GDB pyclewn works pretty well. But I probably do end up just using the VS debugger more often.

Dicky B
Mar 23, 2004

Keebler posted:

I've been using VIM for coding for a while now, my only complaint over using an IDE is that I don't have a nice visual debugger available to use. Does anything like the MSVC debugger exist that might run in this environment? I tend to use C/C++.
Which platform? On Linux I use cgdb.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

https://github.com/natw/dotfiles - Here's my dotfile repo, with my vimrc and all that other good stuff. I use submodules and pathogen for plugin management. I can't say it's all in active use, but I've been tending to it for a while.

MononcQc
May 29, 2007

Do you ever get to edit a file, delete everything, then start writing new stuff, only to find out, 2 hours later, that you needed something that was in the old version and that you lost it all?

Don't start typing from scratch just yet! Vim allows time-based undoing!

code:
:earlier {count}	Go to older text state {count} times.
:earlier {N}s		Go to older text state about {N} seconds before.
:earlier {N}m		Go to older text state about {N} minutes before.
:earlier {N}h		Go to older text state about {N} hours before.
:earlier {N}d		Go to older text state about {N} days before.

:earlier {N}f		Go to older text state {N} file writes before.
			When changes were made since the last write
			":earlier 1f" will revert the text to the state when
			it was written.  Otherwise it will go to the write
			before that.
			When at the state of the first file write, or when
			the file was not written, ":earlier 1f" will go to
			before the first change.
You can go back in time based on undo counts, seconds, minutes, hours, days, or even filesaves. The ':later' command allows to do the same, but forward in time.

How can this be done? Vim stores a tree of changes in memory instead of just a regular line. That means you can also find forks in an open file's history, but rather than using the commands to do that, use Gundo:

code:
  Undo graph                          File
+-----------------------------------+---------------------------+
| " Gundo for something.txt [1]     |one                        |
| " j/k  - move between undo states |two                        |
| " <cr> - revert to that state     |three                      |
|                                   |five                       |
| @  [5] 3 hours ago                |                           |
| |                                 |                           |
| | o  [4] 4 hours ago              |                           |
| | |                               |                           |
| o |  [3] 4 hours ago              |                           |
| | |                               |                           |
| o |  [2] 4 hours ago              |                           |
| |/                                |                           |
| o  [1] 4 hours ago                |                           |
| |                                 |                           |
| o  [0] Original                   |                           |
+-----------------------------------+                           |
| --- 3 2010-10-12 06:27:35 PM      |                           |
| +++ 5 2010-10-12 07:38:37 PM      |                           |
| @@ -1,3 +1,4                      |                           |
|  one                              |                           |
|  two                              |                           |
|  three                            |                           |
| +five                             |                           |
+-----------------------------------+---------------------------+
  Preview pane
Gundo can let you see all your changes to a file that has been open under the form of a tree, and it shows you highlighted diffs that you can navigate through. You can jump anywhere in the tree, apply it, go copy content, jump back into the newest form, and paste it there if you want to. It requires python support in vim, but works well both in gvim and the traditional vim.

astr0man
Feb 21, 2007

hollyeo deuroga

Sailor_Spoon posted:

https://github.com/natw/dotfiles - Here's my dotfile repo, with my vimrc and all that other good stuff. I use submodules and pathogen for plugin management. I can't say it's all in active use, but I've been tending to it for a while.

Wow, I don't know how it never occurred to me to just version my entire .vim directory using git submodules for the plugin stuff.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
About time for Vim thread. Here's my config. https://bitbucket.org/MalucoMarinero/vimsettings
Some bits don't work as intended, but I try not to spend too much time gardening and just fix things as they become problems, or when I have a little time to burn.

jony neuemonic
Nov 13, 2009

What are people's thoughts on spf-13? I've been using it for a while now with some minor tweaks (mostly to remove some plugins I don't use, and to add in ragtag) and it seems to work out OK. It's definitely a bit bloated, though.

ephphatha
Dec 18, 2009




astr0man posted:

Absolute basics
Return to normal mode, and navigate to the start of the word. In normal mode, the w and b move the cursor forward and backward by one word at a time respectively. Place the cursor on the start of the word rtmacs, and still in insert mode type x.

I think that should refer to normal mode.

All these nice .vimrc files are great but I interact with about 10 servers daily and 8 of them only have vi installed (with no possibility of installing vim). Does anyone have a nice example of a .vimrc/.exrc combo?

For me it's just:
code:
.exrc:
set number

.vimrc:
@source .exrc
Since I haven't been bothered to set up something fancy.

Scat Cat
Mar 13, 2008
I'm really excited for this thread. I just started a RA position at my school and we are working in Python almost exclusively. I've seen a colleague using Vim and he accomplished fixing my files in a fraction of the time that it would have taken me using IDLE in windows.

Anyways! I'd like to learn Vim this summer. I briefly read over your OP and was wondering if you, or any other users have any tips for beginners. We will be working on large data sets to populate 3D scenes in OpenSceneGraph. Does anyone have any experience working in Vim in this specific arena? Do you have any advice or time saving tricks to use with data or 3D scenes?

I should also mention that I'm pretty nubile when it comes to Unix.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
While some may not agree with me, fully loaded distributions of Vim with every plugin under the sun should be avoided until you have a good grip of the basics. There are some good books out there that'll help you tackle the early stages. I haven't worked all the way through it but it seems pretty well written: http://pragprog.com/book/dnvim/practical-vim

Vim is a very deep editor, especially in the level of customisation it has received. If something goes wrong with all that customisation you'll be lost, so it's much better if you can find stable footing with the core features.

astr0man
Feb 21, 2007

hollyeo deuroga

Ephphatha posted:

I think that should refer to normal mode.

Thanks, fixed it.

jony neuemonic
Nov 13, 2009

Scat Cat posted:

Anyways! I'd like to learn Vim this summer. I briefly read over your OP and was wondering if you, or any other users have any tips for beginners.

Remap H to ^ (beginning of line) and L to $ (end of line). Stumbled on it in someone's .vimrc a while back and now I can't live without it. ; to : is good too, saves hitting shift every time you want to use a command.

MononcQc
May 29, 2007

Something nice about the visual block mode (^V). Let's take the following document:

code:
line 1
line 2
some line
line 3
line 4
Go into visual block mode, and select the first character of each line by navigating with the arrow keys (yeah I still use them) or hjkl. If you press I (uppercase I means 'insert behind the cursor'), you will be able to add text, in this case ' -' (sorry for the drop shadow from OSX):



Press <Esc> twice, or once followed by any movement key and the change should be repeated on each line:



That's right, visual block mode allows the usual selection tricks: Select text with v, press c and you can replace the text. We could use that to uppercase our list, for example, by selecting it, then pressing c and changing things:



That's a bad example. Let's press u to undo once, and use ~ on the selected text instead. That one toggles case:



Hooray, text successfully edited!
All other regular modificators (d, r, c, I, :s for regexes, > and < to indent, etc.) all work there and allow to edit multiple lines at once.

This is especially nice when you're working over well-structured text and need to make changes to the structure. It took me a while to discover that one and I'm using it more frequently than I'd have expected.

ephphatha
Dec 18, 2009




My .vimrc/.exrc combo is slightly more complex now that I had some motivation to do it. One thing I'm wondering though is is there any danger to using map! in this way?

code:
.exrc
  1 set number
  2
  3 set autoindent
  4
  5 set hardtabs=2
  6 set tabstop=2
  7 set shiftwidth=2
  8
  9 map! <tab> <space><space>

.vimrc
  1 source $HOME/.exrc
  2 unmap! <tab>
  3
  4 nnoremap <leader>ev :split $MYVIMRC<cr>
  5 nnoremap <leader>sv :source $MYVIMRC<cr>
  6
  7 syntax on
  8
  9 set expandtab
 10 set smartindent
 11
 12 colorscheme wombat

Adbot
ADBOT LOVES YOU

Civil Twilight
Apr 2, 2011

Is there a reason to do that when you have expandtab set?

  • Locked thread