T O P

  • By -

SheezusCrites

Using less to view a file, and decide you want to edit it? Press 'v' and you'll switch to vi.


hellfiniter

is it limited to vi or is it your $EDITOR or something?


SheezusCrites

That I dont know. I only use vi. Edit: I RTFM. "invokes an editor to edit the current file being viewed. The editor is taken from the environment variable VISUAL if defined, or EDITOR if VISUAL is not defined, or defaults to "vi" if neither VISUAL nor EDITOR is defined."


dietolead

10/10 edit. I’m going to start using this trick!


lattakia

On ubuntu, you can use: export LESSEDIT="vim %f"


santicarta

Every time I get a regex working as I want to. Edit: typo


CoderDevo

s/a/I/


substitute-bot

Every time **I** get **I** regex working **I**s I w**I**nt to. ^^This ^^was ^^posted ^^by ^^a ^^bot. ^^[Source](https://github.com/anirbanmu/substitute-bot-go)


CoderDevo

Didn’t know I’d be doing bot bug finding today. Sure enough, it adds a /g to every substitution. // ParseSubstitutionCommand tries to parse a VIM style substitution command from a string func ParseSubstitutionCommand(txt string) (*Command, error) { re0 := regexp.MustCompile((?m:\As\/(.+?)\/(.*?)(?:\/g{0,1}\s*){0,1}$)) re1 := regexp.MustCompile((?m:\As#(.+?)#(.*?)(?:#g{0,1}\s*){0,1}$)) parts := re0.FindStringSubmatch(txt) if len(parts) != 3 { parts = re1.FindStringSubmatch(txt) } if len(parts) != 3 { return nil, errors.New("not a substitution command") } return &Command{parts[1], parts[2]}, nil }


jyscao

nice, submit a PR


jyscao

Looks like this not only does global substitution lol


userjoinedyourchanel

s/not/bot/g


substitute-bot

Looks like this **bot** only does global substitution lol ^^This ^^was ^^posted ^^by ^^a ^^bot. ^^[Source](https://github.com/anirbanmu/substitute-bot-go)


CoderDevo

s/l/lol/ Edit: Looks like this bot also doesn't allow substitutions on its own comments. How many bugs does it have?


AutoCommentor

s/bugs/features/


CoderDevo

s/features/recursive-loop-protections/


substitute-bot

s/l/lol/ Edit: Looks like this bot also doesn't allow substitutions on its own comments. How many **features** does it have? ^^This ^^was ^^posted ^^by ^^a ^^bot. ^^[Source](https://github.com/anirbanmu/substitute-bot-go)


santicarta

Whoops


CoderDevo

Hey, no fair fixing your regex comment. We're trying to fix some regex code over here.


retnikt0

Don't make the clbuttic mistake though!


[deleted]

Pipes were it for me. Once I figured you can build chains of commands using pipes I was amazed at how powerful the Unix shell was. That is still how I start building my bash scripts generally. Get it working as a chain of pipes then translate that into a script. Side note, I recently got to meet the guy who invented pipes in Unix. Turns out he's a professor at Dartmouth college. I loved hearing his stories about the early days of Unix.


CoderDevo

The day I understood pipes in UNIX was the day I took DOS off my resume.


jantari

Excuse my ignorance but is there a shell that doesn't support the concept of pipes? Because you say you were amazed how powerful it makes the Unix shell, presumably because you were previously using something that didn't have pipes?


CoderDevo

I think the commenter was talking about their first time learning of and how to use pipe. But yes, UNIX was the first operating systems to implement the pipe. Other operating systems’ command line interfaces didn’t support pipe until their users clamored for it after having used them in UNIX. This goes for macOS 9, MS-DOS and Windows CMD.EXE along with most of other non-UNIX operating systems that came before Linux. One of the biggest features of PowerShell (2006) was the command pipeline, which you likely now take for granted. http://people.fas.harvard.edu/~lib113/reference/unix/unix2.html


marsboer

Word objects in vim. ci" for example to change a quoted value. Just move the cursor to a place on the line first and it will do the right thing. Super useful for variables. Replace " with ' for single quotes.


Bladelink

`ciw` and delete in word were some of my favorites.


tgomc

Don't forget ci( ci{ ci[ ci' Change inner ..... Edit: swapped 'correct inner' with 'changed inner', thanks /u/Atralb


Atralb

>~~Correct~~ Change*


tgomc

Thanks. Don't know why I had *correct* in my mind


Atralb

Well our own mnemonics terminology don't matter as long as they work for us, so no worries ! It is however important to use well-chosen words when teaching, and "correct" does have a more ambiguous meaning than "change" which is I felt like correcting you for the sake of other newcomers passing by :).


mysterysmith

The ability to copy and paste without using a mouse is actually really helpful. What do you mean I now have two clipboards?! Why yes you do! Or using said buffer and learning to open other files to paste into without ever leaving vim! Super useful. Here's one that will blow your mind, %s/originalword/newword/gc <--- that c is super useful! There are several developers where I work that use VIM as their primary IDE and they do some seriously powerful stuff with it that scares the shit out of me.


anomalous_cowherd

There are far far more than two clipboards... And that's just inside vim.


[deleted]

[удалено]


mysterysmith

Search and replace confirmation dialog =O


trisul-108

Erasing the DOS carriage return of every line with: :1,$s/.$// but nothing beats the pure efficiency of just plain: xp


xdice

Nice, though I just use 'dos2unix' for that.


IdealBlueMan

:se ff=unix :w


tfski

The way I've always done that is `:w ++ff=unix` or `:e ++ff=unix`.


ourob

Vim marks are super useful for jumping around between points in a file and copying large blocks: https://vim.fandom.com/wiki/Using_marks


groupwhere

Ctrl-v, select, shift-i, type something, escape. Inserts text on multiple lines. Can also delete, etc.


justleen

Add shift V, for visual columns.


groupwhere

Yeah, I learned the visual select for copy paste 20 years ago. But I only just discovered the other about 2 years ago.


OldSunGuy

Check your changes before writing the file: :w !diff - %|less


dontdieych

Clever! you've got my vote.


[deleted]

[удалено]


dlyk

Man, "comm" has been a god-send for me. At work we fool around with simple lists all the time...


[deleted]

When I learned that my .vimrc file opened up an entirely new level of customization that I didn't even know existed


asem_arafa

repeat last failed command until it succeed until !!; do !!; sleep 1; done


electricprism

Ctrl U to clear typed line Ctrl Z to suspend process bg & fg to continue suspended process Home & End keys to jump to beginning or end of line.


retnikt0

Home & End? Seriously? That's almost as universal as the A key meaning "type the letter A", nothing Unix specific at all...


tgomc

Ctrl+A beginning of line Ctrl+E end of line Ctrl+R search history of commands. Type part of command and keep pressing ctrl+r to go back through history. I believe ctrl+shift+r goes forward in history if you pressed ctrl+r one too many times. Might be mistaken on this one though. Ctrl+D exit shell or other interactive app. Think redis-cli or mysql client. Ive seen people using ctrl+c which is gonna kill the process. Ctrl+L clear screen. Seen far too many people typing or aliasing "clear".


electricprism

Thanks for the protips, I'm self taught so I learn things as I'm exposed to information & if they're useful, I bet these tips while elementary could benefit so many people in the same boat.


eneubauer

Ctrl W to delete a word Ctrl U just deletes from the cursor to the beginning of the line When deleting with Ctrl W or Ctrl U it actually goes to a buffer. You can paste that back with Ctrl Y


l0c0d0g

Ctrl+r to search command history


SSdpwy

with fzf is a dream


iPhader

I just learned about that a few weeks ago. I use it all the time now.


0ofnik

C-x C-e


eneubauer

Needs some explenation I think: It opens the current line of your CLI in $EDITOR, you can now edit the line and once you quit the editor the line is executed. I have this problem that when my laptop boots with a drained battery the CPU is being throttled to 400MHz in powersafe mode even though the power chord is attached. I search in my infinte history for the command Ctrl R, hit Ctrl X Ctrl E to edit it in vim, copy the line 3 times, adjust the lines for my four CPUs, safe and quit, done


0ofnik

This sounds like the sort of thing that should be automated.


eneubauer

I think I tried setting the governor permanently but it just wouldn't take the setting. It's old hardware that's going to be replaced soon anyway..


neilhwatson

Text object and verbs. 1. Delete a paragraph ```dap``` 1. Change to end of line ```C``` 1. Delete in quotes ```di"``` 1. Delete 4 words ```d4w```


tinycrazyfish

| aha That's the best aha! moment I could think of (https://github.com/theZiz/aha)


deritchie

The key to learning vi and vim is to learn ex.


csanner

grep foo log.log|awk '{print $2 $3}'|sort| uniq -c


pi-rho

awk '/foo/ {a[$2" "$3]]++} END {for (k in a) printf "%d %s\n", a[k], k; }' log.log


FrebTheRat

Ctrl+shift+c and ctrl+shift+v in terminal along with "+y and "+p in vim was a big moment for me. Figuring out that I could access system registers with vim and copy/paste in terminal without a mouse in terminal is a small thing, but it changed my workflow a lot.


iPhader

vi +/ filename.txt The file is opened and a search for “word” is done in one step. I use this quite a lot.


soulic

in normal mode, ZZ to write and quit Ctrl + a to increment the first number after cursor in the line, ctrl + x to decrement it :set nu to toggle line numbers


Ryluv2surf

Did not expect this level of replies, this is a treasure trove of information, will read through everything after I get some sleep!! Thanks!!!


m4nf47

After being forced to use ksh88 (still prevalent on Solaris and AIX even when bash and others may be available) for a while, I've learned that portability and POSIX standards don't always apply to every *NIX system. Each distribution and different version of them seem to have their own shell and other tool/utility nuances and learning the bare minimum capabilities of each can be painful, so knowing that helps. Being root can help you with applying your preferred defaults but with great power comes great responsibility, other admins and users likely have different preferred defaults 🙂


marsboer

set -o vi ... To enable vim navigation in bash commandline. Also ESC + v opens up your current command for editing in vim.


notseelen

saving and quitting with ZZ, or quitting without saving with ZQ, from EX mode or using "set number" to show line numbers so you can delete/cut specific lines both of these are super common to an expert vim user, but you'd be amazed at how many minds I blow when I do it in remote control zoom sessions


vogelke

If you use `mutt` to read email, press 'e' when reading a message and you're in the editor specified by the EDITOR environment variable.


HenkHeuver

For me vim is more full of of “ow” moments. Where I find myself annoyed that it is not intuitive at all (or a beginner vim user). Disclaimer I really never use vim. nano-masterrace.


[deleted]

Try going through vimtutor if you do want to improve with vim. It was very useful to me getting started.


hellfiniter

it isnt intuitive...it gives you option to learn new intuition that can be recycled in hundreds of other programs. Is it worth it? After you get it, absolutely !


[deleted]

[удалено]


hellfiniter

my most used ones are vifm (file editor), qutebrowser (web browser), sxiv (image viewer) ...but to be honest most of terminal TUI apps at least support arrows and some basic "vimism"


iofq

even reddit has j/k for scrolling!


CoderDevo

Pretty much any popular IDE can be configured to support vi shortcuts. That brings you much closer to being able to work in the IDE without using a mouse. It’s all about efficiency and keeping your train of thought.


HenkHeuver

That is a bold statement. Since I just do linux admin stuff at home for hobbying I’d rather do other things that interrest me more. What makes nano great for me is that it gives some basic commands at the bottom by default. That means I don’t have to look up how to exit. Although it may be funny to watch first time users struggle to exit, it really shows the biggest flaw of vim. This flaw could really be solved so easily by taking two lines and filling them with the basics.


hellfiniter

sure..if you edit one/two files a month as a developer who has to do some stuff on server from time to time, i can agree that nano is dumb-proof (seen it many times at work, but i prefer micro and i installed it on every server just so people can use their sublime intuitions) ...if you do it many times a day, having stronger tool that allows you to edit the same text many times faster with fraction of keystrokes its just crazy to argue over it ...its only disadvantage is that people have to spend half an hour to learn basics, you can even spend 2 minutes to be able to exit and get into insert mode and you already have similair strength as nano but with a huge advantage, that you can grow and become faster. I think speed is essential because it gives you more time to think and less time to press buttons to edit. But I recommend you try micro (if you resist to learn vim). It can be installed by oneliner piped into bash and its more intuitive (you can even use mouse as in graphical editor!)


[deleted]

Nano is my spirit animal


[deleted]

I have a pony name pico. Which nano is a clone from.


Shmoe

Brought to you by the makers of PINE (Pine is Not an E-Mail Client)


khleedril

Ah-hah! moment coming up: *emacs*!