Opinions wanted - Vim or Nano

Pages: 12
I just installed MSYS2, following the instructions here:

https://solarianprogrammer.com/2019/11/05/install-gcc-windows/

Primarily I downloaded it to update the Code::Blocks compiler.

https://solarianprogrammer.com/2019/11/16/install-codeblocks-gcc-windows-build-c-cpp-fortran-programs/

First impression MSYS2 might actually make it easier to learn and use command-line compiling. A good thing IMO. So I don't need to update the compiler, though I will later.

I noticed while following the install instructions the site mentioned there are a couple of terminal editors available. Vim and Nano.

OK, which editor do you people suggest I use. I downloaded both, dinked around for a couple of minutes with each, but want some feedback from experienced people.

Is there another terminal editor you'd recommend instead of Vim or Nano?
closed account (2z0kLyTq)
Vim advantages will not be realized if you are not a touch typist. I've noticed that a lot younger people can type quite quickly but are not touch typist; if you have to look at the keyboard when you type Vim will probably feel like a hindrance.

That said, I recommend Vim. I love using regular regex, and block select, which are not always implemented well with other text editors.

Can't speak about nano -- I no longer remember what it was like.

I've also noticed that many tutorials over complicate make/gmake. Remember to make sure you're able to read your makefiles.



Last edited on
If you're working remotely, vi[m] is ubiquitous on Unix systems as a terminal editor, which is a major advantage. It also seems very stable.

As far as editing text is concerned, I dislike vim's modality.
I am not working remotely, so the need for that is nullptr.

In my admittedly limited experience with Vim I can't seem to figure out how to actually get to the editor, though I am a touch typist for the most part. Vim looks to be powerful, but how to unlock the power I need a tutorial or a manual.

Nano, for me, seems to be easier to get along with since it acts more like a traditional DOS word processor. Simple for what I want to do. Edit code as text.

One thing I miss from using an IDE, the ability to easily format the code. Without running an external program. VS excelled at that.

Now, make files. Another thing I need to learn how to use. And use effectively at the command-line.

IDEs are nice, especially for this self-taught hobbyist programmer. But going back to the antediluvian ways to program is something I should learn.
Last edited on
closed account (2z0kLyTq)
Vim comes with a tutorial, type:

:help tut

remember to type [esc] first to get in normal mode
Last edited on
Type all 5 characters of [esc]? Serious question.

I was doing some web searches for a Vim tutorial/manual while I was typing my previous comment, and discovered the included tutorial. :)

I accidentally got into "normal" (editor) mode once, and how I did it I don't have a clue.

I can exit Vim easily, :q! That is about all I can do so far.

I can invoke generic help, and help on some topics. Not that the help was, well, of any help to this Vim noob.

I can see learning Vim will not be a "5 minutes and I'm expert" kinda thing. I feel like a 3 year old again having to learn this. >_<
Oooh, a Vim FAQ!

https://vimhelp.org/vim_faq.txt.html

Some meat for me to nosh on! :D
closed account (2z0kLyTq)
I'm sure you already figured it out, but I meant type the escape key.

To get to the FAQ you type:

:help FAQ

but you'll figure it out yourself.
closed account (2z0kLyTq)
Just so you know this is an adequate makefile for a hello world program:
1
2
CPPFLAGS=-std=C++17 -Wall -pedantic -g
CC=g++


You name the makefile 'makefile' no extension needed.

Then to compile all you need to type into the terminal is:
make hello

I'm assuming that you put both your makefile and your program in the same directory, and that the hello world program in named hello.cpp.

you may have to type:
gmake hello
Last edited on
I had looked at make files a couple of years ago, so some of the syntax is understandable.

Thanks for giving me a bit of a nudge about make files and usage, :)

Thank you both for relating your experience and opinions about Vim and Nano.

MSYS2 terminal/console windows have a *nix terminal style appearance.
Since you are on Windows, there is no limitation o. Choice of text editor. C::B has a nice one. I also recommend Notepad++ and Sublime.
The MSYS2 setup allows for embedded* terminal editors in the terminal window.

I already figured out using an external editor is possible since "it's Windows!" :)

The webpage that has the instructions for installing MSYS2 on Windows mentions two embedded terminal editors available, vim and nano.

So I downloaded both and played around with both for a bit.

Just asking for some expert opinions about using one or the other.

Or going external editor.

Maybe I am just being anal retentive, but I like being able to format my code with indents, braces, etc. Automatically as I type or manually later.

Something the VS editor has.

*Embedded is probably the wrong term. All I know is there are two editors available that are easily usable within the terminal window.
Last edited on
Personally, I only use msys2 to have the correct environment to build the library files (to get make to work properly), and I still build all my normal programs on the vanilla-Windows side. I know that text editors like Vim and Emacs can be really handy if you take the time to learn them, but I just haven't. I hear about Vim more often than Nano, if that means anything.

C::B drives mes nuts compared to Visual Studio, to be honest. I am currently still using it at home, but I really dislike how you can't jump through search results, I find myself repeatedly pressing Ctrl + F.
Last edited on
With regard to C::B, the deal breakers for me are:

There doesn't seem to be any way of doing any kind of version control;
There wasn't any background compilation to show errors as one types.

Not sure if any improvements have been made, I haven't used it for awhile.

Looks like I will be back to Qt Creator again, am starting a Postgres project with Qt as the front end.
I write most of my code/documents/etc. in Emacs. I've used all of the editors mentioned here at one point or the other, with the exception of the CodeBlocks integrated one.

Nano is far closer to Windows Notepad than a proper programmable editor. Definitely avoid it. It won't offer the same productivity benefits that other tools offer.

Personally, I definitely prefer not to edit text in the terminal emulator if I have a choice. Emacs works just fine in that capacity, but I prefer things the other way.
Last edited on
Cool, more feedback for me to consider. Thank you all! :)

Nano is far closer to Windows Notepad than a proper programmable editor.

That is one aspect of nano that makes it like it. Simple almost to a fault.
Simple almost to a fault.
That is the whole point of Nano — it is designed to be stupidly easy to use by anyone, just like Notepad.

And that is why I can’t stand it. It is too simple — so simple it is useless for anything big. Sure, quick emails and rc files are easy, but source code? Never.


I’ll take vim any day of the week and twice on Sundays.

If you have used less, you will easily transition to using vim. The only really off-putting thing about it is the modal state, which modern users are unaccustomed to (because it is annoying). But it makes powerful editing very easy if you pay attention.


Emacs is also another great choice. It has versions both for plain vanilla terminal editing and GUI editing. It also has an extensive command set, and will guide you through learning it if you ask nicely.

Hope this helps.
I am at the baby steps stage of learning command-line programming, so simple and easy to use for the moment makes for less frustrating road blocks.

Being a professional programmer is out of the question, learning for fun as a hobby is where I'm at.

I am not rejecting the suggestions of vim (or other editors) out of hand, really. The complexity makes the learning experience for me a lot more frustrating, so I am more likely to give up trying to learn and use command-line as not worth the effort.

That is what happened the times previously I tried to learn to use command-line. This go-around will be the 6th or 7th try.

The last time was almost a decade ago. Things have changed considerably since. C++11 and later, etc.

Hope this helps.

Very much so.

I'll likely need a push, gentle or otherwise, to not give up learning command-line programming so quickly. :)

I may be an old dog, but I really do want to learn new tricks.

Remember that the command line is really just a launch pad for other programs, with the added state of being “in” a specific directory.

Make yourself a cheat sheet of all the commands you will want to use regularly. For example:

WINDOWS                      LINUX                         MEANING
cd ..                        cd ..                         change to parent directory
cd quux                      cd quux                       change to "quux" subdirectory
cd \Users\FurryGuy           cd ~                          change to my home directory
dir                          ls                            list all files in directory
copy con quux.txt            cat > quux.txt                copy typed text to a new/overwritten file
^Z Enter                     ^D                            stop copying typed text
pushd quux                   pushd quux                    save current directory and change to quux
popd                         popd                          change back to saved directory
more quux.txt                less quux.txt                 view file
md quux                      mkdir quux                    create a subdirectory named "quux"
rd quux                      rmdir quux                    delete an (empty) subdirectory named "quux"
del quux.txt                 rm quux.txt                   delete the file "quux.txt"
copy quux.txt hello.txt      cp quux.txt hello.txt         duplicate the file "quux.txt" into a new file "hello.txt"
exit                         exit                          end the console/terminal session

And so on.

BTW, "^C" means Ctrl+C.


Controlling your PATH is paramount to using the console/terminal effectively.

Create a directory under your profile named "bin":
> cd \Users\FurryGuy
C:\Users\FurryGuy> md bin
C:\Users\FurryGuy> cd bin
C:\Users\FurryGuy\bin> dir
  [.]
  [..]
  0 files
C:\Users\FurryGuy\bin>


Now you want to add some aliases to help you at the command line.

C:\Users\FurryGuy\bin> copy con prompt.bat
@echo off
cls

:: All our utilities in ~/bin come first!
path C:\Users\FurryGuy\bin;%PATH%

:: This modifies how files are displayed to you when you type 'dir'
:: Order by name, grouping directories first
set DIRCMD=/ogn

:: These are your preferred macro aliases.
:: Here are a couple to get you started

doskey deltree=rd/s/q $*
doskey dird=dir/ad $*
doskey dira=dir/ah $*

doskey 7z="C:\Program Files\7-Zip\7z.exe" $*
doskey hxd="C:\Program Files (x86)\HxD\HxD.exe" $*
doskey npp="C:\Program Files (x86)\Notepad++\Notepad++" $*
doskey mcd=@md $* $T @cd $*
doskey mpath=for %A in ("%PATH:;=";"%") do @if not "%~A"=="" @echo   %~A

