80 votes
Accepted

Change default editor to vim for _ sudo systemctl edit [unit-file] _

First method, you can add this line to ~/.bashrc: export SYSTEMD_EDITOR=vim And then sudo visudo and add this line: Defaults env_keep += "SYSTEMD_EDITOR" Start new bash session to take effect, ...
林果皞's user avatar
  • 5,156
75 votes
Accepted

Text editor for printing C++ code

Well, if you want to go the extra mile, do it in LaTeX and provide a professional level PDF file. You haven't mentioned your distribution so I'll give instructions for Debian based systems. The same ...
terdon's user avatar
  • 242k
75 votes
Accepted

How can I set the default editor as nano on my Mac?

Set the EDITOR and VISUAL environment variables to nano. If you use bash, this is easiest done by editing your ~/.bashrc file and adding the two following lines: export EDITOR=nano export VISUAL="...
Kusalananda's user avatar
  • 335k
63 votes

VISUAL vs. EDITOR – what’s the difference?

The accepted answer is probably a good, short treatment, but this will be an attempt to go deeper on when the distinction between VISUAL and EDITOR might still matter (building on Adam Katz's answer). ...
robla's user avatar
  • 733
34 votes

Non-root user getting root access after running "sudo vi /etc/hosts"

The non-root user became root as soon as they successfully ran sudo (given the assumed root target user); they started running vi as root. When you ask vi for a shell, it dutifully runs a shell, as ...
Jeff Schaller's user avatar
  • 67.3k
31 votes

How to make Vi work as Emacs in Git Bash shell?

You can't do it that way. vi is vi and emacs is emacs. If you are not happy with the default editor, do git config --global core.editor path-to-emacs.exe-on-your-machine You can install emacs ...
Philippos's user avatar
  • 13.5k
29 votes

Text editor for printing C++ code

I'd usually use enscript: something like $ enscript --highlight=cpp --header='|Real Name|Class 101' --footer='|Page $% of $=|' -poutput.ps *.cpp will be a start - ...
Useless's user avatar
  • 4,810
26 votes

Change default editor to vim for _ sudo systemctl edit [unit-file] _

You are setting the variables for your own user, but are running the systemctl command as root (sudo). Therefore, the variables you've set for your user are irrelevant. To fix this, you can either (...
terdon's user avatar
  • 242k
24 votes

Console Text Editor with Windows-like keyboard shortcuts (ctrl-z, x, c, v)

Try Micro. https://github.com/zyedidia/micro Micro is a terminal-based text editor that aims to be easy to use and intuitive, while also taking advantage of the full capabilities of modern terminals. ...
PJ Brunet's user avatar
  • 783
20 votes

How do I change the default text editor in the Debian (squeeze) distro

The solution mentioned above works, but it isn't scriptable. If you want to do this in a scriptable (non-interactive) fashion, you should use --set: # update-alternatives --set editor /usr/bin/vim....
Joel Griffiths's user avatar
16 votes

Non-root user getting root access after running "sudo vi /etc/hosts"

If sudo vi /etc/hosts is successful, it means that the system administrator has allowed the user to run vi /etc/hosts as root. That's the whole point of sudo: it lets the system administrator ...
Gilles 'SO- stop being evil''s user avatar
15 votes
Accepted

How to properly edit system files (as root) in GUI (and CLI) in Gnu/Linux?

You shouldn’t run an editor as root unless absolutely necessary; you should use sudoedit or sudo -e or sudo --edit, or your desktop environment’s administrative features. sudoedit Once sudoedit is set ...
Stephen Kitt's user avatar
15 votes
Accepted

Using the caret symbol (^) in substitutions in the vi editor

In the vi editor, as well as in both ex and ed (as found on BSD systems), the ^ addresses the previous line. This means that the command ^d would delete the previous line, ^m. would swap this line ...
Kusalananda's user avatar
  • 335k
14 votes
Accepted

What text editor was used by Thompson and Ritchie in the writing of Unix?

I think your advised time line is correct. At the very beginning before Unix (called Unics at 60s, standing for UNiplexed Information and Computing Service) , Bell Labs had focused on the Multics ...
George Vasiliou's user avatar
13 votes
Accepted

Using Visual Studio Code as EDITOR e.g. with sudoedit

You need to tell the editor to wait: SUDO_EDITOR="/snap/bin/code --wait" sudoedit /etc/fstab Without that option, VS Code forks, or notifies an already-running instance, and control ...
Stephen Kitt's user avatar
12 votes

Move in crontab -e editor

You can pick any editor you like by setting the $EDITOR variable before calling crontab -e e.g. $ EDITOR=emacs crontab -e will run emacs as your editor. If you have a favourite editor then you can ...
Stephen Harris's user avatar
12 votes
Accepted

Export EDITOR with a flag

Use a wafer-thin shell wrapper: #!/bin/sh exec /usr/local/bin/mvim -v "$@" And stash that somewhere (somewhere in PATH or maybe in ~/libexec or whatever) and then set that wrapper as the EDITOR ...
thrig's user avatar
  • 35k
11 votes

Earliest viewer for viewing .json files?

jq is a json processor (like sed for json) which can also be used to pretty-print json documents. cat yourfile.json | jq
Bryce Guinta's user avatar
11 votes
Accepted

How to quit the `mg` editor?

Ok, so I'm not sure what the ' means here, but pressing ctrlx and ctrlc actually worked: C-x C-c' save-buffers-kill-emacs save-buffers-kill-emacs Offer to save modified buffers and quit mg.
ruohola's user avatar
  • 282
10 votes

How can I set the default editor as nano on my Mac?

I had this same challenge when setting up my new MacBook Pro. To elaborate more on Kusalananda's answer To switch to your editor of choice (say nano) you will need to add the following lines to your ~/...
Promise Preston's user avatar
9 votes

VISUAL vs. EDITOR – what’s the difference?

$VISUAL is a more capable and interactive preference over $EDITOR. If undefined, anything seeking $VISUAL should then try $EDITOR next. Some people have adopted a modern convention denoting $VISUAL as ...
Adam Katz's user avatar
  • 3,965
9 votes

Text editor for printing C++ code

You can use the :TOhtml command in vim. This renders what you see (i.e. syntax highlighting) as html. From there, a web browser that can print to pdf works, as you can usually customize the header/...
Shade's user avatar
  • 191
9 votes
Accepted

Open default text editor from terminal

In Ubuntu exist a command called xdg-open, that opens a file or URL in the user's preferred application, so you can open several types of files with the default program pre-defined. xdg-open ...
Luis Ángel Rodríguez's user avatar
9 votes

Editing text files in WSL with Notepad++

I use notepad++ with my WSL (ubuntu) as the default editor for both Windows and Linux and have setup so that it is launched from both contexts for files under either filesystem. My setup: Launching ...
Kelly Trinh's user avatar
8 votes

vi/vim, how can I write out a number of lines to a new file

If you know the line numbers that you want to write, you can do it from the command line: vim -c "100,200w new_file.txt" -c wq original_file.txt
Akavall's user avatar
  • 233
8 votes
Accepted

Cannot open GUI editors in superuser mode

You shouldn’t run an editor as root to edit system files, you should use sudoedit (especially since you have sudo set up already). That will make a copy of the file, that you can edit, open it in the ...
Stephen Kitt's user avatar
8 votes

Change default editor to vim for _ sudo systemctl edit [unit-file] _

I use a shell alias: sc='sudo SYSTEMD_EDITOR=/bin/vi /usr/bin/systemctl' Then just: sc edit service-name It's also useful for generally avoiding typing 7 out of the 9 characters of systemctl in ...
Tom Hale's user avatar
  • 30.5k
8 votes
Accepted

How to delete current word in nano text editor?

Save this file to ~/.nanorc and ctrl+] cuts the word to the left, and ctrl+\ cuts right This works for me in nano version 2.5 bind ^] cutwordleft main bind ^\\ ...
activedecay's user avatar
8 votes

Debian editor with syntax highlight for DOT language

Vim has this built-in: https://github.com/vim/vim/blob/master/runtime/syntax/dot.vim. Mode for Emacs, can be installed from MELPA: https://github.com/ppareit/graphviz-dot-mode
Arkadiusz Drabczyk's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible