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
Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.
gVim is just a window wrapper around vim. The thing with vim in Windows is that there are a few default shortcuts that are different due to global Windows shortcuts (most notably ctrl+c and ctrl+v). :help explains the differences.

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Clark Nova posted:

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.


Marsol0 posted:

gVim is just a window wrapper around vim. The thing with vim in Windows is that there are a few default shortcuts that are different due to global Windows shortcuts (most notably ctrl+c and ctrl+v). :help explains the differences.

Thanks. I fired Vim up for the first time at work today, it's going to take some getting used to but I'm liking it so far.

Hughmoris fucked around with this message at 00:37 on Jun 23, 2015

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

Hughmoris posted:

Thanks. I fired Vim up for the first time at work today, it's going to take some getting used to but I'm liking it so far.

vimtutor is your friend

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Hughmoris posted:

Thanks. I fired Vim up for the first time at work today, it's going to take some getting used to but I'm liking it so far.

The good news is that after a couple weeks, you'll be super productive with it, and all the suffering through the learning curve will be worth it. That or you'll have Stockholm Syndrome and you'll keep telling yourself that you're much more productive.... :ohdear:

homercles
Feb 14, 2010

If I vim edit a file I'm already editing, is there a way to tell the old vim session to close and the new vim session to load in whatever changes the old session had made?

So the workflow is:
  • vim edit a file on window 1
  • make some changes
  • vim edit the same file on window 2
  • window 1's vim closes
  • window 2's vim has window 1's changes (kind of like "screen -d -r" of an old attached screen session)

I just love opening new xterms and this habit will never change.

Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.
You could try something like what this guy does. https://www.youtube.com/watch?v=aHm36-na4-4&t=720s (start at 12m, watch for 4-5 minutes).

Here's hit github with his plugins: https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup

homercles
Feb 14, 2010

Thanks, that's pretty close to what I'm looking for. I'll have to figure out a way to introspect all gnome-terminal inactive tab names since they're not visible to wmctrl, but I have alternatives now.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm running Windows 7. Is there a way to have Vim launch " :! " commands in powershell, instead of the command prompt? For instance, if I executed
code:
:! perl testScript.pl
I'd like that to launch in a powershell window because it makes copy/pasting/scrolling a lot easier.

VikingofRock
Aug 24, 2008




Hughmoris posted:

I'm running Windows 7. Is there a way to have Vim launch " :! " commands in powershell, instead of the command prompt? For instance, if I executed
code:
:! perl testScript.pl
I'd like that to launch in a powershell window because it makes copy/pasting/scrolling a lot easier.

According to this site the relevant commands are
code:
set shell=powershell
set shellcmdflag=-command
I don't have access to my windows box at the moment to test that out, but hopefully it works for you!

Hughmoris
Apr 21, 2007
Let's go to the abyss!

VikingofRock posted:

According to this site the relevant commands are
code:
set shell=powershell
set shellcmdflag=-command
I don't have access to my windows box at the moment to test that out, but hopefully it works for you!

Thanks. I tried that first but it's not working for me, but I might be doing it wrong. I placed those two lines in my _vimrc file, and when I run the command, it still loads it in the black command prompt window.
code:
:! perl testScript.pl

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Is there a simple way to copy all regex matches in a file, and paste it into a new buffer? If not, maybe highlight all matches and delete anything that is not a match?

MrPablo
Mar 21, 2003

Hughmoris posted:

Is there a simple way to copy all regex matches in a file, and paste it into a new buffer? If not, maybe highlight all matches and delete anything that is not a match?

You can use :g/regex/d to delete lines that match a regex, like so:

code:
> echo old.txt:; \
  cat old.txt; \
  vim old.txt +:g/^delete/d +:w\!\ new.txt +:qa\!; \
  echo new.txt:; \
  cat new.txt 
old.txt:
delete a
keep a
delete b
keep b
new.txt:
keep a
keep b
It's probably better to just use grep though:

code:
> echo old.txt:; \
  cat old.txt; \
  echo grep:; \
  grep '^keep' old.txt 
old.txt:
delete a
keep a
delete b
keep b
grep:
keep a
keep b

VikingofRock
Aug 24, 2008




Hughmoris posted:

Is there a simple way to copy all regex matches in a file, and paste it into a new buffer? If not, maybe highlight all matches and delete anything that is not a match?

For the first:
:g/regex/y A will yank all matching lines into register a. Then you switch to your new buffer and hit :p"a to paste them. If you mess this up, hit qaq to clear register a before trying again.

For the second:
:v/regex/d will delete all non-matching lines.

foobardog
Apr 19, 2007

There, now I can tell when you're posting.

-- A friend :)
I gathered they meant that only the parts that match would end up in the file. So given \(cat\|dog\) as the regex
and

code:
I have a cat and a dog.
I have a rat.
I have a cat.
I have a dog, and I hate it!
You'd get
code:
catdog
cat
dog
So definitely :v/regex/d would work to start and I was able to mostly get it with :s/.\{-}\(regex\)/\1/g, (i.e., using a non-greedy search and capturing groups) but that left the trailing parts alone:

code:
 
catdog.
cat.
dog, and I hate it!
I gave up and hoped other people would have an idea how to get it. I guess you could make another regex to get everything afterwards, but I started looking at the negative look ahead and decided it wasn't worth it.

VikingofRock
Aug 24, 2008




Found an answer on stack exchange. Apparently what we want is this:

code:
:%s/regex/\=setreg('A', submatch(0), 'V')/gn
That yanks all the matches (and only the matches), separated by newlines, into buffer 'a'. You can then paste this as above.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Thanks for the ideas. Yeah, I was hoping to grab just the captures and delete everything else. So, the starting text would be:
code:
adsfkjla"ORDER=PIZZA"djiasdf
nznjvzzajdf"ORDER=COKE"jaidjfa
nzxncvjzx"ORDER=CAKE"jadsmfa
and the ideal result would be the current buffer, or new buffer, containing
code:
PIZZA
COKE
CAKE

Hughmoris fucked around with this message at 19:32 on Sep 19, 2015

VikingofRock
Aug 24, 2008




Hughmoris posted:

Thanks for the ideas. Yeah, I was hoping to grab just the captures and delete everything else. So, the starting text would be:
code:
adsfkjla"ORDER=PIZZA"djiasdf
nznjvzzajdf"ORDER=COKE"jaidjfa
nzxncvjzx"ORDER=CAKE"jadsmfa
and the ideal result would be the current buffer, or new buffer, containing
code:
PIZZA
COKE
CAKE

Gotcha. This worked for me:

code:
:%s/"ORDER=\([^"]\+\)/\=setreg('A', submatch(1), 'V')/gn #to copy matches into buffer a
"ap                                                      #to put from buffer a

sink
Sep 10, 2005

gerby gerb gerb in my mouf
is NeoVim a thing worth using?

I move frequently between editing with a full IDE (IntelliJ) at work to editing with just vim. IntelliJ annoys the poo poo out of me by how clunky and unusable it can be. Vim annoys the poo poo out of me by how little it offers out of the gate and how painful or ghetto the configuration is to get it to have the bells and whistles.

aerique
Jul 16, 2008

sink posted:

is NeoVim a thing worth using?

I move frequently between editing with a full IDE (IntelliJ) at work to editing with just vim. IntelliJ annoys the poo poo out of me by how clunky and unusable it can be. Vim annoys the poo poo out of me by how little it offers out of the gate and how painful or ghetto the configuration is to get it to have the bells and whistles.

I don't[1] want to be that guy in a Vim thread but you might want to check out Emacs since it comes out of the gate with more of the bells and whistles you might be looking for. Specifically Spacemacs[2], which is Emacs configured using a Vim emulation mode[3] and which uses the space key as leader (hence the name).

