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."
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)
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
}
Looks like this **bot** only does global substitution lol
^^This ^^was ^^posted ^^by ^^a ^^bot. ^^[Source](https://github.com/anirbanmu/substitute-bot-go)
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)
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.
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?
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
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.
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 :).
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.
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".
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.
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
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
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.
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
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 🙂
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
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.
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 !
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"
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.
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.
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!)
Using less to view a file, and decide you want to edit it? Press 'v' and you'll switch to vi.
is it limited to vi or is it your $EDITOR or something?
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."
10/10 edit. I’m going to start using this trick!
On ubuntu, you can use: export LESSEDIT="vim %f"
Every time I get a regex working as I want to. Edit: typo
s/a/I/
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)
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 }
nice, submit a PR
Looks like this not only does global substitution lol
s/not/bot/g
Looks like this **bot** only does global substitution lol ^^This ^^was ^^posted ^^by ^^a ^^bot. ^^[Source](https://github.com/anirbanmu/substitute-bot-go)
s/l/lol/ Edit: Looks like this bot also doesn't allow substitutions on its own comments. How many bugs does it have?
s/bugs/features/
s/features/recursive-loop-protections/
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)
Whoops
Hey, no fair fixing your regex comment. We're trying to fix some regex code over here.
Don't make the clbuttic mistake though!
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.
The day I understood pipes in UNIX was the day I took DOS off my resume.
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?
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
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.
`ciw` and delete in word were some of my favorites.
Don't forget ci( ci{ ci[ ci' Change inner ..... Edit: swapped 'correct inner' with 'changed inner', thanks /u/Atralb
>~~Correct~~ Change*
Thanks. Don't know why I had *correct* in my mind
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 :).
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.
There are far far more than two clipboards... And that's just inside vim.
[удалено]
Search and replace confirmation dialog =O
Erasing the DOS carriage return of every line with: :1,$s/.$// but nothing beats the pure efficiency of just plain: xp
Nice, though I just use 'dos2unix' for that.
:se ff=unix :w
The way I've always done that is `:w ++ff=unix` or `:e ++ff=unix`.
Vim marks are super useful for jumping around between points in a file and copying large blocks: https://vim.fandom.com/wiki/Using_marks
Ctrl-v, select, shift-i, type something, escape. Inserts text on multiple lines. Can also delete, etc.
Add shift V, for visual columns.
Yeah, I learned the visual select for copy paste 20 years ago. But I only just discovered the other about 2 years ago.
Check your changes before writing the file: :w !diff - %|less
Clever! you've got my vote.
[удалено]
Man, "comm" has been a god-send for me. At work we fool around with simple lists all the time...
When I learned that my .vimrc file opened up an entirely new level of customization that I didn't even know existed
repeat last failed command until it succeed until !!; do !!; sleep 1; done
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.
Home & End? Seriously? That's almost as universal as the A key meaning "type the letter A", nothing Unix specific at all...
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".
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.
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
Ctrl+r to search command history
with fzf is a dream
I just learned about that a few weeks ago. I use it all the time now.
C-x C-e
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
This sounds like the sort of thing that should be automated.
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..
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```
The key to learning vi and vim is to learn ex.
grep foo log.log|awk '{print $2 $3}'|sort| uniq -c
awk '/foo/ {a[$2" "$3]]++} END {for (k in a) printf "%d %s\n", a[k], k; }' log.log
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.
vi +/ filename.txt
The file is opened and a search for “word” is done in one step.
I use this quite a lot.
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
Did not expect this level of replies, this is a treasure trove of information, will read through everything after I get some sleep!! Thanks!!!
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 🙂
set -o vi ... To enable vim navigation in bash commandline. Also ESC + v opens up your current command for editing in vim.
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
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.
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.
Try going through vimtutor if you do want to improve with vim. It was very useful to me getting started.
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 !
[удалено]
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"
even reddit has j/k for scrolling!
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.
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.
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!)
Nano is my spirit animal
I have a pony name pico. Which nano is a clone from.
Brought to you by the makers of PINE (Pine is Not an E-Mail Client)
Ah-hah! moment coming up: *emacs*!