^Z Enter
C:\Users\FurryGuy\bin> 


As displayed, you can make various utilities very useful. I have 7-Zip installed in "Program Files", but HxD and Notepad++ in "Program Files (x86)". You must, obviously, provide the correct path to the programs you intend to have available and useful from the command-line.

Here’s an update to our cheat sheet:
7z a quux.7z quux   Zip the "quux" directory into an archive named "quux.7z"
7z x quux.7z        Unzip the "quux" archive
7z l quux.7z        List the contents of the "quux" archive
hxd quux.dat        Use HxD to examine the binary file "quux.dat"
npp quux.cpp        Use Notepad++ to edit "quux.cpp"
mcd quux            Make a subdirectory named "quux" and change to it
mpath               List all the directories in the %PATH%, in order, one directory per line


Now to add a shortcut to start your prompt.

1. Using Windows Explorer, navigate to your new C:\Users\FurryGuy\bin directory.
2. Right click and choose "New Shortcut"
3. Type "cmd.exe" in the box and click "Next"
4. Name your shortcut something convenient (like "Console") and click "Finish"
5. Right-click on the shortcut icon and click "Properties"
6. Make sure the "Target" reads as: "C:\Windows\System32\cmd.exe /K C:\Users\FurryGuy\bin\prompt.bat"
7. Set the "Start In" directory to "C:\Users\FurryGuy"
8. Click "OK".
9. Right-click the shortcut icon and click "Pin to Taskbar"


Now you can easily start a console session. Do so now.
Click the titlebar icon and choose "Properties".
Play with the options until you get the console to start up the way you like. For mine:
  Options:
    [x] Quick Edit Mode
    [x] Insert Mode
  Font:
    Size: 16
    Font: Consolas (or Lucida Console/Unicode)
  Layout:
    Set it to where you would like to see it and UNclick "Let System Position Window"
    I have mine set to use up most of the display, and aligned so that I can slam my mouse
    to the right side of the screen and frob the scrollbar.
Click "OK" and if it asks if you want to apply the changes to all future invocations, choose yes.

Type "exit" to terminate the console window.


I recommend you get a few GNU programs (like GNU "less" for Win32) and unzip them in your bin directory.


Setting up the MSYS2 is a similar process. Click on your MSYS2 icon (which you should have added to your Quick Launch as well) and it will dump you in your "Linux" home directory (which is on your C: drive as "C:\msys64\home\FurryGuy").

Type the following:
$ cat >> .bashrc
source %HOME/.profile
^D

That adds the ".profile" file (analogous to our "prompt.bat") to our MSYS2 startup. Now to create it.

First, I want to modify the prompt. I already know who I am and what machine I am using, but I still want pretty colors and to know what directory I am in. The PS1 variable is admittedly a bit scary-looking. You can read more about it at http://ss64.com/bash/syntax-prompt.html and http://tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html. Or just use the fancy wizard at https://www.kirsle.net/wizards/ps1.html.

$ cat > .profile
# prompt
export PS1='\n\[\033]0;\033[33m\]\w \[\033[32m\]\$\[\033[37m\] '

# aliases
alias dir='ls -CF'
alias dira='ls -CFa'

dird () {         # Make 'dird' command without
  if [ -n "$*" ]  # any arguments default to:
  then            #
    ls -Cd "$@"   #   dird */
  else
    ls -Cd */
  fi
}

alias cls=clear
alias copy=cp
alias del=rm
alias deltree='rm -r -f'
alias md=mkdir
alias move=mv
alias rd=rmdir
alias ren=mv

alias 7z='/c/Program\ Files/7-Zip/7z.exe'
alias hxd='/c/Program\ Files\ \(x86\)/HxD/HxD.exe'
alias npp='/c/Program\ Files\ \(x86\)/Notepad++/Notepad++'

^D

And so on.

A lot of these aliases are just to add “DOS”-style commands to the *nix prompt. Remember, though, it’s just a façade. If you spend much time with the MSYS console, you will eventually need to learn how to use the actual *nix commands.

You might even be inclined to make a bunch of macro-aliases in ~\bin\prompt.bat that mimic *nix commands. Even so, it is better to get used to using both systems’ native commands.

Notice also how we aliased a number of our non-unix programs, like our favorite editor, so we can start them from the MSYS command-line.

Finally, notice that odd-looking one for dird. That’s a bash shell function — weird magic you can study later.


Heh, well, that gets you started with normal stuff. For a future installment, we’ll get various compilers working for you without cluttering the path...

Last edited on
> I like being able to format my code with indents, braces, etc. Automatically as I type or manually later.
:help autoindent
:help C-indenting
:help gq
(I have clang-format as formatpgr)


> Make yourself a cheat sheet of all the commands you will want to use regularly
cd -

change to previous directory


if you are going to work on the terminal, I'll recommend you tmux. I'll give you tabs, splits and workspaces.
Pages: 12