190
Sep 25 '15
Mmmm text editor fan fiction.
100
u/mike413 Sep 25 '15
Good thing vim is the only editor that lets you navigate with one hand free.
34
u/notNullOrVoid Sep 25 '15
That would have been funny to me, had it been factual.
25
u/mike413 Sep 25 '15 edited Sep 25 '15
oh right, some keyboards have arrow keys.
EDIT: the old joke was: "only vi lets you refer to the code while talking on the phone", but I guess the PC keyboard levels the editor playing field. :)
6
1
1
5
u/rubdos Sep 25 '15
I really need to remap my vim for dvorak...
6
u/skylos2000 Sep 25 '15
There's bound to be someone whose already done it.
0
Sep 25 '15
[deleted]
4
u/smtudor Sep 26 '15
Can I thank you right now?
5
u/jones_supa Sep 26 '15
Only later. You must wait a certain amount of true long-term thankfulness to accumulate.
2
u/bobbaluba Sep 26 '15
What if I want the shortcuts to stay where they are? (I don't care for mnemonics)
1
Sep 26 '15
I'm not sure I understand what you mean.
2
u/bobbaluba Sep 26 '15
I want the key positions to be the same. I want to delete things using e on dvorak. Because that's where my finger moves when i want to delete stuff.
1
u/socium Sep 29 '15
You might want to add some comments here and there.
1
Sep 29 '15
Where in particular? Unless GitHub's being stupid for one reason or another, I commented the Dvorak section and explained what things were being changed to.
1
u/socium Sep 29 '15
Well, if the config you have is only for yourself then I suppose it's ok to add some basic comments, but with all configs that I have I turn them into a story so that the people trying to learn and copy stuff from it know what they're copying.
For example:
I for one don't understand what
" Usability {{{1lines are. Functions are only explained by their code.Also, things like this:
set whichwrap=<,>,[,],h,l set scrolloff=2 set backspace=indent,eol,start set ttimeout set ttimeoutlen=50 set timeoutlen=3000 set incsearch set number set numberwidth=5 set hidden set mouse=nIf I have no idea what they do, then I have to look up every single option.
1
Sep 29 '15
Ah, I see what you mean; the rest of the file. Yeah, it's mostly just for me. If I was writing one for others, I'd absolutely add more detailed comments, as well as using the long names for the options instead of shortnames where possible.
A lot of it is just stuff I picked up over the years when I discovered a behavior in vim that I didn't like.
Anyway, the
{{{part in comments are folds and fold levels, so this:" {{{1 Some stuff more stuff " {{{2 even MORE stuff " }}} A sidenote or two blah " }}}With folding on, will look like this:
" {{{1 (9 lines)Or similar. If you toggle it (with
za), you'll see:" {{{1 Some stuff more stuff " {{{2 (3 lines) A sidenote or two blah " }}}It basically creates a heirarchy of folds. I don't use it for every file, but I wanted to organize my
vimrcand decided that was the best way to do it.Here's a quick look when I first open it in vim (Sorry about not using imgur; it errored on me)
2
u/zebediah49 Sep 25 '15
I tried it; it doesn't work too well.
The problem is that vim is a split between keys that are conveniently placed, keys that stand for their action, and some that are both. Fixing the mapping causes a couple annoying collisions.
2
u/CarVac Sep 26 '15
I've never felt the need to remap.
I like having a browser open and scrolling in that with my right hand, while navigating in vim with my left hand.
1
u/zebediah49 Sep 26 '15
Fair enough, I'd say that's probably the way to go in Dvorak -- the movement keys make no sense though.
1
u/zottasi Sep 26 '15
Even better: You can use VimFx to navigate your browser with one hand free.
It's useful sometimes.
41
u/sacramentalist Sep 25 '15
The "." (repeat last edit) is my favourite thing.
One of the guys here uses nano, and doesn't know how to send his text through the command shell and replace it with the results. It's like missing a limb.
24
Sep 25 '15 edited Sep 26 '15
Sorry, just starting out with vim - no idea what you are talking about..sounds handy..TEACH ME?!?
Edit: Thank you all! Each comment makes my jaw open wider, damn you sexy Vim.
32
u/tolos Sep 25 '15
6
u/Tordek Sep 25 '15
I use :!sort often
11
u/whatevsz Sep 25 '15
No need to call an external command:
:sort2
1
u/Tordek Sep 27 '15
See, that's one thing that bothers me slightly. Why does vim need its own implementation of sort? "Unix nature" and all that, just pipe data through external filters.
2
u/bombita Sep 28 '15
Vi exists in multiple platforms, like BSD, OSX, Windows, Solaris, etc. Not all of them have that idea in mind.
1
Sep 28 '15
My guess would be that vim needed sort for something internal and just decided to expose it to the user because it was already there.
1
Sep 26 '15
This is awesome for when I need to write my bootloader .conf's and need to put the PARTUUID in to the file!
1
14
u/adamnew123456 Sep 25 '15
Also, you can pipe a region through a command without doing replacement - it will show standard out in the bottom part of the display. For example:
:'<'>w !wc -wInstant word count of your region. You can also do this for entire buffers:
:w !wc -wThis word counts the whole buffer you're working in.
3
u/naught101 Sep 25 '15
Huh. I was not aware that
:wwrites to stdout if you provide a!command... Interesting. Is there a way to pipe that output back into the buffer?2
u/adamnew123456 Sep 25 '15
You can do replacement of your current selection with the output of the command with
:'<'>r!tac. tac being a command which reverses its input lines, this whole command reverses the order of the lines in your selection.I'm not sure if you can send the output of a command to a register so you don't have to replace your current selection. A good question to ask the gurus around here.
2
u/microphylum Sep 26 '15
There's a slightly faster way to do an instant word count that doesn't require calling an external command: select the region as before, and then hit g, followed by Ctrl-g.
11
u/sacramentalist Sep 25 '15 edited Sep 25 '15
! lets you run a shell command. Well, :n,m! where n and m are the line identifiers.
The famous examples are calling fmt or sort. For instance, if you have a paragraph with lines longer than 78, the fmt command will even the words out so no line has more than 78 characters
!}fmt (edited because you don't use the :)
Oh yeah, } is a paragraph selector (between above and below blank lines)
Or if you want to sort lines 20-40
:20,40!sort
Or, if you want to scramble the lines of your file:
:%!shuf
Well, I guess you could :%!sort -R . There's more than one way to do these things.
:!! repeats the previous shell command
Save your work. Esc and u are your best friends.
11
u/Pipinpadiloxacopolis Sep 25 '15
I wish "." was better. What if I want to re-do the second-to-last command? Sorry, it's gone, why didn't you make a macro?
8
u/kofdog Sep 25 '15
q:5
u/Rojs Sep 25 '15
q:is the command line history brought up in an buffer you can edit and execute.
@:Will repeat the last command line directly.Neither of these are related to
.1
u/kofdog Sep 25 '15
Actually, I only just learned from your comment that
q:only applies to command-line commands. I guess I've never even thought to use it for key commands, so I just assumed it would have those as well. My answer, then, only applies to a specific subset of Vim commands. Thanks for the info!2
Sep 25 '15
.command is just a shortcut for@., so whenever you press.in normal mode, you replaying a macro.1
u/RandomDamage Sep 25 '15
vim also gives you easy access to sed, though care must be taken when making mass search/replace edits.
find $html_base -name '*.html' -exec sed -i -e's/\.wav/.ogg/' {} ;
1
u/polartechie Sep 25 '15
They can't? As someone who's used only vim and hasn't tried nano/pico, that's crazy
1
16
u/TreeFitThee Sep 25 '15
As I read the hacker news comments I make one small, sad, discovery
1159 days ago
31
Sep 25 '15
As someone who finally stuck it out through vimtutor yesterday, this was a great read.
I have tried vim and so many times I hit a couple of (to me) normal short cuts or commands and vim chucks a fit - then I used to get in that violent WTF IS VIM HOW DO I QUIT OMFG GO TO HELL DIE! thing.
But yesterday...it clicked...
I typed :! dir for one of the tutorial things in vimtutor. Yes, next! Done! whatever, stupid vim making me learn it...wait a second...wtf did I just do? I output the actual command inside the document...
Oh..
my..
Vim!
6
Sep 25 '15
Confession Time!
I still don't know how to exit emacs... I think it is something like ^w^q^x I am not sure :(
8
u/EverybodyLovesRayman Sep 25 '15
C-x C-c, my friend!
3
u/dynetrekk Sep 25 '15
C-Z doesn't work?
8
u/xalorous Sep 25 '15
Ctrl+z? then grep for the abandoned process and kill it, but yeah, it gets you out of whatever you're stuck in.
6
3
u/zebediah49 Sep 25 '15
I once saw someone actively using emacs, and he just stopped and abandoned the process to "quit".
I was horrified (but didn't want to attempt to explain what was actually happening).
1
1
u/TravestyTravis Sep 26 '15
Can you direct me to Vimtutor? I did a google search and seem to find outdated and closed websites primarily. Thanks in advance!NVM:
Yes, vimtutor is literally the name of a program that runs you through a tutorial for vim. If installed on a Unix environment, that command should be sufficient. On windows, there's an entry in the start menu folder just titled "Vim tutor" which is a shortcut for vimtutor
0
Sep 25 '15
[deleted]
11
Sep 25 '15 edited Sep 25 '15
?
I actually upvoted you for an explanation because unless it was just an insult I don't know what your comment means.
15
u/Eoran Sep 25 '15
6
2
4
3
4
Sep 25 '15
[removed] — view removed comment
2
Sep 26 '15
Um I think there is a .vimrc thing at the end of vimtutor...it gave me coloured syntax in c++ files :)
Thats as far as I have gotten atm. But the stuff I learned in this thread will keep me busy for a little while.
1
u/bobbaluba Sep 26 '15
Don't wait too long before starting to install plugins. Many of them are ridiculously important if you want vim to be an efficient tool compared to Atom, IntelliJ etc.
If you install vundle, then adding other plugins is as simple as adding a single line to your .vimrc file and run an update command.
A few recommendations to get you started:
Syntastic: Gives you syntax/lint errors.
Fugitive: Git integration
Ctrl-p: Easy opening and switching files within a project.
Nerd-tree: file browser at the side
Surround: Easily add/change/delete parenthesis and friends (){}"" <tag></tag>
There's also a lot of language specific plugins that are pretty great. i.e. Go, C#, js, html.
7
45
u/realitythreek Sep 25 '15
Amusing read. I enjoyed it.
It's kind of representative of the problem with everyone's preoccupation with the editor wars. Typing efficiency != faster coding.
37
u/linuxwes Sep 25 '15
There is a lot more to an editor that just typing. A good editor allows you to navigate interconnections between large numbers of files easily and while maintaining a train of thought. If I am reading some code and see a function and wonder what it does, if it takes me 30 seconds to find and open the file which contains the function I am going to totally lose my train of thought. A good editor with tag support will allow me to move between functions and files without ever pulling my brain out of the problem space, and that definitely == faster coding. None of that justifies the editor wars though, because there is more than one way to smoothly interact with code.
2
24
u/Lorizean Sep 25 '15
But typing efficiency does equal faster coding?
I mean, just because you can churn out text twice as fast does not mean you'll code twice as fast, but it does help - you'll still spend the same time on conceptualization and looking up things, but the actual typing will (by definition) be faster.
And fully using an advanced editor like vim or emacs doesn't just increase the speed of initial code writing but of refactoring etc.
2
u/SarcasticOptimist Sep 25 '15
Though you do need to calculate the time and productivity lost in getting to that point. Also, there are some massive productivity improvers (autofillers, git branch indicators, etc.) that manually need to be added, making it necessary to save the vim profile.
This assumes you know the language's syntax well in the first place.
Efficiency issues are less of an issue now since when vim was implemented. In the end, while the time investment to VIM proficiency should be rewarding, in the end you're arguing about tools and not about the end product. As long as you're comfortable getting to point B through that means is the important part.
2
u/Lorizean Sep 25 '15 edited Sep 25 '15
I very much agree that you should be using whatever you're comfortable with. I have tried several IDEs and I like vim more, doesn't mean that it can't be the opposite for other people (although it does take some time to get used to vim, whereas most IDEs can just be picked up and then you improve as you go).
You are right, the end product is what counts (and the time to get there). I was just arguing that being better at using the tools will allow you to code faster.
Edit after reading the article you linked: I will never willingly use a non-vim syntax IDE again. I am sure that there are great features out there that might be made easier with an IDE but I like to have full control over my environment.
Using a "normal" editing environment also just feels incredibly slow. I agree that people can probably do a lot of coding-related tasks just as fast or faster in an IDE, but I very mouch doubt that pure text manipulation can be done more efficiently than with a streamlined editor like vim or emacs.
2
u/Sasamus Sep 26 '15
I think you two have different definitions about what "coding" means in this context.
It seems like you define it as the initial writing of the code while /u/realitythreek defines it as everything involved with the creation of the finished product.
If my interpretation of of both of your definitions is correct I agree with both of your statements.
6
u/ingvij Sep 25 '15 edited Sep 25 '15
That is essentially me, over the last two years... My life has changed ever since, and so my productivity... And I still think I have a long road ahead....
15
u/ender_wiggum Sep 25 '15
I've been programming for almost 20 years, and I still learn something new in 'vi' every few months. I think of Vim as essentially bottomless: there is always a little more left in that tube of toothpaste ;)
6
u/marksei Sep 25 '15
I didn't think it was possible to create a not-so-unrealistic fan fiction about a text editor. But the most interesthing thing to notice and pretty amusing in my opinion is the :wq
28
6
Sep 25 '15 edited Sep 25 '15
That's exactly how I found Vim :| I saw someone using Vim in a class full of Turbo C++ users in college. I was using Nano before too, Sublime Text before that.
8
u/kazagistar Sep 25 '15
That's intereating, how and why did you make that first transition (sub -> nano)?
8
Sep 25 '15
I wanted to try something new for fun. Also, I was learning the terminal and command prompt at that time.
4
u/kazagistar Sep 25 '15
I just went the other way, and it seemed like a pretty straightforward improvement, so I was surprised, haha.
3
Sep 25 '15 edited Sep 25 '15
PCs at my college are horrible. Even sublime text has input lag. Vim works flawlessly.
1
u/TheNoodlyOne Sep 26 '15
And you were compiling C++ on these machines? Dear Lord.
1
Sep 26 '15
Yes? They aren't too bad to compile C++. And we have really basic shit this year - introduction to the language.
They run Windows XP just fine too.
3
u/TheGlassCat Sep 25 '15
I learned about vim from Slashdot. Before that I used vi and before that I used ed. Oh, God, I'm old!
2
u/Fidodo Sep 26 '15
I was a big vim user, but sublime text multi-cursor mode is da bomb
0
Sep 26 '15
[deleted]
1
Sep 26 '15 edited Sep 26 '15
My college forces Turbo C++ for practical examinations and teaching.
0
Sep 26 '15
[deleted]
1
Sep 26 '15
Noone is without Windows AFAIK. Some people don't have a desktop/laptop PC. Most of the PC-less use AIDE on Android.
0
1
u/Fidodo Sep 26 '15
You're taught on it? That's odd, the reason I learned vim wasn't because we were all required to, it was because we had to do a lot of projects over ssh and I chose that among the CLI text editors.
3
u/swordgeek Sep 25 '15
Just remember, it all stems from vi. (and if you ever pronounce vi as a single syllable, I will cut you!)
2
u/TheGlassCat Sep 25 '15
Actually, it seems from ed. vi is just a VIsual extension of ed.
1
u/swordgeek Sep 26 '15
Well yes, but there's a limit on the number of blank stares I can take on any given day. :-)
And really, vi is a visual extension of ex, which was the extended version of ed. But if I start to go down that path, I'll really get blank stares.
That said, I can still function in single-line ed if I have to. That either makes me rare, or ancient. or both.
3
u/HawkEgg Sep 25 '15
:x
1
2
2
2
u/VelvetElvis Sep 26 '15
Am I the only person on earth who likes vile or is this just me being older than most of Reddit again?
I first learned elvis when it was the default vi shipped by slackware and then then moved to vile when debian dropped elvis.
2
3
u/eppic123 Sep 26 '15
2
u/Kernel_Manic Sep 26 '15
I use Atom. I feel like my hacker cred suffers a little because of this, but oh well. Learning vim is not something I'm up to yet.
2
u/Sasamus Sep 26 '15
I honestly think Atom will be a big contender among the editors.
The main complaint I've heard about it is it's bad performance because of it's decision to use web technology.
But it did that to be as customizable as possible and as I see it, performance will only be improved over time, both by improvements in Atom itself and by the inevitable evolution of hardware. While it's a lot harder to improve customizabillity if the foundation hinder it.
And because of that it can be customized into anything the user wants, it can be made to behave exactly like vim or emacs and there's already good progress on those fronts. So many of the reason to use something else will disappear, personally I'm really looking forward to the vim-mode package to properly support international keyboards and I'll have vim's commands in Atom and be really happy.
All this while maintaining a high approachability. An average user can use it immediately and it has the functionality one would expect.
Both vim and emacs have a tendency to scare away potential users, that doesn't mean it's not worth it to get over that initial hurdle, but with Atom you don't have to.
It may not be a worthy contender yet, but because of it's philosophy and the groundwork I think it will be sooner or later. If it isn't already.
2
1
1
1
u/Technonick Sep 25 '15
As someone who is suffering through the pain that is MS Visual Studio after using vi, tmux and gcc, g++ for most of my computer programming classes, this is so very relevant.
0
u/en3r0 Sep 26 '15
Someone tell me right now why I should use vim instead of vi for my random text edits when using the command line.
3
u/AutoBiological Sep 26 '15
Vim has plugins in scripting language, and many plugins.
Vi is painful to use if you're used to vim. It works similarly, but then you go to do something and you can't. Something you just have to experience.
I guess a few useful things that may not be compatible with vi (not really sure, but if you run
:help <something>vim always says "not compatible" with vi-mode.)Highlight the current line you're one. Set a column for 80 chars (or any arbitrary column). Tab completions for loading new files. Make, yes that make. Full featured path finding. Ability to launch programming languages inside vim without leaving vim. Completions in general are built in. Syntax aware. Ability to create your own syntax and highlight files for whatever regex you decide works best.
If you're using neovim on the command line you're able to access the entire thing through a socket.
1
5
u/[deleted] Sep 25 '15
What’s the best (non-GUI) editor if I’m just editing config files, typing essays, occasional shell scripts/HTML, etc.? I’m tempted to go with Vim (if nothing else, because nearly every application has a Vim mode and consistency in interface is great), but I feel like it might have more features than I need.