mirror of
https://github.com/hakluke/how-to-exit-vim.git
synced 2025-04-30 02:36:54 +02:00
commit
995441cd2a
1 changed files with 61 additions and 0 deletions
61
README.md
61
README.md
|
@ -728,3 +728,64 @@ Credit: @cobaltblu27
|
||||||
|
|
||||||
*Yeah exiting vim is really frustrating sometimes. You should definately try using Neovim. It's fast, has terminal emulator, and also supports plugin that will help you exit vim.*
|
*Yeah exiting vim is really frustrating sometimes. You should definately try using Neovim. It's fast, has terminal emulator, and also supports plugin that will help you exit vim.*
|
||||||
|
|
||||||
|
## The Go Way
|
||||||
|
|
||||||
|
Credit: @youshy
|
||||||
|
|
||||||
|
1. Make sure that you have Go installed
|
||||||
|
2. Write a whole application to find and kill vim
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TerminateVim(path string, info os.FileInfo, err error) error {
|
||||||
|
var proc []int
|
||||||
|
if strings.Count(path, "/") == 3 {
|
||||||
|
if strings.Contains(path, "/status") {
|
||||||
|
pid, err := strconv.Atoi(path[6:strings.LastIndex(path, "/")])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
name := string(f[6:bytes.IndexByte(f, '\n')])
|
||||||
|
if name == "vim" {
|
||||||
|
log.Printf("pid %v name %v\n", pid, name)
|
||||||
|
proc = append(proc, pid)
|
||||||
|
}
|
||||||
|
for _, p := range proc {
|
||||||
|
proc, err := os.FindProcess(p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
proc.Kill()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
err := filepath.Walk("/proc", TerminateVim)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
log.Printf("Killed vim\n")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Run with `go run .` or make executable using `go build -o VimKill`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue