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
Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Plorkyeran posted:

Ctrl-V, Enter should work.
Fantastic, thank you.

Adbot
ADBOT LOVES YOU

MacGowans Teeth
Aug 13, 2003

Destroyenator posted:

Combining with visual mode can be pretty powerful too:
code:
:g/{/norm f{v%J
All lines matching open brace ( :g/{/ ) normal mode ( norm ) jump forward to brace ( f{ ) enter visual [highlighting] mode ( v ) jump to matching brach ( % ) join all highlighted lines ( J )

You can chain multiple calls if you have an enter key press in a register. I can't work out how to paste one into the command line without having pre-recorded it though.
code:
:g/something/norm V/searchtarget^Md
All lines matching something ( :g/something/ ) normal mode ( norm ) line highlighting ( V ) search forward for searchtarget ( /searchtarget^M ) delete all highlighted lines ( d )
Where ^M is a pasted enter, to record one to register q ( qq<Enter>q ) and paste with control-r q.

:monocle: Whoa, using visual mode hadn't occurred to me, that's awesome.

dbcooper
Mar 21, 2008
Yams Fan
For those of you with a mechanical keyboard1:



Showcase your favorite editor on your keyboard. Buy a Vim keycap in a group buy. Deal ends on/around 2014-04-25.

1 With Cherry MX key switches

fuf
Sep 12, 2004

haha
Any tips or good plugins for writing HTML with vim?

Two things that I'd find really helpful:

A command to jump from a tag to the corresponding close tag (like jump from <div> to </div>)

A command to replace the contents of the open and close tag at the same time (like if I replace <h1> with <h2> it will simultaneously replace </h1> with </h2>)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

fuf posted:

Any tips or good plugins for writing HTML with vim?

Two things that I'd find really helpful:

A command to jump from a tag to the corresponding close tag (like jump from <div> to </div>)

A command to replace the contents of the open and close tag at the same time (like if I replace <h1> with <h2> it will simultaneously replace </h1> with </h2>)

The HTML ones I could not live without are:

Snipmate: https://github.com/garbas/vim-snipmate
Define your own snippets to poop out blocks of HTML you use frequently quickly

Sparkup: https://github.com/tristen/vim-sparkup
Write HTML super fast!

Non-plugin command that is wonderful for HTML (which you probalby already know): cit Will, from anywhere in the contents of a tag (say, the text inside an H1) remove it and put you in edit mode.

Those thing you find helpful would be very, very cool. I don't know if they exist, but it makes me want to learn to write vim plugins.

fuf
Sep 12, 2004

haha
Thanks Lumpy!

I feel like pretty much every thread I ask a question in you are usually the one who provides a useful answer! ;)

sharktamer
Oct 30, 2011

Shark tamer ridiculous
I don't even use vim full time, but you'll probably find emmet.vim really useful. It's great on sublime text.

e: It seems sparkup does the same thing and if Lumpy is recommending it, it must be better.

sharktamer fucked around with this message at 17:05 on Apr 25, 2014

The Laplace Demon
Jul 23, 2009

"Oh dear! Oh dear! Heisenberg is a douche!"

fuf posted:

A command to jump from a tag to the corresponding close tag (like jump from <div> to </div>)

Place cursor over div, and press %.

fuf posted:

A command to replace the contents of the open and close tag at the same time (like if I replace <h1> with <h2> it will simultaneously replace </h1> with </h2>)

I don't do much with markup, but a plug-in I use all the time for refactoring is vim-multiple-cursors. Without changing its configuration, you'd put your cursor over the first h1, hit <C-n> twice to enter multicursor mode and select the current word, hit <C-x> once for each of the nested h1s you have ;), and when it highlights the closing h1, press c then type h2.

If you don't have any nested h1s, that'd reduce to <C-n><C-n>ch2<Esc>. Usually when I'm refactoring my code, I want to replace all of my variable names, so I can just mash on <C-n> until everything is matched, but sometimes that granularity of being able to skip some matches comes in handy.

The Laplace Demon fucked around with this message at 18:25 on Apr 25, 2014

jony neuemonic
Nov 13, 2009

fuf posted:

Any tips or good plugins for writing HTML with vim?

Two things that I'd find really helpful:

A command to jump from a tag to the corresponding close tag (like jump from <div> to </div>)

A command to replace the contents of the open and close tag at the same time (like if I replace <h1> with <h2> it will simultaneously replace </h1> with </h2>)

He (accidentally?) wiped the readme, but I always liked Tim Pope's Ragtag. There's a walkthrough here, it's similar to Emmett/Sparkup though admittedly with less features.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
Learned about bufdo today and it saved me loads of headaches. If any of you need to execute a command across many files, take a look at it.

fuf
Sep 12, 2004

haha

Lumpy posted:

Sparkup: https://github.com/tristen/vim-sparkup
Write HTML super fast!

Update: I can't live without this now. :)

I still haven't quite found a solution for this one though:

fuf posted:

A command to jump from a tag to the corresponding close tag (like jump from <div> to </div>)

This doesn't work unfortunately:

The Laplace Demon posted:

Place cursor over div, and press %.

(it jumps from between the opening and closing brackets of <div>, but not from <div> to </div>)

The closest thing I've found is this plugin which highlights the closing tag (pretty useful in itself):
https://github.com/gregsexton/MatchTag
http://www.vim.org/scripts/script.php?script_id=3818

If I knew how I'd edit the plugin code to add a way to jump between matched tags.

The Laplace Demon
Jul 23, 2009

"Oh dear! Oh dear! Heisenberg is a douche!"

fuf posted:

(it jumps from between the opening and closing brackets of <div>, but not from <div> to </div>)

:downs: Oops, I use sensible.vim, which automatically runs runtime! macros/matchit.vim. That macro has been included in vim since 6.0, and it's what adds the jump between tag behavior.

fuf
Sep 12, 2004

haha

The Laplace Demon posted:

:downs: Oops, I use sensible.vim, which automatically runs runtime! macros/matchit.vim. That macro has been included in vim since 6.0, and it's what adds the jump between tag behavior.

Oh hey it works! Thanks.

fuf
Sep 12, 2004

haha
I used to have a shortcut that would open a fullscreen list of all open buffers that you could scroll through and switch to with <enter>.

It wasn't :ls, and I'm sure it wasn't a plugin. Any ideas?

jony neuemonic
Nov 13, 2009

Anyone tried out trackperlvars.vim yet? It's a handy plugin for dealing with Perl variables since it understands the different variable types (so it doesn't get confused when you want to move from definitions to uses, or globally rename a variable), but it's also supposed to highlight all uses of a variable when you put the cursor over one and that part doesn't seem to be working.

e. Turns out it only defines highlights for terminal Vim. Easily fixed.

jony neuemonic fucked around with this message at 18:50 on Aug 10, 2014

The Gay Bean
Apr 19, 2004
I have become addicted to Vim keys / modal editing for programming, and also completion for C++. The problem is, what I'm using for completion/semantic completion, YouCompleteMe, while it works well, makes Vim slow to a crawl after an unpredictable amount of time between 30 minutes and two hours. I have tried everything to resolve this and it appears to be a YCM issue that the developer is unwilling/unable to address.

I know there are several other options, a big one being NeoCompleteCache, but I just want to hear what people are using for this and what has worked well for them instead of trying out a hundred other plugins and realizing I don't like them. Has anybody found a C++ completion engine that just works? A big bonus is the ability to do semantic completion based on standard libraries, and an even bigger bonus is the ability to do semantic completion on third-party libraries, but I'm willing to go with something that's a little simpler, as long as it gets variable names and such.

Should I just suck it up and buy Sublime2/vintage mode? Does that emulate the whole modal editing thing sufficiently?

Dicky B
Mar 23, 2004

clang-complete works in much the same way as YCM. I used it for a long time before switching to YCM.

Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.

The Gay Bean posted:

I have become addicted to Vim keys / modal editing for programming, and also completion for C++. The problem is, what I'm using for completion/semantic completion, YouCompleteMe, while it works well, makes Vim slow to a crawl after an unpredictable amount of time between 30 minutes and two hours. I have tried everything to resolve this and it appears to be a YCM issue that the developer is unwilling/unable to address.

I ran into the same issue, and in the end I just stopped using YCM. I use ctags quite a bit for my auto-complete, although that doesn't help much with libraries. Instead, now I just read the documentation in Dash or Zeal, which is definitely not as efficient. :(

The Gay Bean
Apr 19, 2004
I actually figured this out. It turns out that I was syntax highlighting was slowing everything down, so I added "syntax sync minlines=256" to and took out "set t_Co=256" from my vimrc and it's fast.

kik2dagroin
Mar 23, 2007

Use the anger. Use it.
Hey guys, I'm transitioning into using vim for my script writing at work and was curious if anyone has developed powershell scripts in vim before. Syntax highlighting exists, but I'm curious if there are any code completion extensions, because the only thing really keeping me on the Powershell ISE is the sheer awesomeness of Show-Command and Out-GridView for when I need to visualize the actual powershell objects. It might be that I should be in the mode of "using the right tools for the right job" but if I could keep the focus entirely in vim for my script writing then I think that would make more sense productivity wise.

Modern Pragmatist
Aug 20, 2008
Does anyone know if there is a way to customize the behavior of spell check based on syntax. For example, I currently have it configured to only spell check strings and comments; however, a lot of the times in the comments I may refer to a function or class by name (which it will obviously interpret as misspelled). Ideally I would like for spell check to automatically add all class and function names to the dictionary that way when they are referred to in the comments, it is only marked as misspelled if it's a) not a word and b) not a valid function or class name.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Is there a git plugin that will add an extra column beside the line numbers telling me if a line is added or changed? I had that feature in an IDE and thought it was pretty handy. I already have fugitive but haven't seen anything about displaying diff stuff inline. Thanks

edit oh duh never mind, it is a feature of fugitive

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I just saw these days someone who used this: https://github.com/airblade/vim-gitgutter

No Safe Word
Feb 26, 2005

Relevant to folks here probably, the vi/vim beta stackexchange thing launched: http://vi.stackexchange.com/

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
If I interact with vim exclusively through ssh to a cluster of computers I don't control (my university's computer lab), how much can I do to make C code easier to edit? For my first couple of projects I've gone with vim as a pure editor, meaning that there's no intellisense or any real assistance from vim at all. Just basic syntax hilighting seems to work out of the box. Most of the info in the OP seems to assume that I have access to install plugins, which I don't. Can I do anything to make my life easier?

I tried working on my projects in Visual Studio for a while, but most of our projects depend on Linux syscalls and target the Linux environment so it proved to quickly become too annoying to constantly scp my source back to the lab computers to test it.

Chin Strap
Nov 24, 2002

I failed my TFLC Toxx, but I no longer need a double chin strap :buddy:
Pillbug

LeftistMuslimObama posted:

If I interact with vim exclusively through ssh to a cluster of computers I don't control (my university's computer lab), how much can I do to make C code easier to edit? For my first couple of projects I've gone with vim as a pure editor, meaning that there's no intellisense or any real assistance from vim at all. Just basic syntax hilighting seems to work out of the box. Most of the info in the OP seems to assume that I have access to install plugins, which I don't. Can I do anything to make my life easier?

I tried working on my projects in Visual Studio for a while, but most of our projects depend on Linux syscalls and target the Linux environment so it proved to quickly become too annoying to constantly scp my source back to the lab computers to test it.

If you have write access to a folder that you can always see, you could probably get Vundle to install packages to that folder, no?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
You could use a local vim to edit files on a remote server:

code:
vim scp://remoteuser@server.tld//path/to/document
If you have write access to a home directory on the server, you can also do something like this to load your .vimrc at startup:

code:
alias vim="vim -c ':source scp://you@your_computer//yourpath/.vimrc'"

sharktamer
Oct 30, 2011

Shark tamer ridiculous
I've never been able to find an actual answer for this, if I'm trying to edit a file through scp on a password protected server that doesn't allow keys, how do I save the password so I'm not asked for it every time I save?

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Bognar posted:

You could use a local vim to edit files on a remote server:

code:
vim scp://remoteuser@server.tld//path/to/document
If you have write access to a home directory on the server, you can also do something like this to load your .vimrc at startup:

code:
alias vim="vim -c ':source scp://you@your_computer//yourpath/.vimrc'"

I do have a home directory I can access. Forgive me, but do I put this in my .bash_profile? I am not a regular Linux user, so I'm learning as I go here. Similarly, how would I get vim to load plugins installed to my home directory?

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
OK, so I figured out how to use vundle and make a vimrc, but it looks like clang_complete needs clang installed to work. How would I go about installing clang to my home directory? All the installation steps I can find assume I have full control of the machine.

Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.

LeftistMuslimObama posted:

OK, so I figured out how to use vundle and make a vimrc, but it looks like clang_complete needs clang installed to work. How would I go about installing clang to my home directory? All the installation steps I can find assume I have full control of the machine.

When you do the ./configure step you can pass it --prefix=~/some/homedir/path and when you do make install it will go there.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Marsol0 posted:

When you do the ./configure step you can pass it --prefix=~/some/homedir/path and when you do make install it will go there.

Cool. Are these the right steps: http://clang.llvm.org/get_started.html
Checking out llvm is taking forever!

Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.

LeftistMuslimObama posted:

Cool. Are these the right steps: http://clang.llvm.org/get_started.html
Checking out llvm is taking forever!

It's not a small thing and in the end may not work out if you have any time constraints where fussing with it gets in the way of actual work. In that case I'd suggest looking into tags with vim. That should be simple to set up and it'll give you completion of your own code and an easy way to bounce around in it.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
Well, it turns out the versions of GCC and Python on the school's computers are too old to even build llvm and clang. I don't suppose there's any other ways to get basic code completion for the standard C libraries, is there? I mostly just want it to catch when I typo printf to pritnf for the millionth time and remind me what the parameters are for library functions. Popping back and forth between the terminal and manpages is time-consuming when I just can't remember the order of parameters for a certain function.

astr0man
Feb 21, 2007

hollyeo deuroga
The only C code completion plugins I know of (YouCompleteMe and clang-complete) rely on clang.

Also this is not really a helpful suggestion but you could always just open the man pages from inside vim with :!man 2 open :v:

Dicky B
Mar 23, 2004

You can use shift-k to look up the word under the cursor

loose-fish
Apr 1, 2005
You can also use ctags for basic completion (and navigation).

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

LeftistMuslimObama posted:

Well, it turns out the versions of GCC and Python on the school's computers are too old to even build llvm and clang. I don't suppose there's any other ways to get basic code completion for the standard C libraries, is there? I mostly just want it to catch when I typo printf to pritnf for the millionth time and remind me what the parameters are for library functions. Popping back and forth between the terminal and manpages is time-consuming when I just can't remember the order of parameters for a certain function.

Build a newer version of gcc, and then use it to build clang :v:

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm in a Windows environment at work and mainly write a lot of single-file scripts to help with day to day workflow. I've been using sublime and am interested in learning Vim, just cause. Is there any reason I should use standard Vim instead of gVim?

Adbot
ADBOT LOVES YOU

Clark Nova
Jul 18, 2004

Hughmoris posted:

I'm in a Windows environment at work and mainly write a lot of single-file scripts to help with day to day workflow. I've been using sublime and am interested in learning Vim, just cause. Is there any reason I should use standard Vim instead of gVim?

Not as far as I know - gVim's GUI is pretty minimal, and can be turned completely off if it bugs you. I don't think there's a way to get hi-color mode (i.e. nice, pretty colorschemes) to work in the standard windows console version of vim. I think you may be able to get that working in cygwin or mingw but I've never tried because :effort: Anyway, vim and gvim will both use the same config file, so you can switch back and forth effortlessly.

  • Locked thread