Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Sunday, January 31, 2016

Everything I learned about linux in 60 hours, 1454226440

In the last everything in 24/today post I didn't post anything on getting commands into the actual vim file you are editing. Whell for that you can use :read, so for the date something like:

:read !date


Sun Jan 31 01:49:15 CST 2016

Like so.

I've been busy with packing for the move, and working on some weird software stuff I can't really talk about just yet and smashing against a few API's so none of the good stuff in this post, just more dates like, if you don't want to use my(everyone's) perl one:

perl -e "print(time());"

You can always use the command line:

date +%s

I actually do a lot of stuff with time. And I have an argument and a some awesome knowledge on why Unix Epoch Time is the best time system ever... As well as things about Leap Seconds...Oh dear the things I could talk about   leap seconds.

But what's the big haps your going to see besides some of that stuff. Well I found the Second Edition of Kernighan and Ritchie's C book...so oh my do you have some Classic  C stuff.

But OH DUSTY, WHY NOT C++. Go read jwz's wikipedia page, cause we agree on that wholeheartedly. Not that jwz actually knows me...

WE ARE NOT WORTHY
WE ARE NOT WORTHY
WE ARE NOT WORTHY


I had someone dis me for using perl today, all bragging about javascript and node, and I was like you don't understand I like node, and this conversation happened.


Facebook tier is the two words cut off at the bottom


Anyway for our one liner today I am tempted to talk about httpie, which is a python utility/module that makes everything easier. Sure curl is great, and you should know curl, cause it's classic and it's basic and it's         ubiqutious. But damn if httpie isn't a little sexier with a brighter syntax.


So let's pie this bitch:

http --verify no GET https://mechanicalpinata.com/bullshit X-Auth-Token:shittoken content-type:application/json
~                                                                            


So that's GETting mechanicalpinata.com/bullshit, with a header of content type and an X-Auth-Token, if you are already super comfortable with curl, no worries and skip on. But otherwise, learn commit and do.


Friday, January 22, 2016

Everything I learned about linux today 1453518423


I'm going to try and do a daily, update on everything I learn about linux the day of. I don't know how long I will do this, or if it will continue after I start working a regular job again. Today I watched "Linux Sucks" the 2016 one that happened on Thursday the 21st:

    January 2016     

Su Mo Tu We Th Fr Sa 

                1  2 

 3  4  5  6  7  8  9 

10 11 12 13 14 15 16 

17 18 19 20 21 22 23 

24 25 26 27 28 29 30 

31 



I was excited to watch it so I had been hoping the link would show in one of my feeds, and eventually it did. I knew Lunduke was going to talk about systemd, and I was pretty sure what his opinion would be, and I was write. I'm not going to tell it to you, you should watch it. If your reading this after Friday you are probably better of checking lunduke's channel, because I imagine he will have a higher quality version posted.

My primary complaint with systemd is that it feels very much at odds with the unix way. The core tenants being:


(i) Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features.
(ii) Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't insist on interactive input.
(iii) Design and build software, even operating systems, to be tried early, ideally within weeks. Don't hesitate to throw away the clumsy parts and rebuild them.
(iv) Use tools in preference to unskilled help to lighten a programming task, even if you have to detour to build the tools and expect to throw some of them out after you've finished using them.
Or summed down to a one liner, perl style:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
Systemd is a monolithic program that does many things. It also stores logs in binary, not plain text. So no I don't prefer it, but I can't say I really love what Mac did with launchd. And in fairness systemd improves boot times in comparison to init. 



I have other gripes with it as well, but I haven't decided if they're unfounded or not. Lennart in general does not particularly ascribe to the linux or posix rules.

So that said does this make him a bad guy, or systemd bad. It doesn't. I do really want devuan to be successful and I would really love to see a yum or dnf package managed system take it's lead. But systemd is assuredly great at speeding up boot times, and it may be great at the many other things it does as well.

Clearly that's just a rant I had in my head for a long time, not something I learned today but whatever.

Your daily one liner or regex:

I started with this, it was just because I was mad because I left the slash off a regex and wanted to prove to the smart ass that pointed it out, that I know my shit and stfu.
A vim regex:
%s/s\/potatoe\/potato/s\/potatoe\/potato\//g

then /u/EnTantoEnCuanto

:%s|toe|to/|g

And then my friend from IRC and /u/xurdm:

:%s|$|/|g

Sunday, January 17, 2016

Getting started with vim, stop using Nano.

Come on guys, when I'm standing behind you, and you fire up nano, I'm not thinking pleasant things. Not to say bad things about nano, pico and their ilk (no really say bad things, why are you using nano and pico).

If you're not already using vim and you are an admin or operator of any kind, take a second right now breathe in, and say to yourself "I am going to learn vim, I am committed." No, for real do it. I'll wait. Get a book if you have to.

Now say, "I will never use nano again."

Vim is a modal editor that is found on nearly all *nix machines. If vim isn't there vi will be, which is it's predecessor. You will at first be in a command mode, from this mode you can do basic things like save the file with these strokes ":w filename.txt" (write to filename.txt). You can also do basic searches by using "/" and the search term you want. To enter insert mode you need only hit the "i"
, and you can get back to command mode by hitting escape. Vim will most likely require a little set up, and on some distros, one setting in particular may in fact make it unusable. If the backspace is wonky, perhaps acting like you hit the insert key in Microsoft Word, you need to open, .vimrc in your home folder, and if it's not their create it(this is the only time in your life you are allowed to use nano, just forget the "never use nano" thing for a second then remember it afterward).  So just add this one line at a minimum:

set backspace=indent,eol,start

Here is my roaming .vimrc:

set expandtab   "changes tabs to spaces DO NOT USE TABS
set shiftwidth=4 " 4 characters for indenting
set showmatch " showmatch: Show the matching bracket for the last ')'?
set backspace=indent,eol,start "set the backspace so it behaves like a backspace
set nowrap " don't wrap by default
syn on                                   "syntax on
set completeopt=menu,longest,preview
set confirm          
set number
set wrap
set linebreak
set nolist

And on a few machines, because of a great vim post I read, I also add these:

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>


Those are for split jumping using only ctrl, and the vim movement keys(hjkl). I use the vertical split a lot, ":vsplit" or ":vs" I rarely use horizontal splits but if that's conducive to your style, maybe you have a vertical monitor or something, these entries help.

Regex in vim is one of my favorite things. I don't care how insane that sounds. So if I want to replace "whatever" in a post with "and a thing", and I want it case agnostic, and to do it no matter how many times it occurs on a line, or in the file:

:%s/whatever/and a thing/gi

It is important to note that vim uses POSIX regex and not Perl regex...so only the second best regex.

If you want to read more about vim, this is my favorite post on the internet about it.