I've not used Spacemacs but I have been using Evil[3] for a couple of years now and I switch between Emacs and Vim on my machine easily. There's few complaints about the Vim emulation out there since it is pretty complete.

(I started using Vi somewhere in the late 1980's, switched to Emacs in the late 1990's and been using Evil for a good while now. For me, it's an ideal combination.)

[1] Well, actually I do.
[2] https://github.com/syl20bnr/spacemacs
[3] https://bitbucket.org/lyro/evil/wiki/Home

Tiger.Bomb
Jan 22, 2012

aerique posted:

I don't[1] want to be that guy in a Vim thread but you might want to check out Emacs since it comes out of the gate with more of the bells and whistles you might be looking for. Specifically Spacemacs[2], which is Emacs configured using a Vim emulation mode[3] and which uses the space key as leader (hence the name).

I've not used Spacemacs but I have been using Evil[3] for a couple of years now and I switch between Emacs and Vim on my machine easily. There's few complaints about the Vim emulation out there since it is pretty complete.

(I started using Vi somewhere in the late 1980's, switched to Emacs in the late 1990's and been using Evil for a good while now. For me, it's an ideal combination.)

[1] Well, actually I do.
[2] https://github.com/syl20bnr/spacemacs
[3] https://bitbucket.org/lyro/evil/wiki/Home

burn him!

But yeah seriously evil/spacemacs sounds like an ideal kind of thing (though I've used neither). tbh, though, I don't think it's difficult at all getting a new set up. neovim is solid (thought I have had a hard crash and ctrl-h is broken) and there are some awesome plugin managers. I am excited for the day when nvim is mainstream and it's used as basically nothing more than the editing widget in IDEs.

Solumin
Jan 11, 2013

Hughmoris posted:

Thanks for the ideas. Yeah, I was hoping to grab just the captures and delete everything else. So, the starting text would be:
code:
adsfkjla"ORDER=PIZZA"djiasdf
nznjvzzajdf"ORDER=COKE"jaidjfa
nzxncvjzx"ORDER=CAKE"jadsmfa
and the ideal result would be the current buffer, or new buffer, containing
code:
PIZZA
COKE
CAKE

A week late and a buck short, but wouldn't
code:
%s/.*ORDER=\([^"]\+\).*/\1
work just fine? This would update the current buffer, which you said would be the ideal solution.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Solumin posted:

A week late and a buck short, but wouldn't
code:
%s/.*ORDER=\([^"]\+\).*/\1
work just fine? This would update the current buffer, which you said would be the ideal solution.

Thanks!

I'm really enjoying learning Vim, and discovering how much it can do. I had an extremely messy text file, with tons of duplicates and lots of noise. Used some :%s to remove the noise, and was left with lots of duplicates. I was thinking I would have to use Perl or Python to remove the duplicates, but it turns out that Vim has :sort u. That removed all the duplicates, and I had the result I wanted.

Good stuff.

Mattavist
May 24, 2003

I'm also new to Vim and trying to get used to working with buffers. Let's say I have a tab split to show two files, A and B. I'm working on A and type :tag some_function_in_B. This makes the view that was showing A to now show B, so B is shown in both views.

How can I make it just switch to the other view that's already displaying B? Or is this another case of "That's not how you're supposed to Vim!"?

waffle enthusiast
Nov 16, 2007



Looks like switchbuf may be what you want.

qsvui
Aug 23, 2003
some crazy thing
Why is there a changelog file type in vim? Does anyone use this?

ExcessBLarg!
Sep 1, 2001
It makes Debian changelogs pretty. Or it did, now those load as the debchangelog filetype.

qsvui
Aug 23, 2003
some crazy thing
Do windows have buffer histories that you can access? I know that pressing CTRL-6 will show the last buffer that was being edited in that window, but is there a way to go further back?

fuf
Sep 12, 2004

haha
gg=G works great on html files, except for inline javascript. It just pushes anything inside the <script> tag all the way to the left:

code:
<html>
   <body>
      <div>
         <script type="text/javascript">
var hello;
console.log("I am not indented");
         </script>
      </div>
   </body>
</html>
Any way to fix this?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
So I decided to work from home today to avoid meetings and get some things finished up. And omnisharp-vim is saying that GoToDefinition et al aren't editor commands.
:ohdear:

qsvui
Aug 23, 2003
some crazy thing
Did your vimrc get messed up or something?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

qsvui posted:

Did your vimrc get messed up or something?

Yeah, I figured it out. I decided to update my vimrc but never bothered to make sure anything I did for windows got carried over.

Quaint Quail Quilt
Jun 19, 2006


Ask me about that time I told people mixing bleach and vinegar is okay
I'm starting my foray into linux and programming today after thinking about it on and off for a few years and would like to dink around in Vim and python while learning Linux.

Instead of frying my os's and storage drives due to trivial mistakes/typos and never getting my AMD card or sound working when trying to install Gentoo like an idiot for a few days, I'd like to know if there is a persistent programmer friendly USB based Linux that has vim that I can experiment on. I don't need all the bells and whistles and I know the bare-basics of command line. I'm curious if I really can get to a point where I do pretty much everything from command line.

I just want to be able to listen to some music or something while going through my python tutorials and books, I downloaded those free MIT comp science courses as well. SliTaz didn't support my keyboard for some reason, I chose US non accented IDK.

I'm know a bit about systemrescuecd and am currently running calculate linux desktop xfce off a 4gb flash drive.

I'm going to do my Practical Vim and Learn Python The Hard Way Exercises after I finish vimtutor, I also tried that vim adventure, but I'm not going to pay for it.
I tried using Levinux-master in windows, and while I appreciate it for what it is, I'd rather use a real operating system if possible.

Really anything would work I guess, but It would be cool to have some persistence so I can focus on the exercises and also so I can get an idea of the Linux experience that I enjoy for later.

Any other advice for a new guy like me? I guess I could have posted this somewhere else probably, but I'm planning on learning the VIM way on my own for awhile and maybe taking a coding bootcamp after a year or two as a backup or new career. I'm poised to make lower end programming wages anyway after completing my 3 year Union Ironworker apprenticeship, but that will break my body down possibly.

Quaint Quail Quilt fucked around with this message at 07:41 on Feb 24, 2016

Imbroglio
Mar 8, 2013

galahan posted:

I'm starting my foray into linux and programming today after thinking about it on and off for a few years and would like to dink around in VIM and python while learning Linux.
Welcome!

quote:

Instead of frying my os's and storage drives due to trivial mistakes/typos and never getting my AMD card or sound working when trying to install Gentoo like an idiot for a few days, I'd like to know if there is a persistent programmer friendly USB based Linux that has vim that I can experiment on. I don't need all the bells and whistles and I know the bare-basics of command line. I'm curious if I really can get to a point where I do pretty much everything from command line.

I just want to be able to listen to some music or something while going through my python tutorials and books, I downloaded those free MIT comp science courses as well. SliTaz didn't support my keyboard for some reason, I chose US non accented IDK.

I'm know a bit about systemrescuecd and am currently running calculate linux desktop xfce off a 4gb flash drive.

I'm going to do my Learn Python The Hard Way Exercises after I finish vimtutor, I also tried that vim adventure, but I'm not going to pay for it.
I tried using Levinux-master in windows, and while I appreciate it for what it is, I'd rather use a real operating system if possible.

Really anything would work I guess, but It would be cool to have some persistence so I can focus on the exercises and also so I can get an idea of the Linux experience that I enjoy for later.
I would recommend virtual machines as an alternative to booting from a flash drive. Virtual machines make it really easy to experiment without taking any risks, and, unless you have a tiny hard drive, you do not have to worry about space nearly as much.
If you would rather boot from a flash drive, it might be worth finding a second flash drive to store files on.

Pretty much any variety of Linux should be programmer friendly and they should all have vim. I would recommend using one of the more popular Linux distributions because they have better hardware support, more extensive documentation, and more people who will be able to help you. Debian and its derivatives (Ubuntu, Xubuntu, Linux Mint, etc.) are all good choices.

Another option, if you want to get really proficient with the command line, is to run a server yourself and connect to it with ssh. Amazon will host a small server for you for free for a year under their free tier: https://aws.amazon.com/ec2/
You can put an ssh client on a flash drive and connect from anywhere. This might be a good option after you have learned the basics.

quote:

Any other advice for a new guy like me? I guess I could have posted this somewhere else probably, but I'm planning on learning the VIM way on my own for awhile and maybe taking a coding bootcamp after a year or two as a backup or new career. I'm poised to make lower end programming wages anyway after completing my 3 year Union Ironworker apprenticeship, but that will break my body down possibly.
  • Whatever you do, do not use the escape key to exit insert mode. I like to remap caps lock to escape, but there are a lot of other approaches.
  • I like this tutorial a lot, especially the part about vim being a language: https://danielmiessler.com/study/vim/
  • Don't try to learn too many things at once because you will not remember them. It takes time and practice to build muscle memory. I used vim for several years before I understood all of the things covered in that tutorial.
  • Programming and vim both have steep initial learning curves, but once you get over the hump, they're both extremely powerful and enjoyable skills.
  • Something that I wish somebody had told me when I started programming is that repetitive strain injuries are real and they can happen to anyone. Spend a few minutes reading about ergonomics and take breaks. If you feel any sort of pain, numbness, or discomfort while typing, you should address it immediately and see a medical professional if it persists. I have been forced to do nearly all of my programming with dictation software for the past year because I ignored the early warning signs of RSI. Don't make the same mistakes that I did!
  • On a more positive but related note, vim allows me to edit code as fast or faster than my coworkers without using my hands, because it is so expressive. The efficiency gains are real, I promise we aren't just a cult of text editing masochists.

sharktamer
Oct 30, 2011

Shark tamer ridiculous
You could try using pythonanywhere too.

Quaint Quail Quilt
Jun 19, 2006


Ask me about that time I told people mixing bleach and vinegar is okay
Thanks! I Think porteus would serve my needs in the meantime. I wasn't planning on using emulation until I get my next machine and Vga passthrough matures a little bit.

I speed read and have picked up a lot about linux and a fuzz about programming (osmosis), I'll be sure to follow cobol now instead of just joke yosps. I think I read the entirety of linux on desktop thread for example.

Quaint Quail Quilt fucked around with this message at 10:07 on Feb 24, 2016

Quaint Quail Quilt
Jun 19, 2006


Ask me about that time I told people mixing bleach and vinegar is okay

sharktamer posted:

You could try using pythonanywhere too.

Noted, It's good to know things exist for later. Vim is probably my first step though, I'll even have a new way to play rougelikes and muds now, hopefully be doing more productive things in the future though.

I suppose I could get another SSD, I'm just scared of grep and fuzzy on partitioning linux and such for dual boot, virtualization will be extremely cool once vga passthrough becomes ubiquitous.

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.

install vagrant, its the easiest way if you just wanna play with VM linux boxes on a mac

mila kunis
Jun 10, 2011
Hey, I'm working on a rails app and thought I'd try out vim. Looking for a little help with getting it set up like an IDE. So far I've installed vim-rails, vim-ruby, Nerdtree and ctrlp. What plugins would you guys recommend for tab autocomplete, closing html tags, jumping to ends of blocks/methods/parentheses and search all files for text functionality?

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
YouCompleteMe is great for completion. You may be able to just get away with using :grep for file searching.

Adbot
ADBOT LOVES YOU

Dicky B
Mar 23, 2004

tekz posted:

What plugins would you guys recommend for tab autocomplete,
YouCompleteMe

tekz posted:

closing html tags,
emmet.vim

tekz posted:

jumping to ends of blocks/methods/parentheses
%

tekz posted:

and search all files for text
I use the ack.vim plugin but :grep should work fine

  • Locked thread