Uncategorized

How To Use Vim In Termux

Vim

What is Termux?

Termux is an android application which is an emulator and it is also a Linux environment app. There is no particular need of setting it up or rooting the phone, It works directly. The additional packages are available using APT package manager. Termux repositories are hosted by JFrog Bintray.

What are the uses of Termux?

There are many uses of termux, Some of them are:

  • Data processing with Python.
  • Programming in a development environment.
  • Downloading and managing files and pages using time-established tools.
  • Learning the basics of the Linux command line environment.
  • Running an SSH client.
  • Synchronizing and backing up your files.

Some of the basic commands of Termux are:

To Update

apt update

To check whether app is properly installed, we use:

pkg install sl
sl

If the termux is properly installed, we will be seeing a moving train.

To see all the processes which are running in Termux, we use

top

To display the text in a different style, we use

apt install figlet
figlet word

To see matrix backgroud animation, we use

apt install cmatrix
cmatrix + ENTER

Using termux we can also find the factors of numbers, To do that we need to install coreutils.

apt install coreutils
factor 2020

One of the commands that I personally like is w3m. It is used to open any url from this termux.

apt install w3m
w3m tdummies.blogspot.com

We can also install metasploit using termux. To do that we first need to install curl.

apt install curl

After installing curl, we need to transfer data.

curl -LO https://raw.githubusercontent.com/Hax4us/Metasploit_termux/master/metasploit.sh

To get the access permission.

chmod 777 metasploit.sh

Now,

./metasploit.sh

In the above mentioned manner you can install any packages to your smart phone based on your need. To learn more about different packages available

What is Vim and Why use Vim?

Willson Mock

Willson MockJan 6, 2016·3 min read

First, a disclaimer: I’m, by no means, a Vim expert. In fact, I’m in the same newbie boat as most of you except I’ve recently started using Vim more seriously at work. For those of you who are still reading, you probably have an idea of what Vim is but in case you don’t, here’s a quick description.

Vim is just a text editor. That’s it. If you’re used to using Notepad (Windows), Sublime Text (Windows / Mac), Atom (Windows / Mac), Nano (Linux), or any text editor, Vim is just another program that allows you to write and edit text.

So what makes Vim special?

Compared to other text editors, 2 aspects make Vim stand out:

Efficiency

This is the big one. Vim is all about efficiency. And there’s a couple of angles from which it approaches efficiency.

Core to Vim’s belief is that most people spend more time editing existing text than writing new text. This is especially true for software engineers who are often tasked with enhancing and maintaining existing code. Even if you’re not a software engineer, think back to when you were writing essays in college — yes, it probably took you a long time to reach the finished product but that’s because you revised it along the way and proofread it 100 times after finishing your initial draft.

Vim allows you to be efficient by forcing you to only use the keyboard (yes, that means no more mouse!) and then giving you the ability to use existing keyboard shortcuts as well as customize and create new ones for completing repetitive tasks quickly. I won’t go into detail about configuring your .vimrc file in this post, but essentially, your .vimrc file is just a plain old text file that Vim processes each time its loaded, and it contains all the shortcuts and configurations to make your Vim editor unique to you. This ability to customize Vim to suit your typing needs is what ultimately lets Vim shred through text at the speed of thought!

Ubiquity

This is also a pretty cool aspect of Vim, which is that it’s everywhere. It’s available on basically every major platform you can think of. Whether you’re using a Mac, Windows, or some Linux distribution, Vim’s got you covered. In particular, if your day to day work involves working in the ssh’ed terminal sessions, Vim is your only text editor available.

Why doesn’t everyone use Vim then?

It’s true that Vim’s a powerful text editor and in this post, I haven’t even scratched the surface of what it can do yet. But like all powerful tools, there’s a learning curve to using it. Just like I don’t expect you to know how to beautifully edit photos immediately in Adobe Photoshop, I don’t expect to become an expert in Vim overnight. But the learning curve is over exaggerated — you can totally get up and running and become productive in Vim after following the vimtutor tutorial (which takes 30 minutes or so).

Getting Started

I’ll end this brief post by showing you how to get your first taste of Vim. For those of you using a Mac, you can follow along the screenshots I’ve attached:

On your Mac, open your terminal application.

I’m using iTerm.

On the shell prompt, type in “vimtutor”.

1*XiBJG4GVgBlr6uyov6t5Eg

That’s it! Now go ahead and follow along the instructions and soon you’ll be able to get up and running editing and writing text in Vim!

1*yvLgDNvsyHxqhcG vpywbw

HOW TO USE VIM IN TERMUX

  1. Install termux from Play Store. If you already installed it skip this step.
  2. Open termux and type: apt update and press enter after the command run type apt upgrade and press enter
  3. Type pkg install vim after the installation type vim to lunch the tools.

How do I use Vim?It’s relatively simple:

  1. Open a new or existing file with vim filename .
  2. Type i to switch into insert mode so that you can start editing the file.
  3. Enter or modify the text with your file.
  4. Once you’re done, press the escape key Esc to get out of insert mode and back to command mode.
  5. Type :wq to save and exit your file.

Vim commands#

The following is a list of frequently used commands and what they do. Many of the commands can be made to repeat by adding a number to the command. This is not an exhaustive list because more advanced commands, such as how to use multiple buffers, are not included. However, just about all of the basic commands for opening, editing and saving documents are included as well as commands that enable you to find and replace text and work with multiple documents.

1. Basic Vim commands#

The most simple commands allow you to open and close documents as well as saving them. As with most other text editors, there are protections in place to help you avoid exiting the editor without having saved what you’re working on.

:help [keyword] – Performs a search of help documentation for whatever keyword you enter

:e [file] – Opens a file, where [file] is the name of the file you want opened

:w – Saves the file you are working on

:w [filename] – Allows you to save your file with the name you’ve defined

:wq – Save your file and close Vim

:q! – Quit without first saving the file you were working on

2. Vim commands for movement#

When using movement commands, you can put a number in front of them to make Vim complete a command multiple times. For example, 5h will move your cursor five spaces to the left, and 90j will put your cursor at the beginning of the 90th line down from where your cursor currently is.

h – Moves the cursor to the left

l – Moves the cursor to the right

j – Moves the cursor down one line

k – Moves the cursor up one line

H – Puts the cursor at the top of the screen

M – Puts the cursor in the middle of the screen

L – Puts the cursor at the bottom of the screen

w – Puts the cursor at the start of the next word

b – Puts the cursor at the start of the previous word

e – Puts the cursor at the end of a word

0 – Places the cursor at the beginning of a line

$ – Places the cursor at the end of a line

) – Takes you to the start of the next sentence

( – Takes you to the start of the previous sentence

} – Takes you to the start of the next paragraph or block of text

{ – Takes you to the start of the previous paragraph or block of text

Ctrl + f – Takes you one page forward

Ctrl + b – Takes you one page back

gg – Places the cursor at the start of the file

G – Places the cursor at the end of the file

# – Where # is the number of a line, this command takes you to the line specified

3. Vim commands for editing#

Those who use Vim tend to use the term “yank” where most people would use the terms copy and paste. Therefore, the command for copying a word is yw, which stands for yank word, and the command for pasting whatever has been copied is p, meaning put. If you look up additional commands in the future, it can be confusing if you don’t know what yank and put mean when using Vim.

You also have two options for how to select text. You can either use commands like dd, which deletes a single line, and yy, which copies a single line, or you can highlight text and then copy it to the unnamed register. The paste commands work the same whether you’ve highlighted text or used a command to automatically copy it.

As with movement commands, putting a number in front of the command can increase the number of times a task is completed. For instance, putting a number in front of yy will increase the number of lines copied, so 5yy will copy five lines.

yy – Copies a line

yw – Copies a word

y$ – Copies from where your cursor is to the end of a line

v – Highlight one character at a time using arrow buttons or the h, k, j, l buttons

V – Highlights one line, and movement keys can allow you to highlight additional lines

p – Paste whatever has been copied to the unnamed register

d – Deletes highlighted text

dd – Deletes a line of text

dw – Deletes a word

D – Deletes everything from where your cursor is to the end of the line

d0 – Deletes everything from where your cursor is to the beginning of the line

dgg – Deletes everything from where your cursor is to the beginning of the file

dG – Deletes everything from where your cursor is to the end of the file

x – Deletes a single character

u – Undo the last operation; u# allows you to undo multiple actions

Ctrl + r – Redo the last undo

. – Repeats the last action

4. Vim commands for searching text#

Like many other text editors, Vim allows you to search your text and find and replace text within your document. If you opt to replace multiple instances of the same keyword or phrase, you can set Vim up to require or not require you to confirm each replacement depending on how you put in the command.

/[keyword] – Searches for text in the document where keyword is whatever keyword, phrase or string of characters you’re looking for

?[keyword] – Searches previous text for your keyword, phrase or character string

n – Searches your text again in whatever direction your last search was

N – Searches your text again in the opposite direction

:%s/[pattern]/[replacement]/g – This replaces all occurrences of a pattern without confirming each one

:%s/[pattern]/[replacement]/gc – Replaces all occurrences of a pattern and confirms each one

5. Vim commands for working with multiple files#

You can also edit more than one text file at a time. Vim gives you the ability to either split your screen to show more than one file at a time or you can switch back and forth between documents. As with other functions, commands make going between documents or buffers, as they’re referred to with Vim, as simple as a few keystrokes.

:bn – Switch to next buffer

:bp – Switch to previous buffer

:bd – Close a buffer

:sp [filename] – Opens a new file and splits your screen horizontally to show more than one buffer

:vsp [filename] – Opens a new file and splits your screen vertically to show more than one buffer

:ls – Lists all open buffers

Ctrl + ws – Split windows horizontally

Ctrl + wv – Split windows vertically

Ctrl + ww – Switch between windows

Ctrl + wq – Quit a window

Ctrl + wh – Moves your cursor to the window to the left

Ctrl + wl – Moves your cursor to the window to the right

Ctrl + wj – Moves your cursor to the window below the one you’re in

Ctrl + wk – Moves your cursor to the window above the one you’re in

6. Marking text (visual mode)#

Visual mode allows you to select a block of text in Vim. Once a block of text is selected you can use visual commands to perform actions on the selected text such as deleting it, copying it, etc.

v – starts visual mode, you can then select a range of text, and run a command

V – starts linewise visual mode (selects entire lines)

Ctrl + v – starts visual block mode (selects columns)

ab – a block with ()

aB – a block with {}

ib – inner block with ()

iB – inner block with {}

aw – mark a word

Esc – exit visual mode

Once you’ve selected a particular range of text, you can then run a command on that text such as the following:

d – delete marked text

y – yank (copy) marked text

> – shift text right

< – shift text left

~ – swap case (upper or lower)

7. Tab pages#

Just like any browser, you can also use tabs within Vim. This makes it incredibly easy to switch between multiple files while you’re making some code changes instead of working in one single file, closing it, and opening a new one. Below are some useful Vim commands for using tab pages:

:tabedit file – opens a new tab and will take you to edit “file”

gt – move to the next tab

gT – move to the previous tab

#gt – move to a specific tab number (e.g. 2gt takes you to the second tab)

:tabs – list all open tabs

:tabclose – close a single tab

Simple Vim workflow example#

If you haven’t had a chance to play around with Vim much yet, you might be wondering what a simple workflow looks like when using it. It’s relatively simple:

  1. Open a new or existing file with vim filename.
  2. Type i to switch into insert mode so that you can start editing the file.
  3. Enter or modify the text with your file.
  4. Once you’re done, press the escape key Esc to get out of insert mode and back to command mode.
  5. Type :wq to save and exit your file.

Of course, there is so much more you can do with Vim, however as a beginner, the above steps are what a simple Vim workflow looks like.

Drop your comment

Leave a Reply

Your email address will not be published.