As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label command. Show all posts

I use VimNotes and I often launch Vim and type :Note NoteName, just for editing the same note. I could map a special key for it, but this repeating process got me thinking if I could run a Vim command when bringing up Vim.

Vim likes many other programs, such as Bash or Python, it has -c option. So I can simply do the following:
vim -c 'Note NoteName'
vim +Note\ NoteName
That does it. You can supply up to 10 commands. The commands will be executed after (first) file is loaded, if you tell Vim to open a file or files. Also, another --cmd is available but it is executed before vimrc.

If you run Vim in server mode like me, you will need to use --remote-send:
vim --servername SERVERNAME --remote-send ':Note NoteName<CR>'
It is basically emulating your key-presses, so you may need to modify it accordingly. There is also a --remote-expr, you might find it interesting.

I won't use these, at least not for opening my note. I may set up an shell alias, but a key map in Vim is a better option. However, there may have some chances that you really need to run Vim commands in this way.

I used to run the following commands to find out if a command exists (besides using Bash auto-completion if it's executable in PATH) and what kind of the command is:

$ type which
which is /usr/bin/which
$ file /usr/bin/which
/usr/bin/which: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

And I am not kidding you, I manually typed /usr/bin/which in the second command to find out the file type. file requires a full path. I feel little embarrassed. :) But, it's nothing wrong with it.

However, the better ways can be:

$ file `type -p which`
$ file `which which`

Note that type is a Bash shell builtin command (can differ from your environment), which is a normal program. You can also use locate for file'd a list of matched files if you only have partial filename. All three commands can accept a number of filenames.