Hi all,
What is the difference between vi or nano for editing a file? In your own opinion? I always used vi for editing files but some people say it's better to use nano. Is it just the user preference?
Hi all,
What is the difference between vi or nano for editing a file? In your own opinion? I always used vi for editing files but some people say it's better to use nano. Is it just the user preference?
Short answer: it isnt about which editor is objectively "better" — its about context. Use a low-friction editor when you only need one-off edits, and invest time in a modal editor when you spend significant time editing in the terminal, automating edits, or working on remote servers.
A few practical points that arent covered in-depth above: minimal Unix installs, rescue shells, and many recovery images almost always provide a vi-compatible editor, so knowing a handful of vi motions can save a stuck session. Conversely, nano is friendlier for newcomers and for quick edits on a desktop system, but it may not be installed everywhere. Also, never edit /etc/sudoers with a plain editor; use visudo, and when editing files as root prefer sudoedit to avoid permission and safety problems.
If you want to try vi/vim without diving in all at once, start small and practice a few commands until they become muscle memory. The tutor and a tiny cheat-sheet are usually enough:
vimtutor
i # enter insert mode
Esc # return to normal (command) mode
:wq # save and quit
:q! # quit without saving
u # undo
. # repeat last edit
:%s/old/new/g # global replace Tie-back to the thread: and highlight the usability angle, while and show the productivity payoff from learning vim. Try both: use nano until you feel limited, learn a few vi basics so youre never stranded, and then decide which workflow actually makes you faster.
Jump to Post— mike_2000_17 2,669It's basically user preference. Vi is meant to be a very comprehensive editor, and it has tons of commands and special features. Nano is more of a basic text editor (think "notepad in the terminal", i.e., nothing more than copy-paste, exit-save). I generally prefer nano because for the times that …
Jump to Post— L7Sqr 227I'll comment as a
vi(vim, actually) user.As mike_2000_17 mentions, when you are talking simply about 'notepad in the terminal' there is more overhead to
vi- edit mode vs. command mode is a good example. However, if you prefer to do most editing in the terminalvihas …
It's basically user preference. Vi is meant to be a very comprehensive editor, and it has tons of commands and special features. Nano is more of a basic text editor (think "notepad in the terminal", i.e., nothing more than copy-paste, exit-save). I generally prefer nano because for the times that I need a terminal-based text editor, I usually don't need a very complicated editor, and I don't like having to remember all the commands when all I ever need to do is write some text and then "save-and-exit" (and nano has a command-reminder at the bottom). I guess if you are used to vi (and know the commands) it is "better" than nano in the sense that it has more features, but to me, it's needlessly feature-rich for most things I do in a terminal-based text-editor.
I'll comment as a vi (vim, actually) user.
As mike_2000_17 mentions, when you are talking simply about 'notepad in the terminal' there is more overhead to vi - edit mode vs. command mode is a good example. However, if you prefer to do most editing in the terminal vi has a rich set of tools that are available (but not necessary). At a minimum, the syntax highlighting alone is often beneficial.
I think that, with little exception, there is not much differencce between the basic functionality of most editors. It really boils down to what you spend the time to become comfortable with. If you take the time to learn vi inside and out you will feel limited when you dont have access to it. If you master the emacs environment, kate, the visual studio editor, or any other fully functional editor you will become more productive with that tool.
If all you really want to do is place text to a file all tools are about the same and nano probably brings the least 'baggage' in the terminal setting.
Ohh crap, here we go with a potential flame/argument/back-and-forward/opinion thread. Oh well, it's been civilised so far, let's keep it that way.
I've used both vi and nano and prefer nano simply because I find it more user friendly. Then again, I never do serious editing in a terminal.
Until I got to grips with vim, I used to use nano quite a lot for editing text files on the command line. It took a little while to get my head around using vim, but learning to use it properly was time well spent IMHO!
Nowadays, I seem to spend a LOT of time with vim in the terminal. In fact I'd now go as far as saying it is my favourite text editor full-stop. Since learning to use vim, I've found that I can be far more productive using vim than any other editor I have tried before. But that's just my experience. Your mileage may vary! Heh heh!
I've even started using vim extensively on my Windows machine at work (via Cygwin terminal). On my 2nd monitor, I always have two cygwin terminals open. One for diffing/editing files in vim and another for running scripts and grepping through our code-repositories. Going off-topic here, but using grep seems to be much faster than using VS's built in search functionality. Often, when wanting to look something up in VS - I have to wait for the intellisense database to finish rebuilding. And it always seems to rebuild itself at the most inopportune moments. Whereas grep just starts searching instantly and generally tends to return results quicker than VS's search functionality. I only tend to use VS for debugging nowadays!
Getting back on topic:
At the end of the day a text editor is a text editor. Just another tool in the toolbox. As the others have said, for simple tasks you probably don't need anything more complicated than nano. But if you want something more powerful, or you have more complicated editing needs; I'd heartily recommend vi or vim!
I'm currently taking the plunge and trying to learn emacs too - which can also be ran from the command line. But I am having touble remembering all of the strange, esoteric and somewhat counter-intuitive keyboard shortcuts. In fact, I'm having far more trouble getting used to emacs than I had getting used to vim!
I've just started trying to relearn Lisp. And emacs has really good Lisp integration, especially with the Slime plugin installed. So using emacs kinda makes sense for coding in Lisp. But again, the unusual keyboard combos are really throwing me!
I've fallen in love with sublime. But it depends on what you are doing as well.
You cannot use sublime in the terminal. I think this discussion is about terminal-based text editors, such as nano, pico, vi, and emacs.
You can't use nedit in a console terminal either, but it is a great editor! I use it for almost all of my programming since it has syntax support for most computer languages out there, including c, c++, bash, php, java, make, et al.
And yes, text editor preferences tend to generate major wars! :-) Find what works well for you, and occasionally try something else to see if you might like it better.
And yes, text editor preferences tend to generate major wars! :-)
A computer geek is not really a computer geek without the occasional text-editor flame-wars! ;)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.